From 00325f16ee60076ff7feffbeb81c0ed1956bdc9e Mon Sep 17 00:00:00 2001 From: stanislavh Date: Thu, 14 Nov 2024 16:05:26 +0100 Subject: [PATCH] SONAR-23522 Add BBTs for mqr mode transition SONAR-23522 Add a way to customize impacts on xoo plugin --- .../sonar/xoo/rule/XooRulesDefinition.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 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 getCustomImpactsForOneIssuePerLine() { + Map 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]) { -- 2.39.5