use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class AbstractDeprecatedXooRuleSensor method doAnalyse.
private void doAnalyse(SensorContext context, String languageKey) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, getRuleKey());
if (activeRules.find(ruleKey) == null) {
return;
}
for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(languageKey))) {
File sonarFile = File.create(inputFile.relativePath());
sonarFile = context.getResource(sonarFile);
processFile(inputFile, sonarFile, context, ruleKey, languageKey);
}
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class OneIssuePerDirectorySensor method analyse.
private static void analyse(SensorContext context) {
FileSystem fs = context.fileSystem();
FilePredicates p = fs.predicates();
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
StreamSupport.stream(fs.inputFiles(p.hasType(Type.MAIN)).spliterator(), false).map(file -> fs.inputDir(file.file().getParentFile())).filter(Objects::nonNull).distinct().forEach(inputDir -> {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputDir).message("This issue is generated for any non-empty directory")).save();
});
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RandomAccessSensor method createIssues.
private static void createIssues(InputFile file, SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(1)).message("This issue is generated on each file")).save();
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class MultilineIssuesSensor method createIssues.
private static void createIssues(InputFile file, SensorContext context, Map<Integer, TextPointer> startPositions, Map<Integer, TextPointer> endPositions, Map<Integer, Table<Integer, Integer, TextPointer>> startFlowsPositions, Map<Integer, Table<Integer, Integer, TextPointer>> endFlowsPositions) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
for (Map.Entry<Integer, TextPointer> entry : startPositions.entrySet()) {
NewIssue newIssue = context.newIssue().forRule(ruleKey);
Integer issueId = entry.getKey();
NewIssueLocation primaryLocation = newIssue.newLocation().on(file).at(file.newRange(entry.getValue(), endPositions.get(issueId)));
newIssue.at(primaryLocation.message("Primary location"));
if (startFlowsPositions.containsKey(issueId)) {
Table<Integer, Integer, TextPointer> flows = startFlowsPositions.get(issueId);
for (Map.Entry<Integer, Map<Integer, TextPointer>> flowEntry : flows.rowMap().entrySet()) {
Integer flowId = flowEntry.getKey();
List<NewIssueLocation> flowLocations = Lists.newArrayList();
List<Integer> flowNums = Lists.newArrayList(flowEntry.getValue().keySet());
Collections.sort(flowNums);
for (Integer flowNum : flowNums) {
TextPointer start = flowEntry.getValue().get(flowNum);
TextPointer end = endFlowsPositions.get(issueId).row(flowId).get(flowNum);
NewIssueLocation newLocation = newIssue.newLocation().on(file).at(file.newRange(start, end)).message("Flow step #" + flowNum);
flowLocations.add(newLocation);
}
if (flowLocations.size() == 1) {
newIssue.addLocation(flowLocations.get(0));
} else {
newIssue.addFlow(flowLocations);
}
}
}
newIssue.save();
}
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class OneBugIssuePerLineSensor method createIssues.
private void createIssues(InputFile file, SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
for (int line = 1; line <= file.lines(); line++) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(line)).message("This bug issue is generated on each line")).save();
}
}
Aggregations