gnodet commented on code in PR #400:
URL: https://github.com/apache/maven-filtering/pull/400#discussion_r4103311222
##########
src/main/java/org/apache/maven/shared/filtering/BaseFilter.java:
##########
@@ -173,6 +177,68 @@ public List<FilterWrapper> getDefaultFilterWrappers(final
AbstractMavenFiltering
return defaultFilterWrappers;
}
+ /**
+ * Returns {@code true} if the given filter path contains glob pattern
characters
+ * ({@code *}, {@code ?}, {@code {}, or {@code [}).
+ */
+ private static boolean isGlobPattern(String path) {
+ return path.indexOf('*') >= 0 || path.indexOf('?') >= 0 ||
path.indexOf('{') >= 0 || path.indexOf('[') >= 0;
+ }
+
+ /**
+ * Expands a glob pattern relative to {@code basedir} and returns the
matched paths in sorted order.
+ * The pattern must use forward slashes as path separators (as is
conventional in Maven filter paths).
+ */
+ private List<Path> expandGlob(Path basedir, String globPattern) throws
IOException {
+ // Normalize to forward slashes; resolveFile accepts them on all
platforms
+ String normalized = globPattern.replace('\\', '/');
+
+ // Find the deepest non-glob path prefix to use as the walk root
+ String[] segments = normalized.split("/");
+ StringBuilder prefix = new StringBuilder();
+ for (String segment : segments) {
+ if (segment.indexOf('*') >= 0
+ || segment.indexOf('?') >= 0
+ || segment.indexOf('{') >= 0
+ || segment.indexOf('[') >= 0) {
+ break;
+ }
+ if (prefix.length() > 0) {
+ prefix.append('/');
+ }
+ prefix.append(segment);
+ }
+
+ Path searchRoot = prefix.length() > 0
+ ? FilteringUtils.resolveFile(basedir, prefix.toString())
Review Comment:
Fixed in 9d1e0cd: added `if (!searchRoot.startsWith(normalizedBase))` guard
that throws `IOException` when the resolved search root escapes the project
basedir.
##########
src/main/java/org/apache/maven/shared/filtering/BaseFilter.java:
##########
@@ -173,6 +177,68 @@ public List<FilterWrapper> getDefaultFilterWrappers(final
AbstractMavenFiltering
return defaultFilterWrappers;
}
+ /**
+ * Returns {@code true} if the given filter path contains glob pattern
characters
+ * ({@code *}, {@code ?}, {@code {}, or {@code [}).
+ */
+ private static boolean isGlobPattern(String path) {
Review Comment:
Fixed in 9d1e0cd: added a fallback — when the glob matches no files, we
check whether a literal file exists at that exact path and load it as-is. This
preserves backward compatibility for filenames like `filter[1].properties`.
##########
src/main/java/org/apache/maven/shared/filtering/BaseFilter.java:
##########
@@ -189,10 +255,23 @@ void loadProperties(
continue;
}
try {
- Path propFile = FilteringUtils.resolveFile(basedir,
filterFile);
- Properties properties =
PropertyUtils.loadPropertyFile(propFile, workProperties, getLogger());
- filterProperties.putAll(properties);
- workProperties.putAll(properties);
+ if (isGlobPattern(filterFile)) {
+ List<Path> matched = expandGlob(basedir, filterFile);
+ if (matched.isEmpty()) {
+ getLogger().warn("Filter glob '" + filterFile + "'
did not match any files");
Review Comment:
Fixed in 9d1e0cd: switched to `getLogger().warn("Filter glob '{}' did not
match any files", filterFile)`.
--
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]