]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23522 Add BBTs for mqr mode transition
authorstanislavh <stanislav.honcharov@sonarsource.com>
Thu, 14 Nov 2024 15:05:26 +0000 (16:05 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 15 Nov 2024 20:02:42 +0000 (20:02 +0000)
 SONAR-23522 Add a way to customize impacts on xoo plugin

plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java

index 4dbd8085f626495531e94685fd92b7d683c09a8b..c34784457d1d6fc140ecb59d45f2068af3487f0c 100644 (file)
@@ -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]) {