diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2023-08-18 14:03:55 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-21 20:02:47 +0000 |
commit | 072791ac2b31eb8f01b686b754c930a1ff4a600e (patch) | |
tree | c3d3e3fa4758c553c9498605a502ca1c9ea0e3cc /sonar-scanner-engine/src/main | |
parent | 522573b028568e85648ca08e84feacb32726ec5c (diff) | |
download | sonarqube-072791ac2b31eb8f01b686b754c930a1ff4a600e.tar.gz sonarqube-072791ac2b31eb8f01b686b754c930a1ff4a600e.zip |
SONAR-20021 Fix Quality gate failure and issue with adhoc rule definition
Diffstat (limited to 'sonar-scanner-engine/src/main')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java index cdd771266b5..e679d683df9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java @@ -57,7 +57,11 @@ import org.sonar.api.batch.sensor.rule.AdHocRule; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; import org.sonar.api.config.Configuration; +import org.sonar.api.issue.impact.Severity; +import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.rules.CleanCodeAttribute; +import org.sonar.api.rules.RuleType; import org.sonar.api.utils.KeyValueFormat; import org.sonar.core.metric.ScannerMetrics; import org.sonar.core.util.CloseableIterator; @@ -257,11 +261,34 @@ public class DefaultSensorStorage implements SensorStorage { if (description != null) { builder.setDescription(description); } - builder.setSeverity(Constants.Severity.valueOf(adHocRule.severity().name())); - builder.setType(ScannerReport.IssueType.valueOf(adHocRule.type().name())); + + + org.sonar.api.batch.rule.Severity severity = adHocRule.severity(); + if (severity != null) { + builder.setSeverity(Constants.Severity.valueOf(severity.name())); + } + + RuleType type = adHocRule.type(); + if (type != null) { + builder.setType(ScannerReport.IssueType.valueOf(type.name())); + } + builder.addAllDefaultImpacts(mapImpacts(adHocRule.defaultImpacts())); + + CleanCodeAttribute cleanCodeAttribute = adHocRule.cleanCodeAttribute(); + if (cleanCodeAttribute != null) { + builder.setCleanCodeAttribute(cleanCodeAttribute.name()); + } writer.appendAdHocRule(builder.build()); } + private static List<ScannerReport.Impact> mapImpacts(Map<SoftwareQuality, Severity> impactsMap) { + return impactsMap.entrySet().stream() + .map(e -> ScannerReport.Impact.newBuilder() + .setSoftwareQuality(e.getKey().name()) + .setSeverity(e.getValue().name()).build()) + .collect(toList()); + } + @Override public void store(NewHighlighting newHighlighting) { DefaultHighlighting highlighting = (DefaultHighlighting) newHighlighting; |