diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2024-11-06 16:20:51 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-11 20:02:44 +0000 |
commit | 93c69969195abe9ae4399e7930c0c58c59ffedf6 (patch) | |
tree | 5feed78f57c64969bedeff60d8f15ee059dc8fc3 /sonar-core | |
parent | 459cbaf76d35b4138ab37cdeb7a7c53bf6e9e514 (diff) | |
download | sonarqube-93c69969195abe9ae4399e7930c0c58c59ffedf6.tar.gz sonarqube-93c69969195abe9ae4399e7930c0c58c59ffedf6.zip |
SONAR-23363 handle manual impact flag during project analysis
Diffstat (limited to 'sonar-core')
3 files changed, 49 insertions, 5 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultImpact.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultImpact.java new file mode 100644 index 00000000000..36ea21eca93 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultImpact.java @@ -0,0 +1,26 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.issue; + +import org.sonar.api.issue.impact.Severity; +import org.sonar.api.issue.impact.SoftwareQuality; + +public record DefaultImpact(SoftwareQuality softwareQuality, Severity severity, boolean manualSeverity) { +} diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index b8c46a299af..dc4fb271e3d 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -28,14 +28,15 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.EnumMap; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang3.StringUtils; @@ -137,7 +138,7 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. private String anticipatedTransitionUuid = null; - private Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts = new EnumMap<>(SoftwareQuality.class); + private final Map<SoftwareQuality, DefaultImpact> impacts = new LinkedHashMap<>(); private CleanCodeAttribute cleanCodeAttribute = null; private String cveId = null; @@ -159,17 +160,26 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. @Override public Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts() { - return impacts; + return impacts.values().stream().collect(Collectors.toMap(DefaultImpact::softwareQuality, DefaultImpact::severity)); + } + + public Set<DefaultImpact> getImpacts() { + return new LinkedHashSet<>(this.impacts.values()); } public DefaultIssue replaceImpacts(Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts) { this.impacts.clear(); - this.impacts.putAll(impacts); + this.impacts.putAll(impacts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new DefaultImpact(e.getKey(), e.getValue(), false)))); return this; } public DefaultIssue addImpact(SoftwareQuality softwareQuality, org.sonar.api.issue.impact.Severity severity) { - impacts.put(softwareQuality, severity); + impacts.put(softwareQuality, new DefaultImpact(softwareQuality, severity, false)); + return this; + } + + public DefaultIssue addImpact(SoftwareQuality softwareQuality, org.sonar.api.issue.impact.Severity severity, boolean manualSeverity) { + impacts.put(softwareQuality, new DefaultImpact(softwareQuality, severity, manualSeverity)); return this; } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java index a50efdc2ef4..ad935a1f7ad 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java @@ -324,6 +324,14 @@ class DefaultIssueTest { } @Test + void addImpact_shouldReplaceExistingSoftwareQuality() { + issue.addImpact(SoftwareQuality.MAINTAINABILITY, Severity.HIGH); + issue.addImpact(SoftwareQuality.MAINTAINABILITY, Severity.LOW, true); + assertThat(issue.getImpacts()) + .containsExactly(new DefaultImpact(SoftwareQuality.MAINTAINABILITY, Severity.LOW, true)); + } + + @Test void prioritizedRule_shouldHaveCorrectDefaultValue() { assertThat(issue.isPrioritizedRule()).isFalse(); issue.setPrioritizedRule(true); |