use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.
the class ExclusionFiltersTest method match_inclusion.
@Test
public void match_inclusion() throws IOException {
Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
filter.prepare();
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java");
assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isFalse();
}
use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.
the class ProjectExclusionFiltersTest method match_at_least_one_inclusion.
@Test
public void match_at_least_one_inclusion() {
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java,**/*Dto.java");
ProjectExclusionFilters filter = new ProjectExclusionFilters(settings.asConfig());
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java", null);
assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isFalse();
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDto.java", null);
assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isTrue();
}
use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.
the class ProjectExclusionFiltersTest method match_exclusions.
@Test
public void match_exclusions() {
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "src/test/java/**/*");
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java");
ProjectExclusionFilters filter = new ProjectExclusionFilters(settings.asConfig());
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java", null);
assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isTrue();
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java", null);
assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isFalse();
// source exclusions do not apply to tests
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/test/java/com/mycompany/FooDao.java", null);
assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.TEST)).isFalse();
}
use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.
the class PathPatternTest method match_relative_path.
@Test
public void match_relative_path() {
PathPattern pattern = PathPattern.create("**/*Foo.java");
assertThat(pattern.toString()).isEqualTo("**/*Foo.java");
IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.java");
assertThat(pattern.match(indexedFile)).isTrue();
// case sensitive by default
indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.JAVA");
assertThat(pattern.match(indexedFile)).isFalse();
indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/Other.java");
assertThat(pattern.match(indexedFile)).isFalse();
}
use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.
the class PathPatternTest method match_absolute_path_and_insensitive_file_extension.
@Test
public void match_absolute_path_and_insensitive_file_extension() throws Exception {
PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java");
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.JAVA");
assertThat(pattern.match(indexedFile, false)).isTrue();
indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/Other.JAVA");
assertThat(pattern.match(indexedFile, false)).isFalse();
}
Aggregations