aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-03-17 22:42:08 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-03-17 22:42:08 +0100
commit7a4824e22a022588f59781e894bfc986a474924d (patch)
tree779a529b902c256631adaa2063802a491a87ad18 /sonar-batch
parenta568fb063bc7f87d473ede426dd719caf8014365 (diff)
downloadsonarqube-7a4824e22a022588f59781e894bfc986a474924d.tar.gz
sonarqube-7a4824e22a022588f59781e894bfc986a474924d.zip
SONAR-926 inclusions are optional
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java37
2 files changed, 15 insertions, 30 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 f2e1e428cc6..7b8297ea062 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
@@ -70,8 +70,8 @@ public class ExclusionFilters implements BatchComponent {
inclusionPatterns = testInclusions;
exclusionPatterns = testExclusions;
}
- boolean matchInclusion = false;
- if (inclusionPatterns != null && inclusionPatterns.length > 0) {
+ if (inclusionPatterns.length > 0) {
+ boolean matchInclusion = false;
for (PathPattern pattern : inclusionPatterns) {
matchInclusion |= pattern.match(inputFile);
}
@@ -79,14 +79,14 @@ public class ExclusionFilters implements BatchComponent {
return false;
}
}
- if (exclusionPatterns != null && exclusionPatterns.length > 0) {
+ if (exclusionPatterns.length > 0) {
for (PathPattern pattern : exclusionPatterns) {
if (pattern.match(inputFile)) {
return false;
}
}
}
- return matchInclusion;
+ return true;
}
PathPattern[] prepareMainInclusions() {
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 75a0c8cb5d9..d84fdce8563 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
@@ -38,49 +38,34 @@ public class ExclusionFiltersTest {
public TemporaryFolder temp = new TemporaryFolder();
@Test
- public void match_main_inclusion() throws IOException {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
- ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
+ public void no_inclusions_nor_exclusions() throws IOException {
+ ExclusionFilters filter = new ExclusionFilters(new FileExclusions(new Settings()));
filter.prepare();
java.io.File file = temp.newFile();
DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/FooDao.java").setFile(file);
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue();
-
- // test are excluded by default if no sonar.tests nor sonar.test.inclusions
- assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse();
-
- inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file);
- assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse();
-
- // test are excluded by default if no sonar.tests nor sonar.test.inclusions
- assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse();
+ assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue();
}
-
@Test
- public void exclude_test_inclusions_from_main_sources() throws IOException {
+ public void match_inclusion() throws IOException {
Settings settings = new Settings();
- settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*.java");
- settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "src/test/java/**/*.java");
+ settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
-
filter.prepare();
java.io.File file = temp.newFile();
-
- DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file);
+ DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/FooDao.java").setFile(file);
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue();
- assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse();
- inputFile = new DefaultInputFile("src/test/java/com/mycompany/Foo.java").setFile(file);
+ inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file);
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse();
- assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue();
}
+
@Test
- public void match_at_least_one_source_inclusion() throws IOException {
+ public void match_at_least_one_inclusion() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java,**/*Dto.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
@@ -97,7 +82,7 @@ public class ExclusionFiltersTest {
}
@Test
- public void match_source_exclusions() throws IOException {
+ public void match_exclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "src/test/java/**/*");
@@ -119,7 +104,7 @@ public class ExclusionFiltersTest {
}
@Test
- public void match_source_exclusion_by_absolute_path() throws IOException {
+ public void match_exclusion_by_absolute_path() throws IOException {
java.io.File includedFile = temp.newFile("Foo.java");
java.io.File excludedFile = temp.newFile("Bar.java");