Search in sources :

Example 11 with IndexedFile

use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.

the class ExclusionFiltersTest method match_exclusion_by_absolute_path.

@Test
public void match_exclusion_by_absolute_path() throws IOException {
    File excludedFile = new File(moduleBaseDir.toString(), "src/main/java/org/bar/Bar.java");
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
    settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:" + excludedFile.getAbsolutePath());
    ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
    filter.prepare();
    IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Foo.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
    indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Bar.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isFalse();
}
Also used : FileExclusions(org.sonar.api.scan.filesystem.FileExclusions) IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) MapSettings(org.sonar.api.config.MapSettings) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) InputFile(org.sonar.api.batch.fs.InputFile) IndexedFile(org.sonar.api.batch.fs.IndexedFile) File(java.io.File) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 12 with IndexedFile

use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.

the class ProjectExclusionFiltersTest method no_inclusions_nor_exclusions.

@Test
public void no_inclusions_nor_exclusions() {
    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)).isFalse();
    assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.TEST)).isFalse();
    assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isTrue();
    assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.TEST)).isTrue();
}
Also used : IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Test(org.junit.Test)

Example 13 with IndexedFile

use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.

the class ProjectExclusionFiltersTest method match_inclusion.

@Test
public void match_inclusion() {
    settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_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.isIncluded(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.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isFalse();
}
Also used : IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Test(org.junit.Test)

Example 14 with IndexedFile

use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.

the class ProjectExclusionFiltersTest method match_exclusion_by_absolute_path.

@Test
public void match_exclusion_by_absolute_path() {
    File excludedFile = new File(moduleBaseDir.toString(), "src/main/java/org/bar/Bar.java");
    settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
    settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:" + excludedFile.getAbsolutePath());
    ProjectExclusionFilters filter = new ProjectExclusionFilters(settings.asConfig());
    IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Foo.java", null);
    assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isFalse();
    indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Bar.java", null);
    assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isTrue();
}
Also used : IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) InputFile(org.sonar.api.batch.fs.InputFile) IndexedFile(org.sonar.api.batch.fs.IndexedFile) File(java.io.File) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Test(org.junit.Test)

Example 15 with IndexedFile

use of org.sonar.api.batch.fs.IndexedFile in project sonarqube by SonarSource.

the class PathPatternTest method match_absolute_path.

@Test
public void match_absolute_path() {
    PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java");
    assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
    IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.java", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isTrue();
    // case sensitive by default
    indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
    indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.java", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
}
Also used : PathPattern(org.sonar.api.batch.fs.internal.PathPattern) IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 IndexedFile (org.sonar.api.batch.fs.IndexedFile)18 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)14 MapSettings (org.sonar.api.config.MapSettings)5 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)5 PathPattern (org.sonar.api.batch.fs.internal.PathPattern)4 Settings (org.sonar.api.config.Settings)4 File (java.io.File)2 InputFile (org.sonar.api.batch.fs.InputFile)2