]> source.dussan.org Git - sonarqube.git/commitdiff
move issue-filter plugin from it-core to SQ sources
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 21 Oct 2015 12:57:55 +0000 (14:57 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 23 Oct 2015 08:44:16 +0000 (10:44 +0200)
it/it-plugins/issue-filter-plugin/pom.xml [new file with mode: 0644]
it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterBeforeLine5.java [new file with mode: 0644]
it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterPlugin.java [new file with mode: 0644]
it/it-plugins/issue-filter-plugin/src/main/java/ModuleIssueFilter.java [new file with mode: 0644]
it/it-plugins/pom.xml

diff --git a/it/it-plugins/issue-filter-plugin/pom.xml b/it/it-plugins/issue-filter-plugin/pom.xml
new file mode 100644 (file)
index 0000000..8df7470
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.sonarsource.sonarqube</groupId>
+    <artifactId>it-plugins</artifactId>
+    <version>5.3-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>issue-filter-plugin</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>sonar-plugin</packaging>
+  <name>IT :: Issue Filter</name>
+  <description>IT :: Issue Filter</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.sonarsource.sonarqube</groupId>
+      <artifactId>sonar-plugin-api</artifactId>
+      <version>${apiVersion}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
+        <artifactId>sonar-packaging-maven-plugin</artifactId>
+        <version>1.15</version>
+        <extensions>true</extensions>
+        <configuration>
+          <pluginClass>IssueFilterPlugin</pluginClass>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterBeforeLine5.java b/it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterBeforeLine5.java
new file mode 100644 (file)
index 0000000..aaea16c
--- /dev/null
@@ -0,0 +1,29 @@
+import org.sonar.api.config.Settings;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueFilter;
+
+/**
+ * This filter removes the issues that are on line < 5
+ * <p/>
+ * Issue filters have been introduced in 3.6.
+ */
+public class IssueFilterBeforeLine5 implements IssueFilter {
+
+  private final Settings settings;
+
+  public IssueFilterBeforeLine5(Settings settings) {
+    this.settings = settings;
+  }
+
+  @Override
+  public boolean accept(Issue issue) {
+    if (issue.componentKey() == null) {
+      throw new IllegalStateException("Issue component is not set");
+    }
+    if (issue.ruleKey() == null) {
+      throw new IllegalStateException("Issue rule is not set");
+    }
+
+    return !settings.getBoolean("enableIssueFilters") || issue.line() == null || issue.line() >= 5;
+  }
+}
diff --git a/it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterPlugin.java b/it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterPlugin.java
new file mode 100644 (file)
index 0000000..19ff029
--- /dev/null
@@ -0,0 +1,17 @@
+import java.util.Arrays;
+import java.util.List;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.PropertyType;
+import org.sonar.api.SonarPlugin;
+
+@Properties(@Property(
+  key = "enableIssueFilters",
+  name = "Enable Issue Filters",
+  defaultValue = "false",
+  type = PropertyType.BOOLEAN))
+public class IssueFilterPlugin extends SonarPlugin {
+  public List getExtensions() {
+    return Arrays.asList(IssueFilterBeforeLine5.class, ModuleIssueFilter.class);
+  }
+}
diff --git a/it/it-plugins/issue-filter-plugin/src/main/java/ModuleIssueFilter.java b/it/it-plugins/issue-filter-plugin/src/main/java/ModuleIssueFilter.java
new file mode 100644 (file)
index 0000000..de0de20
--- /dev/null
@@ -0,0 +1,32 @@
+import org.sonar.api.config.Settings;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueFilter;
+import org.sonar.api.rule.RuleKey;
+
+/**
+ * This filter removes the issues that are raised by Xoo plugin on modules.
+ * <p/>
+ * Issue filters have been introduced in 3.6.
+ */
+public class ModuleIssueFilter implements IssueFilter {
+
+  private static final RuleKey ONE_ISSUE_PER_MODULE_RULEKEY = RuleKey.of("xoo", "OneIssuePerModule");
+
+  private final Settings settings;
+
+  public ModuleIssueFilter(Settings settings) {
+    this.settings = settings;
+  }
+
+  @Override
+  public boolean accept(Issue issue) {
+    if (issue.componentKey() == null) {
+      throw new IllegalStateException("Issue component is not set");
+    }
+    if (issue.ruleKey() == null) {
+      throw new IllegalStateException("Issue rule is not set");
+    }
+
+    return !settings.getBoolean("enableIssueFilters") || !ONE_ISSUE_PER_MODULE_RULEKEY.equals(issue.ruleKey());
+  }
+}
index 4d709ab02e20aee93617c406f3f7c4be13c248a0..36a13b04d4979cbf9eab91ab2f2e4d3267c0ba99 100644 (file)
@@ -45,5 +45,6 @@
     <module>settings-plugin</module>
     <module>sonar-fake-plugin</module>
     <module>sonar-subcategories-plugin</module>
+    <module>issue-filter-plugin</module>
   </modules>
 </project>