Search in sources :

Example 1 with WebIssue

use of org.sonar.plugins.web.checks.WebIssue 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();
    }
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation) WebIssue(org.sonar.plugins.web.checks.WebIssue) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) Metric(org.sonar.api.measures.Metric) Map(java.util.Map) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

Map (java.util.Map)1 InputFile (org.sonar.api.batch.fs.InputFile)1 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)1 NewIssueLocation (org.sonar.api.batch.sensor.issue.NewIssueLocation)1 Metric (org.sonar.api.measures.Metric)1 WebIssue (org.sonar.plugins.web.checks.WebIssue)1