Search in sources :

Example 1 with DefaultLanguagesRepository

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

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

use of org.sonar.scanner.repository.language.DefaultLanguagesRepository 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() {
    LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap", "ABAP")));
    LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
    assertThat(detectLanguageKey(detection, "abc.abap")).isEqualTo("abap");
}
Also used : 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 4 with DefaultLanguagesRepository

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

use of org.sonar.scanner.repository.language.DefaultLanguagesRepository in project sonarqube by SonarSource.

the class LanguageDetectionTest method should_not_fail_if_no_language.

@Test
public void should_not_fail_if_no_language() {
    LanguageDetection detection = spy(new LanguageDetection(settings.asConfig(), new DefaultLanguagesRepository(new Languages())));
    assertThat(detectLanguageKey(detection, "Foo.java")).isNull();
}
Also used : Languages(org.sonar.api.resources.Languages) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Test(org.junit.Test)

Aggregations

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