Search in sources :

Example 91 with MapSettings

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

the class CoverageExclusionsTest method prepare.

@Before
public void prepare() {
    settings = new MapSettings(new PropertyDefinitions(ExclusionProperties.all()));
    coverageExclusions = new CoverageExclusions(settings);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) Before(org.junit.Before)

Example 92 with MapSettings

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

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

the class LanguageDetectionTest method fail_if_conflicting_language_suffix.

@Test
public void fail_if_conflicting_language_suffix() throws Exception {
    LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
    LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
    try {
        detection.language(newIndexedFile("abc.xhtml"));
        fail();
    } catch (MessageException e) {
        assertThat(e.getMessage()).contains("Language of file 'abc.xhtml' can not be decided as the file matches patterns of both ").contains("sonar.lang.patterns.web : **/*.xhtml").contains("sonar.lang.patterns.xml : **/*.xhtml");
    }
}
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) Test(org.junit.Test)

Example 94 with MapSettings

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

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

the class LanguageDetectionTest method search_by_file_extension.

@Test
public void search_by_file_extension() throws Exception {
    LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob")));
    LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
    assertThat(detection.language(newIndexedFile("Foo.java"))).isEqualTo("java");
    assertThat(detection.language(newIndexedFile("src/Foo.java"))).isEqualTo("java");
    assertThat(detection.language(newIndexedFile("Foo.JAVA"))).isEqualTo("java");
    assertThat(detection.language(newIndexedFile("Foo.jav"))).isEqualTo("java");
    assertThat(detection.language(newIndexedFile("Foo.Jav"))).isEqualTo("java");
    assertThat(detection.language(newIndexedFile("abc.cbl"))).isEqualTo("cobol");
    assertThat(detection.language(newIndexedFile("abc.CBL"))).isEqualTo("cobol");
    assertThat(detection.language(newIndexedFile("abc.php"))).isNull();
    assertThat(detection.language(newIndexedFile("abc"))).isNull();
}
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) Test(org.junit.Test)

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