Search in sources :

Example 1 with FilePredicate

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

the class AndPredicateTest method flattenNestedAnd.

@Test
public void flattenNestedAnd() {
    PathPatternPredicate pathPatternPredicate1 = new PathPatternPredicate(PathPattern.create("foo1/**"));
    PathPatternPredicate pathPatternPredicate2 = new PathPatternPredicate(PathPattern.create("foo2/**"));
    PathPatternPredicate pathPatternPredicate3 = new PathPatternPredicate(PathPattern.create("foo3/**"));
    FilePredicate andPredicate = AndPredicate.create(Arrays.<FilePredicate>asList(pathPatternPredicate1, AndPredicate.create(Arrays.<FilePredicate>asList(pathPatternPredicate2, pathPatternPredicate3))));
    assertThat(((AndPredicate) andPredicate).predicates()).containsExactly(pathPatternPredicate1, pathPatternPredicate2, pathPatternPredicate3);
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate) Test(org.junit.Test)

Example 2 with FilePredicate

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

the class AndPredicateTest method simplifyAndExpressionsWhenTrue.

@Test
public void simplifyAndExpressionsWhenTrue() {
    PathPatternPredicate pathPatternPredicate1 = new PathPatternPredicate(PathPattern.create("foo1/**"));
    PathPatternPredicate pathPatternPredicate2 = new PathPatternPredicate(PathPattern.create("foo2/**"));
    FilePredicate andPredicate = AndPredicate.create(Arrays.<FilePredicate>asList(pathPatternPredicate1, TruePredicate.TRUE, pathPatternPredicate2));
    assertThat(((AndPredicate) andPredicate).predicates()).containsExactly(pathPatternPredicate1, pathPatternPredicate2);
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate) Test(org.junit.Test)

Example 3 with FilePredicate

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

the class OrPredicateTest method simplifyAndExpressionsWhenTrue.

@Test
public void simplifyAndExpressionsWhenTrue() {
    PathPatternPredicate pathPatternPredicate1 = new PathPatternPredicate(PathPattern.create("foo1/**"));
    PathPatternPredicate pathPatternPredicate2 = new PathPatternPredicate(PathPattern.create("foo2/**"));
    FilePredicate andPredicate = OrPredicate.create(Arrays.<FilePredicate>asList(pathPatternPredicate1, TruePredicate.TRUE, pathPatternPredicate2));
    assertThat(andPredicate).isEqualTo(TruePredicate.TRUE);
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate) Test(org.junit.Test)

Example 4 with FilePredicate

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

the class SensorOptimizer method fsCondition.

private boolean fsCondition(DefaultSensorDescriptor descriptor) {
    if (!descriptor.languages().isEmpty() || descriptor.type() != null) {
        FilePredicate langPredicate = descriptor.languages().isEmpty() ? fs.predicates().all() : fs.predicates().hasLanguages(descriptor.languages());
        FilePredicate typePredicate = descriptor.type() == null ? fs.predicates().all() : fs.predicates().hasType(descriptor.type());
        return fs.hasFiles(fs.predicates().and(langPredicate, typePredicate));
    }
    return true;
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate)

Example 5 with FilePredicate

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

the class AdditionalFilePredicatesTest method key.

@Test
public void key() {
    FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java");
    InputFile inputFile = new TestInputFileBuilder("struts", "Action.java").build();
    assertThat(predicate.apply(inputFile)).isTrue();
    inputFile = new TestInputFileBuilder("struts", "Filter.java").build();
    assertThat(predicate.apply(inputFile)).isFalse();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) FilePredicate(org.sonar.api.batch.fs.FilePredicate) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

FilePredicate (org.sonar.api.batch.fs.FilePredicate)14 Test (org.junit.Test)10 InputFile (org.sonar.api.batch.fs.InputFile)3 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)1 RuleKey (org.sonar.api.rule.RuleKey)1