Search in sources :

Example 1 with FileExclusions

use of org.sonar.api.scan.filesystem.FileExclusions in project sonarqube by SonarSource.

the class ExclusionFiltersTest method trim_pattern.

@Test
public void trim_pattern() {
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "   **/*Dao.java   ");
    ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
    assertThat(filter.prepareMainExclusions()[0].toString()).isEqualTo("**/*Dao.java");
}
Also used : FileExclusions(org.sonar.api.scan.filesystem.FileExclusions) MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 2 with FileExclusions

use of org.sonar.api.scan.filesystem.FileExclusions 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();
}
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) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 3 with FileExclusions

use of org.sonar.api.scan.filesystem.FileExclusions in project sonarqube by SonarSource.

the class ExclusionFiltersTest method no_inclusions_nor_exclusions.

@Test
public void no_inclusions_nor_exclusions() throws IOException {
    ExclusionFilters filter = new ExclusionFilters(new FileExclusions(new MapSettings()));
    filter.prepare();
    IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
    assertThat(filter.accept(indexedFile, InputFile.Type.TEST)).isTrue();
}
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) Test(org.junit.Test)

Example 4 with FileExclusions

use of org.sonar.api.scan.filesystem.FileExclusions in project sonarqube by SonarSource.

the class ExclusionFiltersTest method match_at_least_one_inclusion.

@Test
public void match_at_least_one_inclusion() throws IOException {
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java,**/*Dto.java");
    ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
    filter.prepare();
    IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isFalse();
    indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDto.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
}
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) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 5 with FileExclusions

use of org.sonar.api.scan.filesystem.FileExclusions in project sonarqube by SonarSource.

the class ExclusionFiltersTest method match_exclusions.

@Test
public void match_exclusions() throws IOException {
    Settings settings = new MapSettings();
    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");
    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)).isFalse();
    indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
    // source exclusions do not apply to tests
    indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/test/java/com/mycompany/FooDao.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.TEST)).isTrue();
}
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) 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