Search in sources :

Example 6 with FilePredicate

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

the class DecimalScaleSensor method analyse.

@Override
public void analyse(Project module, SensorContext context) {
    if (context.settings().getBoolean(DecimalScaleProperty.KEY)) {
        FilePredicate all = context.fileSystem().predicates().all();
        Iterable<InputFile> files = context.fileSystem().inputFiles(all);
        double value = 0.0001;
        for (InputFile file : files) {
            LOG.info("Value for {}: {}", file.relativePath(), value);
            context.newMeasure().on(file).forMetric(DecimalScaleMetric.definition()).withValue(value).save();
            value += 0.0001;
        }
    }
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate) InputFile(org.sonar.api.batch.fs.InputFile)

Example 7 with FilePredicate

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

the class OneIssuePerUnknownFileSensor method execute.

@Override
public void execute(SensorContext context) {
    RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
    FilePredicate unknownFilesPredicate = context.fileSystem().predicates().matchesPathPattern("**/*.unknown");
    Iterable<InputFile> unknownFiles = context.fileSystem().inputFiles(unknownFilesPredicate);
    unknownFiles.forEach(inputFile -> {
        NewIssue newIssue = context.newIssue();
        newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputFile).message("This issue is generated on each file with extension 'unknown'")).save();
    });
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) FilePredicate(org.sonar.api.batch.fs.FilePredicate) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) InputFile(org.sonar.api.batch.fs.InputFile)

Example 8 with FilePredicate

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

the class AndPredicate method create.

public static FilePredicate create(Collection<FilePredicate> predicates) {
    if (predicates.isEmpty()) {
        return TruePredicate.TRUE;
    }
    AndPredicate result = new AndPredicate();
    for (FilePredicate filePredicate : predicates) {
        if (filePredicate == TruePredicate.TRUE) {
            continue;
        } else if (filePredicate == FalsePredicate.FALSE) {
            return FalsePredicate.FALSE;
        } else if (filePredicate instanceof AndPredicate) {
            result.predicates.addAll(((AndPredicate) filePredicate).predicates);
        } else {
            result.predicates.add(OptimizedFilePredicateAdapter.create(filePredicate));
        }
    }
    Collections.sort(result.predicates);
    return result;
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate)

Example 9 with FilePredicate

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

the class AndPredicateTest method sortPredicatesByPriority.

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

Example 10 with FilePredicate

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

the class AndPredicateTest method simplifyAndExpressionsWhenFalse.

@Test
public void simplifyAndExpressionsWhenFalse() {
    PathPatternPredicate pathPatternPredicate1 = new PathPatternPredicate(PathPattern.create("foo1/**"));
    PathPatternPredicate pathPatternPredicate2 = new PathPatternPredicate(PathPattern.create("foo2/**"));
    FilePredicate andPredicate = AndPredicate.create(Arrays.<FilePredicate>asList(pathPatternPredicate1, FalsePredicate.FALSE, pathPatternPredicate2));
    assertThat(andPredicate).isEqualTo(FalsePredicate.FALSE);
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate) 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