use of org.sonar.api.batch.fs.internal.PathPattern in project sonarqube by SonarSource.
the class DefaultCpdTokens method onFile.
@Override
public DefaultCpdTokens onFile(InputFile inputFile) {
this.inputFile = requireNonNull(inputFile, "file can't be null");
String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
for (PathPattern cpdExclusion : PathPattern.create(cpdExclusions)) {
if (cpdExclusion.match(inputFile)) {
this.excluded = true;
}
}
return this;
}
use of org.sonar.api.batch.fs.internal.PathPattern in project sonarqube by SonarSource.
the class ExclusionFilters method accept.
public boolean accept(IndexedFile indexedFile, InputFile.Type type) {
PathPattern[] inclusionPatterns;
PathPattern[] exclusionPatterns;
if (InputFile.Type.MAIN == type) {
inclusionPatterns = mainInclusions;
exclusionPatterns = mainExclusions;
} else if (InputFile.Type.TEST == type) {
inclusionPatterns = testInclusions;
exclusionPatterns = testExclusions;
} else {
throw new IllegalArgumentException("Unknown file type: " + type);
}
if (inclusionPatterns.length > 0) {
boolean matchInclusion = false;
for (PathPattern pattern : inclusionPatterns) {
matchInclusion |= pattern.match(indexedFile);
}
if (!matchInclusion) {
return false;
}
}
if (exclusionPatterns.length > 0) {
for (PathPattern pattern : exclusionPatterns) {
if (pattern.match(indexedFile)) {
return false;
}
}
}
return true;
}
use of org.sonar.api.batch.fs.internal.PathPattern in project sonarqube by SonarSource.
the class PathPatternTest method match_absolute_path.
@Test
public void match_absolute_path() {
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()))).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();
}
use of org.sonar.api.batch.fs.internal.PathPattern 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();
}
use of org.sonar.api.batch.fs.internal.PathPattern 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();
}
Aggregations