Search in sources :

Example 1 with IssueType

use of org.sonar.scanner.protocol.output.ScannerReport.IssueType in project sonarqube by SonarSource.

the class IssuePublisher method createReportExternalIssue.

private static ScannerReport.ExternalIssue createReportExternalIssue(ExternalIssue issue, int componentRef) {
    // primary location of an external issue must have a message
    String primaryMessage = issue.primaryLocation().message();
    Severity severity = Severity.valueOf(issue.severity().name());
    IssueType issueType = IssueType.valueOf(issue.type().name());
    ScannerReport.ExternalIssue.Builder builder = ScannerReport.ExternalIssue.newBuilder();
    ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
    ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
    // non-null fields
    builder.setSeverity(severity);
    builder.setType(issueType);
    builder.setEngineId(issue.engineId());
    builder.setRuleId(issue.ruleId());
    builder.setMsg(primaryMessage);
    locationBuilder.setMsg(primaryMessage);
    locationBuilder.setComponentRef(componentRef);
    TextRange primaryTextRange = issue.primaryLocation().textRange();
    if (primaryTextRange != null) {
        builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
    }
    Long effort = issue.remediationEffort();
    if (effort != null) {
        builder.setEffort(effort);
    }
    applyFlows(builder::addFlow, locationBuilder, textRangeBuilder, issue.flows());
    return builder.build();
}
Also used : ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) IssueType(org.sonar.scanner.protocol.output.ScannerReport.IssueType) Severity(org.sonar.scanner.protocol.Constants.Severity) TextRange(org.sonar.api.batch.fs.TextRange) IssueLocation(org.sonar.scanner.protocol.output.ScannerReport.IssueLocation)

Aggregations

TextRange (org.sonar.api.batch.fs.TextRange)1 ExternalIssue (org.sonar.api.batch.sensor.issue.ExternalIssue)1 Severity (org.sonar.scanner.protocol.Constants.Severity)1 IssueLocation (org.sonar.scanner.protocol.output.ScannerReport.IssueLocation)1 IssueType (org.sonar.scanner.protocol.output.ScannerReport.IssueType)1