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);
}
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();
}
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");
}
}
Aggregations