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;
}
}
}
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();
});
}
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;
}
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);
}
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);
}
Aggregations