use of org.sonar.scanner.repository.language.LanguagesRepository in project sonarqube by SonarSource.
the class LanguageDetectionTest method plugin_can_declare_a_file_extension_twice_for_case_sensitivity.
@Test
public void plugin_can_declare_a_file_extension_twice_for_case_sensitivity() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap", "ABAP")));
LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
assertThat(detection.language(newIndexedFile("abc.abap"))).isEqualTo("abap");
}
use of org.sonar.scanner.repository.language.LanguagesRepository in project sonarqube by SonarSource.
the class LanguageDetectionTest method force_language_using_deprecated_property.
@Test
public void force_language_using_deprecated_property() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "java");
LanguageDetection detection = new LanguageDetection(settings, languages);
assertThat(detection.language(newIndexedFile("abc"))).isNull();
assertThat(detection.language(newIndexedFile("abc.php"))).isNull();
assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("java");
assertThat(detection.language(newIndexedFile("src/abc.java"))).isEqualTo("java");
}
use of org.sonar.scanner.repository.language.LanguagesRepository in project sonarqube by SonarSource.
the class LanguageDetectionTest method language_with_no_extension.
@Test
public void language_with_no_extension() throws Exception {
// abap does not declare any file extensions.
// When analyzing an ABAP project, then all source files must be parsed.
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap")));
// No side-effect on non-ABAP projects
LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
assertThat(detection.language(newIndexedFile("abc"))).isNull();
assertThat(detection.language(newIndexedFile("abc.abap"))).isNull();
assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("java");
Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "abap");
detection = new LanguageDetection(settings, languages);
assertThat(detection.language(newIndexedFile("abc"))).isEqualTo("abap");
assertThat(detection.language(newIndexedFile("abc.txt"))).isEqualTo("abap");
assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("abap");
}
use of org.sonar.scanner.repository.language.LanguagesRepository 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");
}
use of org.sonar.scanner.repository.language.LanguagesRepository 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");
}
}
Aggregations