Skip to content

Commit ae016b5

Browse files
committed
[GR-64314] Print warning when glob is too general
PullRequest: graal/20575
2 parents fb645b6 + 853d3ac commit ae016b5

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/CompressedGlobTrie/CompressedGlobTrie.java

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public static <C> GlobTrieNode<C> build(List<GlobWithInfo<C>> patterns) {
109109
if (!invalidPatterns.isEmpty()) {
110110
StringBuilder sb = new StringBuilder("Error: invalid glob patterns found:" + System.lineSeparator());
111111
invalidPatterns.forEach(msg -> sb.append(msg).append(System.lineSeparator()));
112+
112113
throw UserError.abort(sb.toString());
113114
}
114115

substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/GlobUtils.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ private GlobUtils() {
4242
public static final String SAME_LEVEL_IDENTIFIER = "#";
4343
private static final Pattern threeConsecutiveStarsRegex = Pattern.compile(".*[*]{3,}.*");
4444
private static final Pattern emptyLevelsRegex = Pattern.compile(".*/{2,}.*");
45+
private static final String ALL_UNNAMED = "ALL_UNNAMED";
4546

4647
public static String transformToTriePath(String resource, String module) {
4748
String resolvedModuleName;
4849
if (module == null || module.isEmpty()) {
49-
resolvedModuleName = "ALL_UNNAMED";
50+
resolvedModuleName = ALL_UNNAMED;
5051
} else {
5152
resolvedModuleName = StringUtil.toSlashSeparated(module);
5253
}
@@ -104,15 +105,25 @@ public static String validatePattern(String pattern) {
104105
escapeMode = current == '\\';
105106
}
106107

107-
// check if pattern contains ** without previous Literal parent. Example: */**/... or **/...
108-
outer: for (List<GlobToken> levelTokens : tokenize(pattern)) {
109-
for (GlobToken token : levelTokens) {
110-
if (token.kind == GlobToken.Kind.LITERAL) {
111-
break outer;
112-
} else if (token.kind == GlobToken.Kind.STAR_STAR) {
113-
sb.append("Pattern contains ** without previous literal. " +
114-
"This pattern is too generic and therefore can match many resources. " +
115-
"Please make the pattern more specific by adding non-generic level before ** level.");
108+
// check if pattern (that matches something from classpath) contains ** without previous
109+
// Literal parent. Example: */**/... or **/...
110+
if (pattern.startsWith(ALL_UNNAMED)) {
111+
List<List<GlobToken>> patternParts = tokenize(pattern);
112+
113+
// remove ALL_UNNAMED prefix
114+
patternParts.removeFirst();
115+
116+
// check glob without module prefix
117+
outer: for (List<GlobToken> levelTokens : patternParts) {
118+
for (GlobToken token : levelTokens) {
119+
if (token.kind == GlobToken.Kind.LITERAL) {
120+
break outer;
121+
} else if (token.kind == GlobToken.Kind.STAR_STAR) {
122+
String patternWithoutModule = pattern.substring(ALL_UNNAMED.length() + 1);
123+
LogUtils.warning("Pattern: " + patternWithoutModule + " contains ** without previous literal. " +
124+
"This pattern is too generic and therefore can match many resources. " +
125+
"Please make the pattern more specific by adding non-generic level before ** level.");
126+
}
116127
}
117128
}
118129
}

0 commit comments

Comments
 (0)