aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-29 08:03:34 +0000
committerGodin <mandrikov@gmail.com>2010-10-29 08:03:34 +0000
commit9ed3191362c27c60a6f41fd2a4756cc92942be6d (patch)
tree07538107b86b409c31238f22f3453693ab731386 /sonar-plugin-api
parent24ec0d77135ebe364b2bd30b486f2a642defa706 (diff)
downloadsonarqube-9ed3191362c27c60a6f41fd2a4756cc92942be6d.tar.gz
sonarqube-9ed3191362c27c60a6f41fd2a4756cc92942be6d.zip
SONAR-1904: WildcardPattern "**/Reader" shouldn't match "org.sonar.channel.CodeReader" and "java.io.StringReader"
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java11
2 files changed, 16 insertions, 5 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 6d93a40a06f..2045b92faa2 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
@@ -45,14 +45,14 @@ public class WildcardPattern {
private String toRegexp(String wildcardPattern, String directorySeparator) {
String patternStr = removeSlahesToIgnore(wildcardPattern);
patternStr = StringUtils.replace(patternStr, "**/**", "**");
- patternStr = StringUtils.replace(patternStr, "**/", "|");
- patternStr = StringUtils.replace(patternStr, "/**", "|");
- patternStr = StringUtils.replace(patternStr, "**", "|");
+ patternStr = StringUtils.replace(patternStr, "**/", "(&/|)");
+ patternStr = StringUtils.replace(patternStr, "/**", "&");
+ patternStr = StringUtils.replace(patternStr, "**", "&");
StringBuilder sb = new StringBuilder();
for (char c : patternStr.toCharArray()) {
switch (c) {
- case '|':
+ case '&':
sb.append(".*");
break;
case '*':
@@ -85,7 +85,7 @@ public class WildcardPattern {
}
public static WildcardPattern[] create(String[] patterns) {
- if (patterns==null) {
+ if (patterns == null) {
return new WildcardPattern[0];
}
WildcardPattern[] exclusionPAtterns = new WildcardPattern[patterns.length];
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 5757b854b4d..1b0d6b80a2b 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
@@ -21,9 +21,11 @@ package org.sonar.api.utils;
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) {
return new WildcardPattern(pattern, separator).match(value);
}
@@ -58,6 +60,11 @@ public class WildcardPatternTest {
assertTrue(match("a.b.c", "a.b.c", "."));
assertTrue(match("*/a.b.c", "foo.a.b.c", "."));
assertFalse(match("*/a.b.c", "foo/aabbc", "."));
+
+ assertTrue(match("**/Reader", "java.io.Reader", "."));
+ assertFalse(match("**/Reader", "org.sonar.channel.CodeReader", "."));
+
+ assertTrue(match("**", "java.io.Reader", "."));
}
@Test
@@ -87,5 +94,9 @@ public class WildcardPatternTest {
assertTrue(match("*/a.b.c", "foo/a.b.c"));
assertFalse(match("*/a.b.c", "foo/aabbc"));
+ assertTrue(match("**/Reader", "java/io/Reader"));
+ assertFalse(match("**/Reader", "org/sonar/channel/CodeReader"));
+
+ assertTrue(match("**", "java/io/Reader"));
}
}