Copilot commented on code in PR #395:
URL: https://github.com/apache/maven-filtering/pull/395#discussion_r4094846926
##########
src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java:
##########
@@ -261,6 +262,7 @@ public void filterResources(MavenResourcesExecution
mavenResourcesExecution) thr
}
boolean filteredExt = filteredFileExtension(
source.getFileName().toString(),
mavenResourcesExecution.getNonFilteredFileExtensions());
+ boolean filteredGlob = !matchesNonFilteredGlob(name,
resource.getNonFilteredFiles());
if (resource.isFiltering() && isPropertiesFile(source)) {
propertiesFiles.add(source);
Review Comment:
A `.properties` file that matches `nonFilteredFiles` is still added to
`propertiesFiles` by the following lines, even though `filteredGlob` makes the
actual copy unfiltered. The end-of-run encoding notice will then incorrectly
describe that file as filtered and list it as potentially affected; record only
files for which the full filtering condition is true.
##########
src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java:
##########
@@ -71,4 +71,25 @@ void copyFile(
*/
void copyFile(Path from, Path to, boolean filtering, List<FilterWrapper>
filterWrappers, String encoding)
throws MavenFilteringException;
+
+ /**
+ * @param from The source file
+ * @param to The target file
+ * @param filtering true to apply filtering
+ * @param filterWrappers {@link List} of FileUtils.FilterWrapper
+ * @param encoding The encoding used during the filtering.
+ * @param gracefulBinaryHandling when {@code true}, files that cause
+ * {@link java.nio.charset.MalformedInputException} are copied
as-is with a warning
+ * instead of failing the build
+ * @throws MavenFilteringException In case of an error.
+ * @since 3.4.0
+ */
+ void copyFile(
+ Path from,
+ Path to,
+ boolean filtering,
+ List<FilterWrapper> filterWrappers,
+ String encoding,
+ boolean gracefulBinaryHandling)
+ throws MavenFilteringException;
}
Review Comment:
This adds a new abstract method to the public `MavenFileFilter` interface.
Any custom/older implementation outside this module will no longer compile, and
an already-loaded implementation will fail with `AbstractMethodError` when
`DefaultMavenResourcesFiltering` invokes this overload. Make this overload a
default method delegating to the existing five-argument overload (while
retaining the override in `DefaultMavenFileFilter`) or use another
backward-compatible propagation path.
##########
src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java:
##########
@@ -363,6 +366,30 @@ static boolean isPropertiesFile(Path file) {
return
"properties".equals(getExtension(file.getFileName().toString()));
}
+ /**
+ * Returns {@code true} if the given relative file path matches any of the
provided
+ * Ant-style glob patterns, meaning the file should NOT be filtered.
+ *
+ * @param relativePath the file path relative to the resource directory
(forward-slash separated)
+ * @param nonFilteredGlobs the list of glob patterns from {@link
Resource#getNonFilteredFiles()},
+ * or {@code null} / empty if none
+ * @return {@code true} if the path matches at least one pattern
+ * @since 3.4.0
+ */
+ static boolean matchesNonFilteredGlob(String relativePath, List<String>
nonFilteredGlobs) {
+ if (nonFilteredGlobs == null || nonFilteredGlobs.isEmpty()) {
+ return false;
+ }
+ // Normalize separators — plexus SelectorUtils expects forward slashes
+ String normalizedPath = relativePath.replace('\\', '/');
+ for (String glob : nonFilteredGlobs) {
+ if (SelectorUtils.matchPath(glob.replace('\\', '/'),
normalizedPath, false)) {
Review Comment:
The third argument to Plexus `SelectorUtils.matchPath` is the
case-sensitivity flag; passing `false` makes exclusions case-insensitive.
Ant-style resource patterns are case-sensitive by default, so a pattern such as
`**/*.p12` will incorrectly bypass filtering for `file.P12`; pass `true` here.
##########
src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java:
##########
@@ -464,6 +475,29 @@ private <T> List<T> copyList(List<T> lst) {
}
}
+ /**
+ * Returns whether files that cannot be filtered due to charset decoding
errors are silently
+ * copied as binary instead of failing the build.
Review Comment:
This public getter says the flag causes files to be copied “silently,” but
the implementation always emits a WARN when the fallback is taken. Update the
description so callers are not misled about the observable logging behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]