diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-10-21 14:57:55 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-10-23 10:44:16 +0200 |
commit | b424f93de235499682f602df7f1541396d22dc16 (patch) | |
tree | 0543043496fc18656bcfeade31048bd298b1c4d5 /it | |
parent | 417e7c62ce4993b66f1fc740a6973aee2c704e53 (diff) | |
download | sonarqube-b424f93de235499682f602df7f1541396d22dc16.tar.gz sonarqube-b424f93de235499682f602df7f1541396d22dc16.zip |
move issue-filter plugin from it-core to SQ sources
Diffstat (limited to 'it')
5 files changed, 118 insertions, 0 deletions
diff --git a/it/it-plugins/issue-filter-plugin/pom.xml b/it/it-plugins/issue-filter-plugin/pom.xml new file mode 100644 index 00000000000..8df7470448d --- /dev/null +++ b/it/it-plugins/issue-filter-plugin/pom.xml @@ -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 index 00000000000..aaea16c5b69 --- /dev/null +++ b/it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterBeforeLine5.java @@ -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 index 00000000000..19ff029ee78 --- /dev/null +++ b/it/it-plugins/issue-filter-plugin/src/main/java/IssueFilterPlugin.java @@ -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 index 00000000000..de0de20cf32 --- /dev/null +++ b/it/it-plugins/issue-filter-plugin/src/main/java/ModuleIssueFilter.java @@ -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()); + } +} diff --git a/it/it-plugins/pom.xml b/it/it-plugins/pom.xml index 4d709ab02e2..36a13b04d49 100644 --- a/it/it-plugins/pom.xml +++ b/it/it-plugins/pom.xml @@ -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> |