Search in sources :

Example 16 with IndexedFile

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

the class PathPatternTest method match_relative_path_and_insensitive_file_extension.

@Test
public void match_relative_path_and_insensitive_file_extension() {
    PathPattern pattern = PathPattern.create("**/*Foo.java");
    IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isTrue();
    indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.java", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isFalse();
}
Also used : PathPattern(org.sonar.api.batch.fs.internal.PathPattern) IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Test(org.junit.Test)

Example 17 with IndexedFile

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

the class PathPatternTest method match_relative_path.

@Test
public void match_relative_path() {
    PathPattern pattern = PathPattern.create("**/*Foo.java");
    assertThat(pattern.toString()).isEqualTo("**/*Foo.java");
    IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.java", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isTrue();
    // case sensitive by default
    indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
    indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.java", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
}
Also used : PathPattern(org.sonar.api.batch.fs.internal.PathPattern) IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Test(org.junit.Test)

Example 18 with IndexedFile

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

the class PathPatternTest method match_absolute_path_and_insensitive_file_extension.

@Test
public void match_absolute_path_and_insensitive_file_extension() {
    PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java");
    assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
    IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isTrue();
    indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.JAVA", null);
    assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isFalse();
}
Also used : PathPattern(org.sonar.api.batch.fs.internal.PathPattern) IndexedFile(org.sonar.api.batch.fs.IndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 IndexedFile (org.sonar.api.batch.fs.IndexedFile)18 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)14 MapSettings (org.sonar.api.config.MapSettings)5 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)5 PathPattern (org.sonar.api.batch.fs.internal.PathPattern)4 Settings (org.sonar.api.config.Settings)4 File (java.io.File)2 InputFile (org.sonar.api.batch.fs.InputFile)2