diff options
author | stanislavh <stanislav.honcharov@sonarsource.com> | 2024-11-14 16:05:26 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-15 20:02:42 +0000 |
commit | 00325f16ee60076ff7feffbeb81c0ed1956bdc9e (patch) | |
tree | 7c9483c327620d650403ead63579a427bb7e5e2f /plugins/sonar-xoo-plugin | |
parent | 010d132cdfe0a6bb0669d9e37e3a66b27e0cc17f (diff) | |
download | sonarqube-00325f16ee60076ff7feffbeb81c0ed1956bdc9e.tar.gz sonarqube-00325f16ee60076ff7feffbeb81c0ed1956bdc9e.zip |
SONAR-23522 Add BBTs for mqr mode transition
SONAR-23522 Add a way to customize impacts on xoo plugin
Diffstat (limited to 'plugins/sonar-xoo-plugin')
-rw-r--r-- | plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java index 4dbd8085f62..c34784457d1 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java @@ -19,6 +19,8 @@ */ package org.sonar.xoo.rule; +import java.util.HashMap; +import java.util.Map; import javax.annotation.Nullable; import org.sonar.api.SonarRuntime; import org.sonar.api.config.Configuration; @@ -125,10 +127,16 @@ public class XooRulesDefinition implements RulesDefinition { ruleWithParameters.createParam("integer").setType(RuleParamType.INTEGER); ruleWithParameters.createParam("float").setType(RuleParamType.FLOAT); + Map<SoftwareQuality, Severity> customImpacts = getCustomImpactsForOneIssuePerLine(); NewRule oneIssuePerLine = repo.createRule(OneIssuePerLineSensor.RULE_KEY).setName("One Issue Per Line") .setCleanCodeAttribute(CleanCodeAttribute.COMPLETE) - .addDefaultImpact(SoftwareQuality.MAINTAINABILITY, Severity.INFO) .setTags("line"); + if (!customImpacts.isEmpty()) { + customImpacts.forEach(oneIssuePerLine::addDefaultImpact); + } else { + oneIssuePerLine.addDefaultImpact(SoftwareQuality.MAINTAINABILITY, Severity.INFO); + } + addDescriptionSectionsWithoutContexts(oneIssuePerLine, "Generate an issue on each line of a file. It requires the metric \"lines\"."); addHowToFixSectionsWithContexts(oneIssuePerLine); oneIssuePerLine @@ -344,6 +352,18 @@ public class XooRulesDefinition implements RulesDefinition { repo.done(); } + private Map<SoftwareQuality, Severity> getCustomImpactsForOneIssuePerLine() { + Map<SoftwareQuality, Severity> customImpacts = new HashMap<>(); + if (configuration != null && configuration.get("sonar.xoo.OneIssuePerLine.impacts").isPresent()) { + String[] impacts = configuration.get("sonar.xoo.OneIssuePerLine.impacts").get().split(","); + for (String impact : impacts) { + String[] impactArray = impact.split(":"); + customImpacts.put(SoftwareQuality.valueOf(impactArray[0]), Severity.valueOf(impactArray[1])); + } + } + return customImpacts; + } + private void addSecurityStandard(NewRule rule, String standard) { String[] splitStandard = standard.split(":"); switch (splitStandard[0]) { |