use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.
the class OneIssuePerTestFileSensor method execute.
@Override
public void execute(SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
if (activeRules.find(ruleKey) == null) {
return;
}
FilePredicates p = fs.predicates();
for (InputFile inputFile : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.TEST)))) {
processFile(inputFile, context, ruleKey);
}
}
use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.
the class OnePredefinedRuleExternalIssuePerLineSensor method execute.
@Override
public void execute(SensorContext context) {
FileSystem fs = context.fileSystem();
FilePredicates p = fs.predicates();
for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) {
createIssues(file, context);
}
}
use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.
the class OneQuickFixPerLineSensor method analyse.
private void analyse(SensorContext context, String language, String repo) {
FileSystem fs = context.fileSystem();
FilePredicates p = fs.predicates();
for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(language), p.hasType(Type.MAIN)))) {
createIssues(file, context, repo);
}
}
use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.
the class ChecksSensor method execute.
@Override
public void execute(SensorContext context) {
Checks<Check> checks = checkFactory.create(XooRulesDefinition.XOO_REPOSITORY);
checks.addAnnotatedChecks((Object[]) Check.ALL);
FilePredicates p = context.fileSystem().predicates();
for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) {
for (Check check : checks.all()) {
check.execute(context, file, checks.ruleKey(check));
}
}
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-apple by insideapp-oss.
the class ReportIssueRecorder method recordIssues.
public void recordIssues(List<ReportIssue> issues, String repository) {
final FileSystem fs = sensorContext.fileSystem();
final FilePredicates predicates = fs.predicates();
FilePredicate mainPredicate = predicates.hasType(InputFile.Type.MAIN);
// Record issues
for (ReportIssue issue : issues) {
// The issue to be record
NewIssue sonarIssue = sensorContext.newIssue().forRule(RuleKey.of(repository, issue.getRuleId()));
// The location of the issue to be record
NewIssueLocation sonarIssueLocation = new DefaultIssueLocation().message(issue.getMessage());
final String filePath = issue.getFilePath();
// We have a file location associated with the generated issue
if (filePath != null) {
final FilePredicate relativePathPredicate = predicates.hasRelativePath(filePath);
final FilePredicate absolutePathPredicate = predicates.hasAbsolutePath(filePath);
final FilePredicate pathPredicate = predicates.or(absolutePathPredicate, relativePathPredicate);
final FilePredicate filePredicate = predicates.and(pathPredicate, mainPredicate);
InputFile inputFile = fs.inputFile(filePredicate);
// Making sure the file is part of SonarQube FS
if (fs.hasFiles(filePredicate) && inputFile != null) {
// Adding the location of the file
sonarIssueLocation.on(inputFile);
final Integer lineNumber = issue.getLineNumber();
// We have a line number for that file
if (lineNumber != null) {
// Adding the line number
sonarIssueLocation.at(inputFile.selectLine(lineNumber));
}
// Associating the location to the issue and saving it.
sonarIssue.at(sonarIssueLocation).save();
} else {
LOGGER.warn("File not included in SonarQube sources {}", filePath);
}
} else {
// No location specified, so a global issue.
// Setting the project as location.
sonarIssueLocation.on(sensorContext.project());
// Associating the location to the issue and saving it.
sonarIssue.at(sonarIssueLocation).save();
}
}
}
Aggregations