diff options
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java | 10 | ||||
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java | 12 |
2 files changed, 20 insertions, 2 deletions
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<ScannerReport.Impact> toProtobufImpacts(Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> softwareQualitySeverityMap) { + List<ScannerReport.Impact> impacts = new ArrayList<>(); + softwareQualitySeverityMap.forEach((q, s) -> impacts.add(ScannerReport.Impact.newBuilder().setSoftwareQuality(q.name()).setSeverity(s.name()).build())); + return impacts; + } + private static List<ScannerReport.MessageFormatting> toProtobufMessageFormattings(List<MessageFormatting> messageFormattings) { return messageFormattings.stream() .map(m -> ScannerReport.MessageFormatting.newBuilder() diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java index faaea60e599..c8bc5f78445 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java @@ -42,6 +42,7 @@ import org.sonar.api.batch.sensor.issue.internal.DefaultExternalIssue; import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation; import org.sonar.api.batch.sensor.issue.internal.DefaultMessageFormatting; +import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.api.rules.RuleType; @@ -59,10 +60,11 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static org.sonar.api.batch.sensor.issue.MessageFormatting.Type.CODE; +import static org.sonar.api.issue.impact.SoftwareQuality.*; @RunWith(MockitoJUnitRunner.class) public class IssuePublisherTest { - static final RuleKey JAVA_RULE_KEY = RuleKey.of("java", "AvoidCycle"); + private static final RuleKey JAVA_RULE_KEY = RuleKey.of("java", "AvoidCycle"); private static final RuleKey NOSONAR_RULE_KEY = RuleKey.of("java", "NoSonarCheck"); private DefaultInputProject project; @@ -128,7 +130,9 @@ public class IssuePublisherTest { .overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL) .setQuickFixAvailable(true) .setRuleDescriptionContextKey(ruleDescriptionContextKey) - .setCodeVariants(List.of("variant1", "variant2")); + .setCodeVariants(List.of("variant1", "variant2")) + .overrideImpact(MAINTAINABILITY, org.sonar.api.issue.impact.Severity.HIGH) + .overrideImpact(RELIABILITY, org.sonar.api.issue.impact.Severity.LOW); when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true); @@ -141,6 +145,10 @@ public class IssuePublisherTest { assertThat(argument.getValue().getQuickFixAvailable()).isTrue(); assertThat(argument.getValue().getRuleDescriptionContextKey()).isEqualTo(ruleDescriptionContextKey); assertThat(argument.getValue().getCodeVariantsList()).containsExactly("variant1", "variant2"); + + ScannerReport.Impact impact1 = ScannerReport.Impact.newBuilder().setSoftwareQuality(MAINTAINABILITY.name()).setSeverity("HIGH").build(); + ScannerReport.Impact impact2 = ScannerReport.Impact.newBuilder().setSoftwareQuality(RELIABILITY.name()).setSeverity("LOW").build(); + assertThat(argument.getValue().getOverridenImpactsList()).containsExactly(impact1, impact2); } @Test |