Skip to content

Commit

Permalink
SLCORE-1023 Sync for Custom Severities with INFO and BLOCKER Does not…
Browse files Browse the repository at this point in the history
… Work
  • Loading branch information
nquinquenel committed Nov 5, 2024
1 parent 7c7b4da commit 352d42b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion API_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 10.8
# 10.9

## New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -162,17 +158,28 @@ public static RuleDetails merging(ServerActiveRule activeRuleFromStorage, Server

public static Map<SoftwareQuality, ImpactSeverity> mergeImpacts(Map<SoftwareQuality, ImpactSeverity> defaultImpacts,
List<ImpactPayload> overriddenImpacts) {
Map<SoftwareQuality, ImpactSeverity> 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, ImpactSeverity>(SoftwareQuality.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ void it_should_only_override_overridden_impact_quality() {
);

Map<SoftwareQuality, ImpactSeverity> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public static class ActiveRule {
private final IssueSeverity severity;
private final Map<String, String> parameters;
private final String templateKey;
private final List<ImpactPayload> impacts;
private final List<ImpactPayload> overridenImpacts;

public ActiveRule(String key, String languageKey, IssueSeverity severity, Map<String, String> parameters,
@Nullable String templateKey, List<ImpactPayload> impacts) {
@Nullable String templateKey, List<ImpactPayload> 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() {
Expand All @@ -89,7 +89,7 @@ public String getTemplateKey() {
}

public List<ImpactPayload> getOverriddenImpacts() {
return impacts;
return overridenImpacts;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 352d42b

Please sign in to comment.