@@ -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