Search in sources :

Example 1 with LanguagesRepository

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");
}
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 2 with LanguagesRepository

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");
}
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 3 with LanguagesRepository

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");
}
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 4 with LanguagesRepository

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");
}
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 5 with LanguagesRepository

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

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