diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-06-28 16:39:13 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-06-28 16:39:52 +0200 |
commit | beadd7ecf6ab8d754dc49963dfdc815e46ae5952 (patch) | |
tree | 2c52ba2f63f130e4db052ed303db07c555b76533 /sonar-plugin-api | |
parent | e97842a436b032c4e274494d54cdc57a94b11f9a (diff) | |
download | sonarqube-beadd7ecf6ab8d754dc49963dfdc815e46ae5952.tar.gz sonarqube-beadd7ecf6ab8d754dc49963dfdc815e46ae5952.zip |
SONAR-4335 No way to exclude/include a file not located in a directory
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java | 7 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java | 10 |
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 */ |