aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-18 16:45:10 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-18 16:45:30 +0100
commit8a6c663a6d1efbd157c7ed8d4f0a7120e064a371 (patch)
treee2f3417c287237e4a3619e59df250ce689d1a634 /sonar-batch
parent71e0f5c99ce17f4f9313689f8b2bb299f22e78fb (diff)
downloadsonarqube-8a6c663a6d1efbd157c7ed8d4f0a7120e064a371.tar.gz
sonarqube-8a6c663a6d1efbd157c7ed8d4f0a7120e064a371.zip
SONAR-2760 fix support of multiple inclusion patterns
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java51
2 files changed, 50 insertions, 11 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
index 959b63e28c7..51e0741baee 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
@@ -91,11 +91,15 @@ public class ExclusionFilters implements FileSystemFilter, ResourceFilter, Batch
private boolean isIgnoredFileResource(Resource resource) {
PathPattern[] inclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testInclusions : sourceInclusions);
if (inclusionPatterns.length > 0) {
- boolean matchInclusion = true;
+ boolean matchInclusion = false;
+ boolean supportResource = false;
for (PathPattern pattern : inclusionPatterns) {
- matchInclusion &= (!pattern.supportResource() || pattern.match(resource));
+ if (pattern.supportResource()) {
+ supportResource = true;
+ matchInclusion |= pattern.match(resource);
+ }
}
- if (!matchInclusion) {
+ if (supportResource && !matchInclusion) {
return true;
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java
index c8aa4e0d411..89c07925e47 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java
@@ -41,7 +41,7 @@ public class ExclusionFiltersTest {
public TemporaryFolder temp = new TemporaryFolder();
@Test
- public void source_inclusions() throws IOException {
+ public void should_match_source_inclusion() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
@@ -62,7 +62,22 @@ public class ExclusionFiltersTest {
}
@Test
- public void source_exclusions() throws IOException {
+ public void should_match_at_least_one_source_inclusion() throws IOException {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java,**/*Dto.java");
+ ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
+
+ FileFilterContext context = new FileFilterContext(mock(ModuleFileSystem.class));
+ context.setType(FileType.SOURCE);
+ context.setRelativePath("com/mycompany/Foo.java");
+ assertThat(filter.accept(temp.newFile(), context)).isFalse();
+
+ context.setRelativePath("com/mycompany/FooDto.java");
+ assertThat(filter.accept(temp.newFile(), context)).isTrue();
+ }
+
+ @Test
+ public void should_match_source_exclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
@@ -83,7 +98,7 @@ public class ExclusionFiltersTest {
}
@Test
- public void source_exclusion_by_absolute_path() throws IOException {
+ public void should_match_source_exclusion_by_absolute_path() throws IOException {
java.io.File includedFile = temp.newFile("Foo.java");
java.io.File excludedFile = temp.newFile("Bar.java");
@@ -103,7 +118,7 @@ public class ExclusionFiltersTest {
}
@Test
- public void resource_inclusions() throws IOException {
+ public void should_match_resource_inclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.c");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
@@ -113,7 +128,7 @@ public class ExclusionFiltersTest {
}
@Test
- public void resource_exclusions() throws IOException {
+ public void should_match_resource_exclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.c");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
@@ -122,11 +137,31 @@ public class ExclusionFiltersTest {
assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isFalse();
}
+ @Test
+ public void should_ignore_resource_exclusions_by_absolute_path() throws IOException {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:**/*Dao.c");
+ ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
+
+ assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isFalse();
+ assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isFalse();
+ }
+
+ @Test
+ public void should_ignore_resource_inclusions_by_absolute_path() throws IOException {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "file:**/*Dao.c");
+ ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
+
+ assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isFalse();
+ assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isFalse();
+ }
+
/**
* JavaFile will be deprecated
*/
@Test
- public void java_resource_inclusions() throws IOException {
+ public void should_match_java_resource_inclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
@@ -139,7 +174,7 @@ public class ExclusionFiltersTest {
* JavaFile will be deprecated
*/
@Test
- public void java_resource_exclusions() throws IOException {
+ public void should_match_java_resource_exclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
@@ -149,7 +184,7 @@ public class ExclusionFiltersTest {
}
@Test
- public void do_not_check_exclusions_on_non_file_resources() throws IOException {
+ public void should_not_check_exclusions_on_non_file_resources() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "*");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));