aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl/src
diff options
context:
space:
mode:
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>2023-08-02 12:07:25 +0200
committersonartech <sonartech@sonarsource.com>2023-08-18 20:02:47 +0000
commitf3028f632704711d23bd27ce35bb04bd56f0b984 (patch)
tree288720d69822f7c1b20948c15689ad7e6bbc567c /sonar-plugin-api-impl/src
parent5f96642125af3af740f79d19e299ca79dbd89545 (diff)
downloadsonarqube-f3028f632704711d23bd27ce35bb04bd56f0b984.tar.gz
sonarqube-f3028f632704711d23bd27ce35bb04bd56f0b984.zip
SONAR-20021 passing overriden impacts from analyzer to scanner report
Diffstat (limited to 'sonar-plugin-api-impl/src')
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java8
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java8
2 files changed, 14 insertions, 2 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
index 4790c3f80a6..38c0d61e041 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
@@ -21,6 +21,8 @@ package org.sonar.api.batch.sensor.issue.internal;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -42,6 +44,7 @@ import static org.sonar.api.utils.Preconditions.checkArgument;
import static org.sonar.api.utils.Preconditions.checkState;
public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements Issue, NewIssue {
+ private final Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> overridenImpacts = new EnumMap<>(SoftwareQuality.class);
private RuleKey ruleKey;
private Double gap;
private Severity overriddenSeverity;
@@ -81,7 +84,8 @@ public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements
@Override
public DefaultIssue overrideImpact(SoftwareQuality softwareQuality, org.sonar.api.issue.impact.Severity severity) {
- return null;
+ overridenImpacts.put(softwareQuality, severity);
+ return this;
}
@Override
@@ -144,7 +148,7 @@ public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements
@Override
public Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> overridenImpacts() {
- return Collections.emptyMap();
+ return overridenImpacts;
}
@Override
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
index f35583825ca..ba3e9e48b94 100644
--- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
+++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
@@ -41,6 +41,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.fix.NewQuickFix;
+import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rule.RuleKey;
import static org.assertj.core.api.Assertions.assertThat;
@@ -235,6 +236,13 @@ public class DefaultIssueTest {
}
@Test
+ public void issue_can_override_impacts() {
+ DefaultIssue issue = new DefaultIssue(project, storage).overrideImpact(SoftwareQuality.RELIABILITY, org.sonar.api.issue.impact.Severity.LOW);
+
+ assertThat(issue.overridenImpacts()).containsEntry(SoftwareQuality.RELIABILITY, org.sonar.api.issue.impact.Severity.LOW);
+ }
+
+ @Test
public void quickfix_only_sets_flag_to_true() {
DefaultIssue issue = new DefaultIssue(project);