]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17592 adding hotspots with multilines to xoo plugin
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Wed, 30 Nov 2022 16:06:55 +0000 (17:06 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 1 Dec 2022 20:03:12 +0000 (20:03 +0000)
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineHotspotSensor.java [new file with mode: 0644]
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/MultilineHotspotSensorTest.java [new file with mode: 0644]
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java

index 3435aab97db9bc637e5a5eac35111e496769e9fb..7e0195ee760a5ebe493f12c1982af50989f525f4 100644 (file)
@@ -43,6 +43,7 @@ import org.sonar.xoo.rule.ChecksSensor;
 import org.sonar.xoo.rule.CreateIssueByInternalKeySensor;
 import org.sonar.xoo.rule.CustomMessageSensor;
 import org.sonar.xoo.rule.HasTagSensor;
+import org.sonar.xoo.rule.MultilineHotspotSensor;
 import org.sonar.xoo.rule.hotspot.HotspotWithSingleContextSensor;
 import org.sonar.xoo.rule.hotspot.HotspotWithoutContextSensor;
 import org.sonar.xoo.rule.hotspot.HotspotWithContextsSensor;
@@ -162,6 +163,7 @@ public class XooPlugin implements Plugin {
 
       CreateIssueByInternalKeySensor.class,
       MultilineIssuesSensor.class,
+      MultilineHotspotSensor.class,
       CustomMessageSensor.class,
 
       OneBugIssuePerLineSensor.class,
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineHotspotSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineHotspotSensor.java
new file mode 100644 (file)
index 0000000..09bd97c
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.xoo.rule;
+
+public class MultilineHotspotSensor extends MultilineIssuesSensor {
+
+  public static final String RULE_KEY = "MultilineHotspot";
+
+  @Override
+  public String getRuleKey() {
+    return RULE_KEY;
+  }
+}
index 1db7c8639a34a11779a2bd70b52e8f39503b9971..1d70838d353c07865719586255a45c9e55f2d379 100644 (file)
@@ -82,6 +82,10 @@ public class MultilineIssuesSensor implements Sensor {
     }
   }
 
+  public String getRuleKey() {
+    return RULE_KEY;
+  }
+
   private void createIssues(InputFile file, SensorContext context) {
     Collection<ParsedIssue> issues = parseIssues(file);
     FlowIndex flowIndex = new FlowIndex();
@@ -91,8 +95,8 @@ public class MultilineIssuesSensor implements Sensor {
     createIssues(file, context, issues, flowIndex);
   }
 
-  private static void createIssues(InputFile file, SensorContext context, Collection<ParsedIssue> parsedIssues, FlowIndex flowIndex) {
-    RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
+  private void createIssues(InputFile file, SensorContext context, Collection<ParsedIssue> parsedIssues, FlowIndex flowIndex) {
+    RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, getRuleKey());
 
     for (ParsedIssue parsedIssue : parsedIssues) {
       NewIssue newIssue = context.newIssue().forRule(ruleKey);
index aba3b4ccccaca37ab862f86a9ff27efd9befbbe5..d00ad839868c5e6b719318dfc26a55ce976980d6 100644 (file)
@@ -186,6 +186,12 @@ public class XooRulesDefinition implements RulesDefinition {
     NewRule issueWithRangeAndMultipleLocations = repo.createRule(MultilineIssuesSensor.RULE_KEY).setName("Creates issues with ranges/multiple locations");
     addAllDescriptionSections(issueWithRangeAndMultipleLocations, "Issue with range and multiple locations");
 
+    NewRule hotspotWithRangeAndMultipleLocations = repo.createRule(MultilineHotspotSensor.RULE_KEY)
+      .setName("Creates hotspots with ranges/multiple locations")
+      .setType(RuleType.SECURITY_HOTSPOT);
+    addAllDescriptionSections(hotspotWithRangeAndMultipleLocations, "Hotspot with range and multiple locations");
+
+
     NewRule issueOnEachFileWithExtUnknown = repo.createRule(OneIssuePerUnknownFileSensor.RULE_KEY).setName("Creates issues on each file with extension 'unknown'");
     addAllDescriptionSections(issueOnEachFileWithExtUnknown, "This issue is generated on each file with extenstion 'unknown'");
 
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/MultilineHotspotSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/MultilineHotspotSensorTest.java
new file mode 100644 (file)
index 0000000..fd2ff0f
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.xoo.rule;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MultilineHotspotSensorTest {
+
+  @Test
+  public void getRuleKey_returnsTheKey() {
+    assertThat(new MultilineHotspotSensor().getRuleKey()).isEqualTo(MultilineHotspotSensor.RULE_KEY);
+  }
+}
\ No newline at end of file
index cb9b5d6cce8653078b5ad458efe88cff63e52b69..78c861973e1bbc8318102db98c979c6b18625746 100644 (file)
@@ -119,7 +119,7 @@ public class XooRulesDefinitionTest {
     assertThat(repo).isNotNull();
     assertThat(repo.name()).isEqualTo("Xoo");
     assertThat(repo.language()).isEqualTo("xoo");
-    assertThat(repo.rules()).hasSize(25);
+    assertThat(repo.rules()).hasSize(26);
     return repo;
   }
 }