From f3028f632704711d23bd27ce35bb04bd56f0b984 Mon Sep 17 00:00:00 2001 From: lukasz-jarocki-sonarsource Date: Wed, 2 Aug 2023 12:07:25 +0200 Subject: SONAR-20021 passing overriden impacts from analyzer to scanner report --- .../src/main/java/org/sonar/scanner/issue/IssuePublisher.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sonar-scanner-engine/src/main/java/org') diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java index 5e3b7a6d254..3b2f99fecaf 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java @@ -19,8 +19,10 @@ */ package org.sonar.scanner.issue; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.function.Consumer; import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -37,6 +39,7 @@ import org.sonar.api.batch.sensor.issue.Issue.Flow; import org.sonar.api.batch.sensor.issue.MessageFormatting; import org.sonar.api.batch.sensor.issue.NewIssue.FlowType; import org.sonar.api.batch.sensor.issue.internal.DefaultIssueFlow; +import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.scanner.protocol.Constants.Severity; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.IssueLocation; @@ -116,6 +119,7 @@ public class IssuePublisher { builder.setRuleKey(issue.ruleKey().rule()); builder.setMsg(primaryMessage); builder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings())); + builder.addAllOverridenImpacts(toProtobufImpacts(issue.overridenImpacts())); locationBuilder.setMsg(primaryMessage); locationBuilder.addAllMsgFormatting(toProtobufMessageFormattings(issue.primaryLocation().messageFormattings())); @@ -138,6 +142,12 @@ public class IssuePublisher { return builder.build(); } + private static List toProtobufImpacts(Map softwareQualitySeverityMap) { + List impacts = new ArrayList<>(); + softwareQualitySeverityMap.forEach((q, s) -> impacts.add(ScannerReport.Impact.newBuilder().setSoftwareQuality(q.name()).setSeverity(s.name()).build())); + return impacts; + } + private static List toProtobufMessageFormattings(List messageFormattings) { return messageFormattings.stream() .map(m -> ScannerReport.MessageFormatting.newBuilder() -- cgit v1.2.3