Search in sources :

Example 6 with FileExclusions

use of org.sonar.api.scan.filesystem.FileExclusions 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)

Aggregations

Test (org.junit.Test)6 MapSettings (org.sonar.api.config.MapSettings)6 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)6 IndexedFile (org.sonar.api.batch.fs.IndexedFile)5 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)5 Settings (org.sonar.api.config.Settings)5 File (java.io.File)1 InputFile (org.sonar.api.batch.fs.InputFile)1