@Test public void multiplePatterns() { WildcardPattern[] patterns = WildcardPattern.create(new String[] {"Foo", "Bar"}); assertThat(WildcardPattern.match(patterns, "Foo")).isTrue(); assertThat(WildcardPattern.match(patterns, "Bar")).isTrue(); assertThat(WildcardPattern.match(patterns, "Other")).isFalse(); assertThat(WildcardPattern.create((String[]) null)).isEmpty(); }
private boolean match(String pattern, String value, String separator) { return new WildcardPattern(pattern, separator).match(value); }
/** * Returns true if specified value matches one of specified patterns. * * @since 2.4 */ public static boolean match(WildcardPattern[] patterns, String value) { for (WildcardPattern pattern : patterns) { if (pattern.match(value)) { return true; } } return false; }
/** * Creates pattern with "/" as a directory separator. * * @see #create(String, String) */ public static WildcardPattern create(String pattern) { return create(pattern, "/"); }
@Override public String toString() { return ABSOLUTE_PATH_PATTERN_PREFIX + pattern.toString(); } }
/** * Creates pattern with specified separator for directories. * <p> * This is used to match Java-classes, i.e. <code>org.foo.Bar</code> against <code>org/**</code>. * <b>However usage of character other than "/" as a directory separator is misleading and should be avoided, * so method {@link #create(String)} is preferred over this one.</b> * * <p> * Also note that no matter whether forward or backward slashes were used in the <code>antPattern</code> * the returned pattern will use <code>directorySeparator</code>. * Thus to match Windows-style path "dir\file.ext" against pattern "dir/file.ext" normalization should be performed. * */ public static WildcardPattern create(String pattern, String directorySeparator) { String key = pattern + directorySeparator; return CACHE.computeIfAbsent(key, k -> new WildcardPattern(pattern, directorySeparator)); } }
boolean matchComponent(@Nullable String path) { return path != null && componentPattern.match(path); }
@Override public String toString() { return pattern.toString(); } }
/** * Creates pattern with specified separator for directories. * <p> * This is used to match Java-classes, i.e. <code>org.foo.Bar</code> against <code>org/**</code>. * <b>However usage of character other than "/" as a directory separator is misleading and should be avoided, * so method {@link #create(String)} is preferred over this one.</b> * * <p> * Also note that no matter whether forward or backward slashes were used in the <code>antPattern</code> * the returned pattern will use <code>directorySeparator</code>. * Thus to match Windows-style path "dir\file.ext" against pattern "dir/file.ext" normalization should be performed. * */ public static WildcardPattern create(String pattern, String directorySeparator) { String key = pattern + directorySeparator; return CACHE.computeIfAbsent(key, k -> new WildcardPattern(pattern, directorySeparator)); } }
private static boolean nameMatchPatterns(String assemblyName, String testProjectPatterns) { if (StringUtils.isEmpty(testProjectPatterns)) { return false; } String[] patterns = StringUtils.split(testProjectPatterns, ";"); boolean testFlag = false; for (int i = 0; i < patterns.length; i++) { if (WildcardPattern.create(patterns[i]).match(assemblyName)) { testFlag = true; break; } } return testFlag; }
public boolean matchFile(@Nullable String filePath) { return filePath != null && filePattern.match(filePath); }
private boolean match(String pattern, String value) { return new WildcardPattern(pattern, "/").match(value); }
public void addRuleExclusionPatternForComponent(DefaultInputFile inputFile, WildcardPattern rulePattern) { if ("*".equals(rulePattern.toString())) { inputFile.setIgnoreAllIssues(true); } else { rulePatternByComponent.put(inputFile, rulePattern); } }
/** * Creates pattern with specified separator for directories. * <p> * This is used to match Java-classes, i.e. <code>org.foo.Bar</code> against <code>org/**</code>. * <b>However usage of character other than "/" as a directory separator is misleading and should be avoided, * so method {@link #create(String)} is preferred over this one.</b> * </p> * <p> * Also note that no matter whether forward or backward slashes were used in the <code>antPattern</code> * the returned pattern will use <code>directorySeparator</code>. * Thus to match Windows-style path "dir\file.ext" against pattern "dir/file.ext" normalization should be performed. * </p> */ public static WildcardPattern create(String pattern, String directorySeparator) { String key = pattern + directorySeparator; WildcardPattern wildcardPattern = CACHE.get(key); if (wildcardPattern == null) { wildcardPattern = new WildcardPattern(pattern, directorySeparator); CACHE.put(key, wildcardPattern); } return wildcardPattern; } }