Package org.sonar.batch.languages

Examples of org.sonar.batch.languages.DefaultLanguagesReferential


import static org.fest.assertions.Assertions.assertThat;

public class LanguageDetectionFactoryTest {
  @Test
  public void testCreate() throws Exception {
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(Java.INSTANCE));
    LanguageDetectionFactory factory = new LanguageDetectionFactory(new Settings(), languages);
    LanguageDetection languageDetection = factory.create();
    assertThat(languageDetection).isNotNull();
    assertThat(languageDetection.patternsByLanguage()).hasSize(1);
    assertThat(languageDetection.patternsByLanguage().containsKey("java")).isTrue();
View Full Code Here


    assertThat(LanguageDetection.sanitizeExtension("cbl")).isEqualTo("cbl");
  }

  @Test
  public void search_by_file_extension() throws Exception {
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob")));
    LanguageDetection detection = new LanguageDetection(new Settings(), languages);

    assertThat(detection.language(newInputFile("Foo.java"))).isEqualTo("java");
    assertThat(detection.language(newInputFile("src/Foo.java"))).isEqualTo("java");
    assertThat(detection.language(newInputFile("Foo.JAVA"))).isEqualTo("java");
View Full Code Here

    assertThat(detection.language(newInputFile("abc"))).isNull();
  }

  @Test
  public void should_not_fail_if_no_language() throws Exception {
    LanguageDetection detection = spy(new LanguageDetection(new Settings(), new DefaultLanguagesReferential(new Languages())));
    assertThat(detection.language(newInputFile("Foo.java"))).isNull();
  }
View Full Code Here

    assertThat(detection.language(newInputFile("Foo.java"))).isNull();
  }

  @Test
  public void plugin_can_declare_a_file_extension_twice_for_case_sensitivity() throws Exception {
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("abap", "abap", "ABAP")));

    LanguageDetection detection = new LanguageDetection(new Settings(), languages);
    assertThat(detection.language(newInputFile("abc.abap"))).isEqualTo("abap");
  }
View Full Code Here

  @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.
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap")));

    // No side-effect on non-ABAP projects
    LanguageDetection detection = new LanguageDetection(new Settings(), languages);
    assertThat(detection.language(newInputFile("abc"))).isNull();
    assertThat(detection.language(newInputFile("abc.abap"))).isNull();
View Full Code Here

    assertThat(detection.language(newInputFile("abc.java"))).isEqualTo("abap");
  }

  @Test
  public void force_language_using_deprecated_property() throws Exception {
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));

    Settings settings = new Settings();
    settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "java");
    LanguageDetection detection = new LanguageDetection(settings, languages);
    assertThat(detection.language(newInputFile("abc"))).isNull();
View Full Code Here

  @Test
  public void fail_if_invalid_language() throws Exception {
    thrown.expect(MessageException.class);
    thrown.expectMessage("No language is installed with key 'unknown'. Please update property 'sonar.language'");

    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
    Settings settings = new Settings();
    settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown");
    new LanguageDetection(settings, languages);
  }
View Full Code Here

    new LanguageDetection(settings, languages);
  }

  @Test
  public void fail_if_conflicting_language_suffix() throws Exception {
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
    LanguageDetection detection = new LanguageDetection(new Settings(), languages);
    try {
      detection.language(newInputFile("abc.xhtml"));
      fail();
    } catch (MessageException e) {
View Full Code Here

    }
  }

  @Test
  public void solve_conflict_using_filepattern() throws Exception {
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));

    Settings settings = new Settings();
    settings.setProperty("sonar.lang.patterns.xml", "xml/**");
    settings.setProperty("sonar.lang.patterns.web", "web/**");
    LanguageDetection detection = new LanguageDetection(settings, languages);
View Full Code Here

    assertThat(detection.language(newInputFile("web/abc.xhtml"))).isEqualTo("web");
  }

  @Test
  public void fail_if_conflicting_filepattern() throws Exception {
    LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol")));
    Settings settings = new Settings();
    settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt");
    settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt");

    LanguageDetection detection = new LanguageDetection(settings, languages);
View Full Code Here

TOP

Related Classes of org.sonar.batch.languages.DefaultLanguagesReferential

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.