Search in sources :

Example 46 with Settings

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

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

Example 48 with Settings

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

the class LanguageDetectionTest method solve_conflict_using_filepattern.

@Test
public void solve_conflict_using_filepattern() throws Exception {
    LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
    Settings settings = new MapSettings();
    settings.setProperty("sonar.lang.patterns.xml", "xml/**");
    settings.setProperty("sonar.lang.patterns.web", "web/**");
    LanguageDetection detection = new LanguageDetection(settings, languages);
    assertThat(detection.language(newIndexedFile("xml/abc.xhtml"))).isEqualTo("xml");
    assertThat(detection.language(newIndexedFile("web/abc.xhtml"))).isEqualTo("web");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) LanguagesRepository(org.sonar.scanner.repository.language.LanguagesRepository) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Languages(org.sonar.api.resources.Languages) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 49 with Settings

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

the class LanguageDetectionTest method fail_if_invalid_language.

@Test
public void fail_if_invalid_language() {
    thrown.expect(MessageException.class);
    thrown.expectMessage("You must install a plugin that supports the language 'unknown'");
    LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown");
    new LanguageDetection(settings, languages);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) LanguagesRepository(org.sonar.scanner.repository.language.LanguagesRepository) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Languages(org.sonar.api.resources.Languages) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 50 with Settings

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

the class LanguageDetectionTest method fail_if_conflicting_filepattern.

@Test
public void fail_if_conflicting_filepattern() throws Exception {
    LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol")));
    Settings settings = new MapSettings();
    settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt");
    settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt");
    LanguageDetection detection = new LanguageDetection(settings, languages);
    assertThat(detection.language(newIndexedFile("abc.abap"))).isEqualTo("abap");
    assertThat(detection.language(newIndexedFile("abc.cobol"))).isEqualTo("cobol");
    try {
        detection.language(newIndexedFile("abc.txt"));
        fail();
    } catch (MessageException e) {
        assertThat(e.getMessage()).contains("Language of file 'abc.txt' can not be decided as the file matches patterns of both ").contains("sonar.lang.patterns.abap : *.abap,*.txt").contains("sonar.lang.patterns.cobol : *.cobol,*.txt");
    }
}
Also used : MapSettings(org.sonar.api.config.MapSettings) MessageException(org.sonar.api.utils.MessageException) LanguagesRepository(org.sonar.scanner.repository.language.LanguagesRepository) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Languages(org.sonar.api.resources.Languages) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Aggregations

Settings (org.sonar.api.config.Settings)52 MapSettings (org.sonar.api.config.MapSettings)43 Test (org.junit.Test)41 Before (org.junit.Before)5 Languages (org.sonar.api.resources.Languages)5 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)5 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)5 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)5 IndexedFile (org.sonar.api.batch.fs.IndexedFile)4 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)4 File (java.io.File)3 String.format (java.lang.String.format)3 TransportClient (org.elasticsearch.client.transport.TransportClient)3 PropertyDto (org.sonar.db.property.PropertyDto)3 InetAddress (java.net.InetAddress)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Condition (org.assertj.core.api.Condition)2 TransportAddress (org.elasticsearch.common.transport.TransportAddress)2 Rule (org.junit.Rule)2 ExpectedException (org.junit.rules.ExpectedException)2