From: Lukasz Jarocki Date: Wed, 6 Jul 2022 12:07:44 +0000 (+0200) Subject: SONAR-16614 added detected context to one of the sensors X-Git-Tag: 9.6.0.59041~261 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=685a8905315ce2fb830c91684ea3c9a3b3ad06a8;p=sonarqube.git SONAR-16614 added detected context to one of the sensors --- diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java index 720110853f1..74c713014a4 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java @@ -29,10 +29,11 @@ import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.Version; import org.sonar.xoo.Xoo; import org.sonar.xoo.Xoo2; +import static org.sonar.xoo.rule.XooRulesDefinition.AVAILABLE_CONTEXTS; + public class OneIssuePerLineSensor implements Sensor { public static final String RULE_KEY = "OneIssuePerLine"; @@ -73,12 +74,9 @@ public class OneIssuePerLineSensor implements Sensor { .on(file) .at(file.selectLine(line)) .message("This issue is generated on each line")) - .overrideSeverity(severity != null ? Severity.valueOf(severity) : null); - if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) { - newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); - } else { - newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); - } + .overrideSeverity(severity != null ? Severity.valueOf(severity) : null) + .setRuleDescriptionContextKey(AVAILABLE_CONTEXTS[0]) + .gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); newIssue.save(); } } 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 38ed2bad0bf..6656e760034 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 @@ -48,11 +48,12 @@ import static org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version.Y2021; */ public class XooRulesDefinition implements RulesDefinition { + public static final String[] AVAILABLE_CONTEXTS = { "JavaScript", "JQuery", "Express.js", "React", "Axios" }; + public static final String XOO_REPOSITORY = "xoo"; public static final String XOO2_REPOSITORY = "xoo2"; private static final String TEN_MIN = "10min"; - private static final String[] AVAILABLE_CONTEXTS = { "JavaScript", "JQuery", "Express.js", "React", "Axios" }; @Nullable private final Version version; diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java index c64ed9b68dc..3ed3cf22683 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java @@ -85,6 +85,7 @@ public class OneIssuePerLineSensorTest { assertThat(context.allIssues()).hasSize(10); // One issue per line for (Issue issue : context.allIssues()) { assertThat(issue.overriddenSeverity()).isEqualTo(Severity.MINOR); + assertThat(issue.ruleDescriptionContextKey()).contains(XooRulesDefinition.AVAILABLE_CONTEXTS[0]); } }