Search in sources :

Example 11 with NewIssueLocation

use of org.sonar.api.batch.sensor.issue.NewIssueLocation in project sonar-web by SonarSource.

the class HtmlSensor method locationForIssue.

private static NewIssueLocation locationForIssue(InputFile inputFile, HtmlIssue issue, NewIssue newIssue) {
    NewIssueLocation location = newIssue.newLocation().on(inputFile).message(issue.message());
    Integer line = issue.line();
    if (issue instanceof PreciseHtmlIssue) {
        PreciseHtmlIssue preciseHtmlIssue = (PreciseHtmlIssue) issue;
        location.at(inputFile.newRange(issue.line(), preciseHtmlIssue.startColumn(), preciseHtmlIssue.endLine(), preciseHtmlIssue.endColumn()));
    } else if (line != null) {
        location.at(inputFile.selectLine(line));
    }
    return location;
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation) PreciseHtmlIssue(org.sonar.plugins.html.checks.PreciseHtmlIssue)

Example 12 with NewIssueLocation

use of org.sonar.api.batch.sensor.issue.NewIssueLocation in project sonar-web by SonarSource.

the class HtmlSensor method saveMetrics.

private static void saveMetrics(SensorContext context, HtmlSourceCode sourceCode) {
    InputFile inputFile = sourceCode.inputFile();
    for (Map.Entry<Metric<Integer>, Integer> entry : sourceCode.getMeasures().entrySet()) {
        context.<Integer>newMeasure().on(inputFile).forMetric(entry.getKey()).withValue(entry.getValue()).save();
    }
    for (HtmlIssue issue : sourceCode.getIssues()) {
        NewIssue newIssue = context.newIssue().forRule(issue.ruleKey()).gap(issue.cost());
        NewIssueLocation location = locationForIssue(inputFile, issue, newIssue);
        newIssue.at(location);
        newIssue.save();
    }
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) Metric(org.sonar.api.measures.Metric) PreciseHtmlIssue(org.sonar.plugins.html.checks.PreciseHtmlIssue) HtmlIssue(org.sonar.plugins.html.checks.HtmlIssue) Map(java.util.Map) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

NewIssueLocation (org.sonar.api.batch.sensor.issue.NewIssueLocation)12 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)5 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 InputFile (org.sonar.api.batch.fs.InputFile)2 IssueLocation (org.sonar.api.batch.sensor.issue.IssueLocation)2 Metric (org.sonar.api.measures.Metric)2 RuleKey (org.sonar.api.rule.RuleKey)2 PreciseHtmlIssue (org.sonar.plugins.html.checks.PreciseHtmlIssue)2 HashMap (java.util.HashMap)1 TextPointer (org.sonar.api.batch.fs.TextPointer)1 NewExternalIssue (org.sonar.api.batch.sensor.issue.NewExternalIssue)1 HtmlIssue (org.sonar.plugins.html.checks.HtmlIssue)1 WebIssue (org.sonar.plugins.web.checks.WebIssue)1 Location (org.sonar.scanner.externalissue.ReportParser.Location)1