Search in sources :

Example 1 with NewIssueLocation

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

the class DeprecatedIssueBuilderWrapper method build.

@Override
public Issue build() {
    if (newIssue.primaryLocation() == null) {
        NewIssueLocation newLocation = newIssue.newLocation().on(primaryComponent);
        if (primaryMessage != null) {
            newLocation.message(primaryMessage);
        }
        if (primaryComponent.isFile() && primaryRange != null) {
            newLocation.at(primaryRange);
        }
        newIssue.at(newLocation);
    }
    return new DeprecatedIssueWrapper(newIssue);
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation)

Example 2 with NewIssueLocation

use of org.sonar.api.batch.sensor.issue.NewIssueLocation 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)

Example 3 with NewIssueLocation

use of org.sonar.api.batch.sensor.issue.NewIssueLocation 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();
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation) RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 4 with NewIssueLocation

use of org.sonar.api.batch.sensor.issue.NewIssueLocation 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();
    }
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation) RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) TextPointer(org.sonar.api.batch.fs.TextPointer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with NewIssueLocation

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

the class CustomMessageSensor method processFile.

@Override
protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
    NewIssue newIssue = context.newIssue().forRule(ruleKey);
    NewIssueLocation location = newIssue.newLocation().on(inputFile);
    settings.get(MESSAGE_PROPERTY).ifPresent(location::message);
    newIssue.at(location).save();
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Aggregations

NewIssueLocation (org.sonar.api.batch.sensor.issue.NewIssueLocation)13 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IssueLocation (org.sonar.api.batch.sensor.issue.IssueLocation)3 InputFile (org.sonar.api.batch.fs.InputFile)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