Search in sources :

Example 1 with Severity

use of org.sonar.scanner.protocol.Constants.Severity in project sonarqube by SonarSource.

the class ModuleIssues method initAndAddIssue.

public boolean initAndAddIssue(Issue issue) {
    DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent();
    Rule rule = validateRule(issue);
    ActiveRule activeRule = activeRules.find(issue.ruleKey());
    if (activeRule == null) {
        // rule does not exist or is not enabled -> ignore the issue
        return false;
    }
    String primaryMessage = Strings.isNullOrEmpty(issue.primaryLocation().message()) ? rule.name() : issue.primaryLocation().message();
    org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
    Severity severity = overriddenSeverity != null ? Severity.valueOf(overriddenSeverity.name()) : Severity.valueOf(activeRule.severity());
    ScannerReport.Issue.Builder builder = ScannerReport.Issue.newBuilder();
    ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
    ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
    // non-null fields
    builder.setSeverity(severity);
    builder.setRuleRepository(issue.ruleKey().repository());
    builder.setRuleKey(issue.ruleKey().rule());
    builder.setMsg(primaryMessage);
    locationBuilder.setMsg(primaryMessage);
    locationBuilder.setComponentRef(inputComponent.batchId());
    TextRange primaryTextRange = issue.primaryLocation().textRange();
    if (primaryTextRange != null) {
        builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
    }
    Double gap = issue.gap();
    if (gap != null) {
        builder.setGap(gap);
    }
    applyFlows(builder, locationBuilder, textRangeBuilder, issue);
    ScannerReport.Issue rawIssue = builder.build();
    if (filters.accept(inputComponent.key(), rawIssue)) {
        write(inputComponent.batchId(), rawIssue);
        return true;
    }
    return false;
}
Also used : Issue(org.sonar.api.batch.sensor.issue.Issue) ActiveRule(org.sonar.api.batch.rule.ActiveRule) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) Severity(org.sonar.scanner.protocol.Constants.Severity) TextRange(org.sonar.api.batch.fs.TextRange) IssueLocation(org.sonar.scanner.protocol.output.ScannerReport.IssueLocation) DefaultInputComponent(org.sonar.api.batch.fs.internal.DefaultInputComponent) ActiveRule(org.sonar.api.batch.rule.ActiveRule) Rule(org.sonar.api.batch.rule.Rule)

Aggregations

TextRange (org.sonar.api.batch.fs.TextRange)1 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)1 ActiveRule (org.sonar.api.batch.rule.ActiveRule)1 Rule (org.sonar.api.batch.rule.Rule)1 Issue (org.sonar.api.batch.sensor.issue.Issue)1 Severity (org.sonar.scanner.protocol.Constants.Severity)1 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)1 IssueLocation (org.sonar.scanner.protocol.output.ScannerReport.IssueLocation)1