use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class DefaultInputFileTest method checkValidPointerUsingGlobalOffset.
@Test
public void checkValidPointerUsingGlobalOffset() {
Metadata metadata = new Metadata(2, 2, "", new int[] { 0, 10 }, new int[] { 8, 15 }, 16);
DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
assertThat(file.newPointer(0).line()).isOne();
assertThat(file.newPointer(0).lineOffset()).isZero();
assertThat(file.newPointer(9).line()).isOne();
// Ignore eol characters
assertThat(file.newPointer(9).lineOffset()).isEqualTo(8);
assertThat(file.newPointer(10).line()).isEqualTo(2);
assertThat(file.newPointer(10).lineOffset()).isZero();
assertThat(file.newPointer(15).line()).isEqualTo(2);
assertThat(file.newPointer(15).lineOffset()).isEqualTo(5);
assertThat(file.newPointer(16).line()).isEqualTo(2);
// Ignore eol characters
assertThat(file.newPointer(16).lineOffset()).isEqualTo(5);
try {
file.newPointer(-1);
fail();
} catch (Exception e) {
assertThat(e).hasMessage("-1 is not a valid offset for a file");
}
try {
file.newPointer(17);
fail();
} catch (Exception e) {
assertThat(e).hasMessage("17 is not a valid offset for file src/Foo.php. Max offset is 16");
}
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class DefaultInputFileTest method checkValidRange.
@Test
public void checkValidRange() {
Metadata metadata = new FileMetadata(mock(AnalysisWarnings.class)).readMetadata(new StringReader("bla bla a\nabcde"));
DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 1)).start().line()).isOne();
// Don't fail
file.newRange(file.newPointer(1, 0), file.newPointer(1, 1));
file.newRange(file.newPointer(1, 0), file.newPointer(1, 9));
file.newRange(file.newPointer(1, 0), file.newPointer(2, 0));
assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 5))).isEqualTo(file.newRange(0, 15));
try {
file.newRange(file.newPointer(1, 0), file.newPointer(1, 0));
fail();
} catch (Exception e) {
assertThat(e).hasMessage("Start pointer [line=1, lineOffset=0] should be before end pointer [line=1, lineOffset=0]");
}
try {
file.newRange(file.newPointer(1, 0), file.newPointer(1, 10));
fail();
} catch (Exception e) {
assertThat(e).hasMessage("10 is not a valid line offset for pointer. File src/Foo.php has 9 character(s) at line 1");
}
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class ProjectExclusionFiltersTest method no_inclusions_nor_exclusions.
@Test
public void no_inclusions_nor_exclusions() {
ProjectExclusionFilters filter = new ProjectExclusionFilters(settings.asConfig());
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java", null);
assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isFalse();
assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.TEST)).isFalse();
assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isTrue();
assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.TEST)).isTrue();
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class ProjectExclusionFiltersTest method match_inclusion.
@Test
public void match_inclusion() {
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
ProjectExclusionFilters filter = new ProjectExclusionFilters(settings.asConfig());
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java", null);
assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isTrue();
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java", null);
assertThat(filter.isIncluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isFalse();
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class ProjectExclusionFiltersTest method match_exclusion_by_absolute_path.
@Test
public void match_exclusion_by_absolute_path() {
File excludedFile = new File(moduleBaseDir.toString(), "src/main/java/org/bar/Bar.java");
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:" + excludedFile.getAbsolutePath());
ProjectExclusionFilters filter = new ProjectExclusionFilters(settings.asConfig());
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Foo.java", null);
assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isFalse();
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Bar.java", null);
assertThat(filter.isExcluded(indexedFile.path(), Paths.get(indexedFile.relativePath()), InputFile.Type.MAIN)).isTrue();
}
Aggregations