Search in sources :

Example 6 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 7 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)

Example 8 with DefaultIndexedFile

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

the class DefaultInputFileTest method checkValidRangeUsingGlobalOffset.

@Test
public void checkValidRangeUsingGlobalOffset() {
    Metadata metadata = new Metadata(2, 2, "", new int[] { 0, 10 }, new int[] { 9, 15 }, 16);
    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
    TextRange newRange = file.newRange(10, 13);
    assertThat(newRange.start().line()).isEqualTo(2);
    assertThat(newRange.start().lineOffset()).isZero();
    assertThat(newRange.end().line()).isEqualTo(2);
    assertThat(newRange.end().lineOffset()).isEqualTo(3);
}
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) TextRange(org.sonar.api.batch.fs.TextRange) Test(org.junit.Test)

Example 9 with DefaultIndexedFile

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

the class DefaultInputFileTest method testRangeOverlap.

@Test
public void testRangeOverlap() {
    Metadata metadata = new Metadata(2, 2, "", new int[] { 0, 10 }, new int[] { 9, 15 }, 16);
    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
    // Don't fail
    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)))).isTrue();
    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isTrue();
    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 1), file.newPointer(1, 2)))).isFalse();
    assertThat(file.newRange(file.newPointer(1, 2), file.newPointer(1, 3)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isFalse();
}
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 10 with DefaultIndexedFile

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

the class ExclusionFiltersTest method no_inclusions_nor_exclusions.

@Test
public void no_inclusions_nor_exclusions() throws IOException {
    ExclusionFilters filter = new ExclusionFilters(new FileExclusions(new MapSettings()));
    filter.prepare();
    IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
    assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
    assertThat(filter.accept(indexedFile, InputFile.Type.TEST)).isTrue();
}
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) 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