|
51 | 51 | * parameter represents list of glob patterns given in any order. At the very beginning, all given |
52 | 52 | * globs will be validated using {@link GlobUtils#validatePattern(String)}. If all globs were |
53 | 53 | * correct, they will be classified (with |
54 | | - * {@link CompressedGlobTrieBuilder#classifyPatterns(List, List, List, List)}) and sorted (using |
55 | | - * {@link CompressedGlobTrieBuilder#comparePatterns(GlobWithInfo, GlobWithInfo)} as the comparator |
56 | | - * function). This preprocessing phase allows incremental structure build, going from the most |
57 | | - * general glob pattern to the more specific ones. Furthermore, when trying to add a new glob, the |
58 | | - * structure will first check if the given glob can be matched with some glob that already exists in |
59 | | - * the structure (NOTE: possibly more than one glob pattern from the structure can match the new |
60 | | - * pattern). When that is not the case, a new pattern will be added using |
| 54 | + * {@link CompressedGlobTrieBuilder#classifyPatterns(List, List, List, List, boolean)}) and sorted |
| 55 | + * (using {@link CompressedGlobTrieBuilder#comparePatterns(GlobWithInfo, GlobWithInfo)} as the |
| 56 | + * comparator function). This preprocessing phase allows incremental structure build, going from the |
| 57 | + * most general glob pattern to the more specific ones. Furthermore, when trying to add a new glob, |
| 58 | + * the structure will first check if the given glob can be matched with some glob that already |
| 59 | + * exists in the structure (NOTE: possibly more than one glob pattern from the structure can match |
| 60 | + * the new pattern). When that is not the case, a new pattern will be added using |
61 | 61 | * {@link CompressedGlobTrieBuilder#addNewBranch}. This function will attempt identical matching |
62 | 62 | * (where wildcards have no special semantics) to move as deep in the structure as possible. Once it |
63 | 63 | * cannot proceed with the existing branches, the function will append rest of the pattern as the |
@@ -100,13 +100,21 @@ public static class CompressedGlobTrieBuilder<C> { |
100 | 100 | * with possibly additional context. |
101 | 101 | */ |
102 | 102 | public static <C> GlobTrieNode<C> build(List<GlobWithInfo<C>> patterns) { |
| 103 | + return build(patterns, true); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Builds an immutable CompressedGlobTrie structure from glob patterns given in any order |
| 108 | + * with possibly additional context. Validation of patterns can be turned off. |
| 109 | + */ |
| 110 | + public static <C> GlobTrieNode<C> build(List<GlobWithInfo<C>> patterns, boolean validatePatterns) { |
103 | 111 | GlobTrieNode<C> root = new GlobTrieNode<>(); |
104 | 112 | /* classify patterns in groups */ |
105 | 113 | List<GlobWithInfo<C>> doubleStarPatterns = new ArrayList<>(); |
106 | 114 | List<GlobWithInfo<C>> starPatterns = new ArrayList<>(); |
107 | 115 | List<GlobWithInfo<C>> noStarPatterns = new ArrayList<>(); |
108 | 116 |
|
109 | | - List<String> invalidPatternsErrors = classifyPatterns(patterns, doubleStarPatterns, starPatterns, noStarPatterns); |
| 117 | + List<String> invalidPatternsErrors = classifyPatterns(patterns, doubleStarPatterns, starPatterns, noStarPatterns, validatePatterns); |
110 | 118 | if (!invalidPatternsErrors.isEmpty()) { |
111 | 119 | invalidPatternsErrors.forEach(LogUtils::warning); |
112 | 120 | } |
@@ -213,19 +221,22 @@ private static <C> void addNewBranch(GlobTrieNode<C> root, List<GlobTrieNode<C>> |
213 | 221 | private static <C> List<String> classifyPatterns(List<GlobWithInfo<C>> patterns, |
214 | 222 | List<GlobWithInfo<C>> doubleStar, |
215 | 223 | List<GlobWithInfo<C>> singleStar, |
216 | | - List<GlobWithInfo<C>> noStar) { |
| 224 | + List<GlobWithInfo<C>> noStar, |
| 225 | + boolean validate) { |
217 | 226 | List<String> invalidPatterns = new ArrayList<>(); |
218 | 227 | for (GlobWithInfo<C> patternWithInfo : patterns) { |
219 | | - /* validate patterns */ |
220 | | - String error = GlobUtils.validatePattern(patternWithInfo.pattern()); |
221 | | - if (!error.isEmpty()) { |
222 | | - if (patternWithInfo.additionalContent() instanceof ClassLoaderSupport.ConditionWithOrigin conditionWithOrigin) { |
223 | | - invalidPatterns.add(error + "Pattern is from: " + conditionWithOrigin.origin()); |
224 | | - } else { |
225 | | - invalidPatterns.add(error); |
226 | | - } |
| 228 | + if (validate) { |
| 229 | + /* validate patterns */ |
| 230 | + String error = GlobUtils.validatePattern(patternWithInfo.pattern()); |
| 231 | + if (!error.isEmpty()) { |
| 232 | + if (patternWithInfo.additionalContent() instanceof ClassLoaderSupport.ConditionWithOrigin conditionWithOrigin) { |
| 233 | + invalidPatterns.add(error + "Pattern is from: " + conditionWithOrigin.origin()); |
| 234 | + } else { |
| 235 | + invalidPatterns.add(error); |
| 236 | + } |
227 | 237 |
|
228 | | - continue; |
| 238 | + continue; |
| 239 | + } |
229 | 240 | } |
230 | 241 |
|
231 | 242 | String pattern = patternWithInfo.pattern(); |
|
0 commit comments