Search in sources :

Example 86 with MapSettings

use of org.sonar.api.config.MapSettings 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 87 with MapSettings

use of org.sonar.api.config.MapSettings 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 88 with MapSettings

use of org.sonar.api.config.MapSettings 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)

Example 89 with MapSettings

use of org.sonar.api.config.MapSettings 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 90 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class InputFileBuilderTest method setUp.

@Before
public void setUp() throws IOException {
    baseDir = temp.newFolder().toPath();
    DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create().setKey("module1").setBaseDir(baseDir.toFile()), 0);
    PathResolver pathResolver = new PathResolver();
    LanguageDetection langDetection = mock(LanguageDetection.class);
    MetadataGenerator metadataGenerator = mock(MetadataGenerator.class);
    BatchIdGenerator idGenerator = new BatchIdGenerator();
    Settings settings = new MapSettings();
    builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) PathResolver(org.sonar.api.scan.filesystem.PathResolver) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Before(org.junit.Before)

Aggregations

MapSettings (org.sonar.api.config.MapSettings)98 Test (org.junit.Test)75 Settings (org.sonar.api.config.Settings)36 Before (org.junit.Before)20 URI (java.net.URI)13 Languages (org.sonar.api.resources.Languages)9 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)9 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)8 File (java.io.File)7 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)7 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)6 Properties (java.util.Properties)5 IndexedFile (org.sonar.api.batch.fs.IndexedFile)5 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)5 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 InputFile (org.sonar.api.batch.fs.InputFile)4 InputStream (java.io.InputStream)3 Description (org.hamcrest.Description)3 CoreProperties (org.sonar.api.CoreProperties)3