diff options
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java | 12 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java | 12 |
2 files changed, 22 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java index 2045b92faa2..572d2c1d01b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java @@ -80,6 +80,18 @@ public class WildcardPattern { return StringUtils.removeEnd(patternStr, "/"); } + /** + * @since 2.4 + */ + public static boolean match(WildcardPattern[] patterns, String value) { + for (WildcardPattern pattern : patterns) { + if (pattern.match(value)) { + return true; + } + } + return false; + } + public static WildcardPattern create(String pattern) { return create(pattern, "/"); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java index 1b0d6b80a2b..f57aff8f6e2 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java @@ -19,11 +19,11 @@ */ package org.sonar.api.utils; +import org.junit.Test; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.junit.Test; - public class WildcardPatternTest { private boolean match(String pattern, String value, String separator) { @@ -99,4 +99,12 @@ public class WildcardPatternTest { assertTrue(match("**", "java/io/Reader")); } + + @Test + public void multiplePatterns() { + WildcardPattern[] patterns = new WildcardPattern[] { WildcardPattern.create("Foo"), WildcardPattern.create("Bar") }; + assertTrue(WildcardPattern.match(patterns, "Foo")); + assertTrue(WildcardPattern.match(patterns, "Bar")); + assertFalse(WildcardPattern.match(patterns, "Other")); + } } |