Search in sources :

Example 11 with Languages

use of org.sonar.api.resources.Languages 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 12 with Languages

use of org.sonar.api.resources.Languages 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)

Example 13 with Languages

use of org.sonar.api.resources.Languages 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 14 with Languages

use of org.sonar.api.resources.Languages 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 15 with Languages

use of org.sonar.api.resources.Languages 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

Languages (org.sonar.api.resources.Languages)16 Test (org.junit.Test)10 MapSettings (org.sonar.api.config.MapSettings)9 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)9 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)8 Settings (org.sonar.api.config.Settings)5 Before (org.junit.Before)4 WsTester (org.sonar.server.ws.WsTester)4 DbClient (org.sonar.db.DbClient)3 QProfileFactory (org.sonar.server.qualityprofile.QProfileFactory)3 I18n (org.sonar.api.i18n.I18n)2 WebService (org.sonar.api.server.ws.WebService)2 MessageException (org.sonar.api.utils.MessageException)2 ComponentFinder (org.sonar.server.component.ComponentFinder)2 QProfileExporters (org.sonar.server.qualityprofile.QProfileExporters)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 StandardCharsets (java.nio.charset.StandardCharsets)1