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);
}
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() {
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));
}
@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/**/*");
}
@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");