Search in sources :

Example 6 with LanguagesRepository

use of org.sonar.scanner.repository.language.LanguagesRepository 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 7 with LanguagesRepository

use of org.sonar.scanner.repository.language.LanguagesRepository 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)

Example 8 with LanguagesRepository

use of org.sonar.scanner.repository.language.LanguagesRepository 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

Test (org.junit.Test)8 MapSettings (org.sonar.api.config.MapSettings)8 Languages (org.sonar.api.resources.Languages)8 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)8 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)8 Settings (org.sonar.api.config.Settings)5 MessageException (org.sonar.api.utils.MessageException)2