Package org.sonar.api.resources

Examples of org.sonar.api.resources.Languages


    }
  }

  private void execute(RulesDefinition... defs) {
    RuleDefinitionsLoader loader = new RuleDefinitionsLoader(mock(RuleRepositories.class), defs);
    Languages languages = mock(Languages.class);
    when(languages.get("java")).thenReturn(mock(Language.class));

    RegisterRules task = new RegisterRules(loader, ruleActivator, dbClient, languages, system);
    task.start();
  }
View Full Code Here


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

  @Test
  public void should_index_java_files() throws IOException {
    fs.add(newInputFile("src/main/java/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false));
    fs.add(newInputFile("src/main/java2/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false));
    fs.add(newInputFile("src/test/java/foo/bar/FooTest.java", "", "foo/bar/FooTest.java", "java", true));
    Languages languages = new Languages(Java.INSTANCE);
    ComponentIndexer indexer = createIndexer(languages);
    indexer.execute(fs);

    verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false));
    verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false));
View Full Code Here

  public void should_index_cobol_files() throws IOException {
    fs.add(newInputFile("src/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false));
    fs.add(newInputFile("src2/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false));
    fs.add(newInputFile("src/test/foo/bar/FooTest.cbl", "", "foo/bar/FooTest.cbl", "cobol", true));

    Languages languages = new Languages(cobolLanguage);
    ComponentIndexer indexer = createIndexer(languages);
    indexer.execute(fs);

    verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false));
    verify(sonarIndex).index(org.sonar.api.resources.File.create("/src2/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false));
View Full Code Here

  }

  @Test
  public void shouldImportSource() throws IOException {
    fs.add(newInputFile("src/main/java/foo/bar/Foo.java", "sample code", "foo/bar/Foo.java", "java", false));
    Languages languages = new Languages(Java.INSTANCE);
    ComponentIndexer indexer = createIndexer(languages);
    indexer.execute(fs);

    Resource sonarFile = org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
    verify(sonarIndex).index(sonarFile);
View Full Code Here

    FileUtils.write(javaFile1, "\uFEFFpublic class Test", Charsets.UTF_8);
    fs.add(new DeprecatedDefaultInputFile("foo", "src/main/java/foo/bar/Foo.java")
      .setPathRelativeToSourceDir("foo/bar/Foo.java")
      .setFile(javaFile1)
      .setLanguage("java"));
    Languages languages = new Languages(Java.INSTANCE);
    ComponentIndexer indexer = createIndexer(languages);
    indexer.execute(fs);

    Resource sonarFile = org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
View Full Code Here

    FileUtils.copyFile(getFile(testFile), javaFile1);
    fs.add(new DeprecatedDefaultInputFile("foo", "src/main/java/foo/bar/Foo.java")
      .setPathRelativeToSourceDir("foo/bar/Foo.java")
      .setFile(javaFile1)
      .setLanguage("java"));
    Languages languages = new Languages(Java.INSTANCE);
    ComponentIndexer indexer = createIndexer(languages);
    indexer.execute(fs);

    Resource sonarFile = org.sonar.api.resources.File.create("/src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
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

TOP

Related Classes of org.sonar.api.resources.Languages

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.