aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java7
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java10
2 files changed, 16 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java
index a62f672a69e..6ec533c5c49 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java
@@ -179,9 +179,14 @@ public class JavaFile extends Resource<JavaPackage> {
if (!fileKey.endsWith(".java")) {
fileKey += ".java";
}
- if (StringUtils.substringAfterLast(antPattern, "/").indexOf(".") < 0) {
+ // Add wildcard extension if not provided
+ if ((antPattern.contains("/") && StringUtils.substringAfterLast(antPattern, "/").indexOf(".") < 0) || antPattern.indexOf(".") < 0) {
antPattern += ".*";
}
+ String noPackagePrefix = JavaPackage.DEFAULT_PACKAGE_NAME + ".";
+ if (fileKey.startsWith(noPackagePrefix)) {
+ fileKey = fileKey.substring(noPackagePrefix.length());
+ }
WildcardPattern matcher = WildcardPattern.create(antPattern, ".");
return matcher.match(fileKey);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
index 4b23394e13b..53b9061bc4e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
@@ -206,6 +206,16 @@ public class JavaFileTest {
assertTrue(clazz.matchFilePattern("**/*"));
}
+ // SONAR-4397
+ @Test
+ public void shouldMatchFilePatternsWhenNoPackage() {
+ JavaFile clazz = new JavaFile("[default].Foo.java");
+ assertTrue(clazz.matchFilePattern("**/*Foo"));
+ assertTrue(clazz.matchFilePattern("**/*Foo.*"));
+ assertTrue(clazz.matchFilePattern("**/*"));
+ assertTrue(clazz.matchFilePattern("Foo*.*"));
+ }
+
/**
* See http://jira.codehaus.org/browse/SONAR-1449
*/