Search in sources :

Example 1 with DefaultIndexedFile

use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.

the class InputFileBuilder method create.

@CheckForNull
DefaultInputFile create(Path file, InputFile.Type type, Charset defaultEncoding) {
    String relativePath = pathResolver.relativePath(moduleBaseDir, file);
    if (relativePath == null) {
        LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", file.toAbsolutePath(), moduleBaseDir);
        return null;
    }
    DefaultIndexedFile indexedFile = new DefaultIndexedFile(moduleKey, moduleBaseDir, relativePath, type, idGenerator.get());
    String language = langDetection.language(indexedFile);
    if (language == null && langDetection.forcedLanguage() != null) {
        LOG.warn("File '{}' is ignored because it doens't belong to the forced langauge '{}'", file.toAbsolutePath(), langDetection.forcedLanguage());
        return null;
    }
    indexedFile.setLanguage(language);
    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(f, defaultEncoding));
    if (language != null) {
        inputFile.setPublish(true);
    }
    return inputFile;
}
Also used : DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) CheckForNull(javax.annotation.CheckForNull)

Example 2 with DefaultIndexedFile

use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.

the class ExclusionFiltersTest method match_inclusion.

@Test
public void match_inclusion() throws IOException {
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
    ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
    filter.prepare();
    IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
    indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isFalse();
}
Also used : FileExclusions(org.sonar.api.scan.filesystem.FileExclusions) IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) MapSettings(org.sonar.api.config.MapSettings) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 3 with DefaultIndexedFile

use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.

the class DefaultInputFileTest method test_equals_and_hashcode.

@Test
public void test_equals_and_hashcode() {
    DefaultInputFile f1 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
    DefaultInputFile f1a = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
    DefaultInputFile f2 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), "src/Bar.php", null), (f) -> mock(Metadata.class));
    assertThat(f1).isEqualTo(f1).isEqualTo(f1a).isNotEqualTo(f2);
    assertThat(f1.equals("foo")).isFalse();
    assertThat(f1.equals(null)).isFalse();
    assertThat(f1).hasSameHashCodeAs(f1).hasSameHashCodeAs(f1a);
}
Also used : DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) FileMetadata(org.sonar.api.batch.fs.internal.FileMetadata) Metadata(org.sonar.api.batch.fs.internal.Metadata) Test(org.junit.Test)

Example 4 with DefaultIndexedFile

use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.

the class DefaultInputFileTest method prepare.

@Before
public void prepare() throws IOException {
    baseDir = temp.newFolder().toPath();
    sensorStrategy = new SensorStrategy();
    indexedFile = new DefaultIndexedFile(baseDir.resolve(PROJECT_RELATIVE_PATH), "ABCDE", PROJECT_RELATIVE_PATH, MODULE_RELATIVE_PATH, InputFile.Type.TEST, "php", 0, sensorStrategy);
}
Also used : DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) SensorStrategy(org.sonar.api.batch.fs.internal.SensorStrategy) Before(org.junit.Before)

Example 5 with DefaultIndexedFile

use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.

the class DefaultInputFileTest method test_toString.

@Test
public void test_toString() {
    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
    assertThat(file.toString()).isEqualTo(MODULE_RELATIVE_PATH);
}
Also used : DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) FileMetadata(org.sonar.api.batch.fs.internal.FileMetadata) Metadata(org.sonar.api.batch.fs.internal.Metadata) Test(org.junit.Test)

Aggregations

DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)25 Test (org.junit.Test)22 IndexedFile (org.sonar.api.batch.fs.IndexedFile)14 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)10 FileMetadata (org.sonar.api.batch.fs.internal.FileMetadata)8 Metadata (org.sonar.api.batch.fs.internal.Metadata)8 MapSettings (org.sonar.api.config.MapSettings)5 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)5 IOException (java.io.IOException)4 PathPattern (org.sonar.api.batch.fs.internal.PathPattern)4 Settings (org.sonar.api.config.Settings)4 File (java.io.File)2 StringReader (java.io.StringReader)2 InputFile (org.sonar.api.batch.fs.InputFile)2 Path (java.nio.file.Path)1 CheckForNull (javax.annotation.CheckForNull)1 Before (org.junit.Before)1 TextRange (org.sonar.api.batch.fs.TextRange)1 SensorStrategy (org.sonar.api.batch.fs.internal.SensorStrategy)1 Language (org.sonar.scanner.repository.language.Language)1