From 352d42b6d9614b9902266f79d211f3d1b0a49b5d Mon Sep 17 00:00:00 2001 From: Nicolas QUINQUENEL Date: Mon, 4 Nov 2024 18:33:39 +0100 Subject: [PATCH] SLCORE-1023 Sync for Custom Severities with INFO and BLOCKER Does not Work --- API_CHANGES.md | 2 +- .../sonarlint/core/rules/RuleDetails.java | 19 +++++++++++++------ .../core/rules/RulesServiceTests.java | 5 +++-- .../serverapi/push/RuleSetChangedEvent.java | 8 ++++---- .../AnalyzerConfigurationStorage.java | 1 - 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/API_CHANGES.md b/API_CHANGES.md index 5a67c1bad4..748d6c4334 100644 --- a/API_CHANGES.md +++ b/API_CHANGES.md @@ -1,4 +1,4 @@ -# 10.8 +# 10.9 ## New features diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetails.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetails.java index 38da04a49a..02abed07e0 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetails.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetails.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -39,9 +38,6 @@ import org.sonarsource.sonarlint.core.commons.VulnerabilityProbability; import org.sonarsource.sonarlint.core.commons.api.SonarLanguage; import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.StandaloneRuleConfigDto; -import org.sonarsource.sonarlint.core.commons.VulnerabilityProbability; -import org.sonarsource.sonarlint.core.commons.api.SonarLanguage; -import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.StandaloneRuleConfigDto; import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.TaintVulnerabilityDto; import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.RaisedFindingDto; import org.sonarsource.sonarlint.core.rule.extractor.SonarLintRuleDefinition; @@ -162,17 +158,28 @@ public static RuleDetails merging(ServerActiveRule activeRuleFromStorage, Server public static Map mergeImpacts(Map defaultImpacts, List overriddenImpacts) { - Map mergedImpacts = new HashMap<>(defaultImpacts); + if (defaultImpacts.isEmpty()) return Collections.emptyMap(); + var mergedImpacts = new EnumMap<>(defaultImpacts); for (ImpactPayload impact : overriddenImpacts) { var quality = SoftwareQuality.valueOf(impact.getSoftwareQuality()); - var severity = ImpactSeverity.valueOf(impact.getSeverity()); + var severity = mapSeverity(impact.getSeverity()); mergedImpacts.computeIfPresent(quality, (k, v) -> severity); } return Collections.unmodifiableMap(mergedImpacts); } + private static ImpactSeverity mapSeverity(String severity) { + if ("BLOCKER".equals(severity) || "ImpactSeverity_BLOCKER".equals(severity)) { + return ImpactSeverity.BLOCKER; + } else if ("INFO".equals(severity) || "ImpactSeverity_INFO".equals(severity)) { + return ImpactSeverity.INFO; + } else { + return ImpactSeverity.valueOf(severity); + } + } + public static RuleDetails merging(RuleDetails serverActiveRuleDetails, RaisedFindingDto raisedFindingDto) { var isMQRMode = raisedFindingDto.getSeverityMode().isRight(); var softwareImpacts = new EnumMap(SoftwareQuality.class); diff --git a/backend/core/src/test/java/org/sonarsource/sonarlint/core/rules/RulesServiceTests.java b/backend/core/src/test/java/org/sonarsource/sonarlint/core/rules/RulesServiceTests.java index 361993955e..7c91f162b2 100644 --- a/backend/core/src/test/java/org/sonarsource/sonarlint/core/rules/RulesServiceTests.java +++ b/backend/core/src/test/java/org/sonarsource/sonarlint/core/rules/RulesServiceTests.java @@ -73,8 +73,9 @@ void it_should_only_override_overridden_impact_quality() { ); Map result = RuleDetails.mergeImpacts(defaultImpacts, overriddenImpacts); - assertThat(result).containsEntry(SoftwareQuality.MAINTAINABILITY, ImpactSeverity.HIGH); - assertThat(result).containsEntry(SoftwareQuality.RELIABILITY, ImpactSeverity.MEDIUM); + assertThat(result) + .containsEntry(SoftwareQuality.MAINTAINABILITY, ImpactSeverity.HIGH) + .containsEntry(SoftwareQuality.RELIABILITY, ImpactSeverity.MEDIUM); } @Test diff --git a/backend/server-api/src/main/java/org/sonarsource/sonarlint/core/serverapi/push/RuleSetChangedEvent.java b/backend/server-api/src/main/java/org/sonarsource/sonarlint/core/serverapi/push/RuleSetChangedEvent.java index 724da627cd..04f09e9157 100644 --- a/backend/server-api/src/main/java/org/sonarsource/sonarlint/core/serverapi/push/RuleSetChangedEvent.java +++ b/backend/server-api/src/main/java/org/sonarsource/sonarlint/core/serverapi/push/RuleSetChangedEvent.java @@ -55,16 +55,16 @@ public static class ActiveRule { private final IssueSeverity severity; private final Map parameters; private final String templateKey; - private final List impacts; + private final List overridenImpacts; public ActiveRule(String key, String languageKey, IssueSeverity severity, Map parameters, - @Nullable String templateKey, List impacts) { + @Nullable String templateKey, List overridenImpacts) { this.key = key; this.languageKey = languageKey; this.severity = severity; this.parameters = parameters; this.templateKey = templateKey; - this.impacts = impacts; + this.overridenImpacts = overridenImpacts; } public String getKey() { @@ -89,7 +89,7 @@ public String getTemplateKey() { } public List getOverriddenImpacts() { - return impacts; + return overridenImpacts; } } } diff --git a/backend/server-connection/src/main/java/org/sonarsource/sonarlint/core/serverconnection/AnalyzerConfigurationStorage.java b/backend/server-connection/src/main/java/org/sonarsource/sonarlint/core/serverconnection/AnalyzerConfigurationStorage.java index 741258da02..80b51e48bb 100644 --- a/backend/server-connection/src/main/java/org/sonarsource/sonarlint/core/serverconnection/AnalyzerConfigurationStorage.java +++ b/backend/server-connection/src/main/java/org/sonarsource/sonarlint/core/serverconnection/AnalyzerConfigurationStorage.java @@ -20,7 +20,6 @@ package org.sonarsource.sonarlint.core.serverconnection; import java.nio.file.Path; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.UnaryOperator;