diff options
author | Steve Marion <steve.marion@sonarsource.com> | 2024-07-26 11:13:16 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-07-29 20:02:48 +0000 |
commit | 8305ff20174aee249f2bdd2cf2a6e157b25ca5fc (patch) | |
tree | c6dda6737ac86567a6e61490322ca31369b65f90 /sonar-scanner-engine/src/main | |
parent | da791972bb7615fc426acab1f406d08d3b91ef1a (diff) | |
download | sonarqube-8305ff20174aee249f2bdd2cf2a6e157b25ca5fc.tar.gz sonarqube-8305ff20174aee249f2bdd2cf2a6e157b25ca5fc.zip |
SONAR-22537 add support for short and full description in adhoc rule created from SARIF import.
Diffstat (limited to 'sonar-scanner-engine/src/main')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/RuleMapper.java | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/RuleMapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/RuleMapper.java index 5638088fd11..1c4f387fc20 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/RuleMapper.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/RuleMapper.java @@ -20,6 +20,7 @@ package org.sonar.scanner.externalissue.sarif; import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.rule.NewAdHocRule; import org.sonar.api.scanner.ScannerSide; @@ -38,13 +39,25 @@ public class RuleMapper { } NewAdHocRule mapRule(ReportingDescriptor rule, String driverName, @Nullable Result.Level ruleSeverity, @Nullable Result.Level ruleSeverityForNewTaxonomy) { - return sensorContext.newAdHocRule() + + NewAdHocRule newAdHocRule = sensorContext.newAdHocRule() .severity(ResultMapper.toSonarQubeSeverity(ruleSeverity)) .type(ResultMapper.DEFAULT_TYPE) .ruleId(rule.getId()) .engineId(driverName) - .name(join(":", driverName, rule.getId())) .cleanCodeAttribute(ResultMapper.DEFAULT_CLEAN_CODE_ATTRIBUTE) .addDefaultImpact(ResultMapper.DEFAULT_SOFTWARE_QUALITY, ResultMapper.toSonarQubeImpactSeverity(ruleSeverityForNewTaxonomy)); + + if (rule.getShortDescription() != null && !StringUtils.isBlank(rule.getShortDescription().getText())) { + newAdHocRule.name(rule.getShortDescription().getText()); + } else { + newAdHocRule.name(join(":", driverName, rule.getId())); + } + + if (rule.getFullDescription() != null && !StringUtils.isBlank(rule.getFullDescription().getText())) { + newAdHocRule.description(rule.getFullDescription().getText()); + } + + return newAdHocRule; } } |