use of org.sonar.api.batch.sensor.issue.NewIssue in project sonar-web by SonarSource.
the class WebSensor method saveMetrics.
private static void saveMetrics(SensorContext context, WebSourceCode sourceCode) {
InputFile inputFile = sourceCode.inputFile();
saveComplexityDistribution(context, sourceCode);
for (Map.Entry<Metric<Integer>, Integer> entry : sourceCode.getMeasures().entrySet()) {
context.<Integer>newMeasure().on(inputFile).forMetric(entry.getKey()).withValue(entry.getValue()).save();
}
for (WebIssue issue : sourceCode.getIssues()) {
NewIssue newIssue = context.newIssue().forRule(issue.ruleKey()).gap(issue.cost());
Integer line = issue.line();
NewIssueLocation location = newIssue.newLocation().on(inputFile).message(issue.message());
if (line != null) {
location.at(inputFile.selectLine(line));
}
newIssue.at(location);
newIssue.save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonar-go by SonarSource.
the class GoSensor method reportIssue.
private void reportIssue(Issue issue, SensorContext context, InputFile inputFile) {
// TODO improve common rule engine to handle this out of the box
RuleKey ruleKey = checks.ruleKey(issue.getCheck());
Objects.requireNonNull(ruleKey, "Rule key not found for " + issue.getCheck().getClass());
NewIssue newIssue = context.newIssue();
NewIssueLocation location = newIssue.newLocation().on(inputFile).message(issue.getMessage());
if (issue.hasLocation()) {
location.at(newRange(inputFile, issue.getPrimary().from, issue.getPrimary().to));
}
newIssue.forRule(ruleKey).at(location).gap(issue.getEffortToFix());
Arrays.stream(issue.getSecondaries()).forEach(secondary -> newIssue.addLocation(newIssue.newLocation().on(inputFile).at(newRange(inputFile, secondary.from, secondary.to)).message(secondary.description == null ? "" : secondary.description)));
newIssue.save();
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class OneQuickFixPerLineSensor 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.setQuickFixAvailable(true).forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(line)).message("This quick fix issue is generated on each line")).save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssue 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.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class CreateIssueByInternalKeySensor method createIssues.
private static void createIssues(InputFile file, SensorContext context) {
ActiveRule rule = context.activeRules().findByInternalKey(XooRulesDefinition.XOO_REPOSITORY, context.config().get(INTERNAL_KEY_PROPERTY).orElse(null));
if (rule != null) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(rule.ruleKey()).at(newIssue.newLocation().on(file).message("This issue is generated on each file")).save();
}
}
Aggregations