Skip to content

Commit

Permalink
Merge pull request #53 from jensgerdes/sonarqube-7.3+
Browse files Browse the repository at this point in the history
sonar-pmd has been heavily refactored to use the current Sonar Plugin API, allowing it to be run on SonarQube 7.3+. Fixes #49, fixes #42
  • Loading branch information
jensgerdes committed Oct 17, 2018
2 parents 6998130 + 583a5ce commit c88d547
Show file tree
Hide file tree
Showing 240 changed files with 2,947 additions and 6,496 deletions.
6 changes: 0 additions & 6 deletions .sonarsource.properties

This file was deleted.

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
- TEST=ci
- TEST=plugin SQ_VERSION=LATEST_RELEASE[6.7]
- TEST=plugin SQ_VERSION=LATEST_RELEASE[7.2]
- TEST=plugin SQ_VERSION=LATEST_RELEASE[7.3]

cache:
directories:
Expand Down
1 change: 0 additions & 1 deletion infinitest.args

This file was deleted.

3 changes: 0 additions & 3 deletions infinitest.filters

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Java :: IT :: Plugins :: PMD Extension Plugin
* Copyright (C) 2013 SonarSource
* sonarqube@googlegroups.com
* Copyright (C) 2013-2018 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
Expand All @@ -13,9 +13,9 @@
* 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 02
* 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.examples.pmd;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Java :: IT :: Plugins :: PMD Extension Plugin
* Copyright (C) 2013 SonarSource
* sonarqube@googlegroups.com
* Copyright (C) 2013-2018 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
Expand All @@ -13,9 +13,9 @@
* 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 02
* 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.examples.pmd;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Java :: IT :: Plugins :: PMD Extension Plugin
* Copyright (C) 2013 SonarSource
* sonarqube@googlegroups.com
* Copyright (C) 2013-2018 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
Expand All @@ -13,42 +13,46 @@
* 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 02
* 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.examples.pmd;

import org.apache.commons.io.IOUtils;
import org.sonar.api.resources.Java;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.rules.XMLRuleParser;

import java.io.InputStream;
import java.util.List;

public class PmdExtensionRepository extends RuleRepository {

// Must be the same than the PMD plugin
private static final String REPOSITORY_KEY = "pmd";
private XMLRuleParser ruleParser;

public PmdExtensionRepository(XMLRuleParser ruleParser) {
super(REPOSITORY_KEY, Java.KEY);
this.ruleParser = ruleParser;
}
// Must be the same than the PMD plugin
private static final String REPOSITORY_KEY = "pmd";
private XMLRuleParser ruleParser;

@Override
public List<Rule> createRules() {
// In this example, new rules are declared in a XML file
InputStream input = getClass().getResourceAsStream("/org/sonar/examples/pmd/extensions.xml");
try {
return ruleParser.parse(input);

} finally {
IOUtils.closeQuietly(input);
public PmdExtensionRepository(XMLRuleParser ruleParser) {
// FIXME: Usage of PmdConstants possible?
super(REPOSITORY_KEY, "java");
this.ruleParser = ruleParser;
}
}

@Override
public List<Rule> createRules() {
// In this example, new rules are declared in a XML file
InputStream input = getClass().getResourceAsStream("/org/sonar/examples/pmd/extensions.xml");
try {
return ruleParser.parse(input);

} finally {
// FIXME Get rid of double close
try {
input.close();
} catch (IOException e) {
throw new RuntimeException("Failed to close stream.", e);
}
}
}
}
7 changes: 1 addition & 6 deletions its/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
<parent>
<groupId>org.sonarsource.parent</groupId>
<artifactId>parent</artifactId>
<version>24</version>
<version>48</version>
</parent>

<groupId>com.sonarsource.it</groupId>
<artifactId>it-pmd-plugin</artifactId>
<name>PMD :: IT :: Plugin</name>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<organization>
<name>SonarSource</name>
<url>http://www.sonarsource.com</url>
</organization>

<inceptionYear>2013</inceptionYear>

<modules>
Expand Down
4 changes: 2 additions & 2 deletions its/plugin/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>it-pmd-plugin-plugins</artifactId>
<version>${pom.version}</version>
<version>${project.version}</version>
<type>pom</type>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* PMD :: IT :: Plugin :: Tests
* Copyright (C) 2013 SonarSource
* sonarqube@googlegroups.com
* Copyright (C) 2013-2018 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
Expand All @@ -13,9 +13,9 @@
* 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 02
* 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 com.sonar.it.java.suite;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* PMD :: IT :: Plugin :: Tests
* Copyright (C) 2013 SonarSource
* sonarqube@googlegroups.com
* Copyright (C) 2013-2018 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
Expand All @@ -13,9 +13,9 @@
* 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 02
* 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 com.sonar.it.java.suite;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* PMD :: IT :: Plugin :: Tests
* Copyright (C) 2013 SonarSource
* sonarqube@googlegroups.com
* Copyright (C) 2013-2018 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
Expand All @@ -13,9 +13,9 @@
* 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 02
* 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 com.sonar.it.java.suite;

Expand Down
79 changes: 51 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sonarsource.parent</groupId>
<artifactId>parent</artifactId>
<version>24</version>
<version>48</version>
</parent>

<groupId>org.sonarsource.pmd</groupId>
Expand All @@ -15,9 +15,7 @@
<packaging>sonar-plugin</packaging>

<name>SonarQube PMD Plugin</name>
<description>PMD is a tool that looks for potential problems like possible bugs, dead code, suboptimal code,
overcomplicated expressions or duplicate code.
</description>
<description>Sonar-PMD is a plugin that provides coding rules from PMD.</description>
<inceptionYear>2012</inceptionYear>

<licenses>
Expand Down Expand Up @@ -60,8 +58,8 @@
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>

<pmd.version>5.4.2</pmd.version>
<sonar.version>4.5.4</sonar.version>
<sonar-java.version>3.6</sonar-java.version>
<sonar.version>6.7</sonar.version>
<sonar-java.version>5.5.0.14655</sonar-java.version>

<!-- Configuration for sonar-packaging-maven-plugin -->
<sonar.pluginKey>pmd</sonar.pluginKey>
Expand All @@ -73,7 +71,7 @@

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
<version>${sonar.version}</version>
Expand All @@ -84,18 +82,35 @@
</exclusion>
</exclusions>
</dependency>
<!--<dependency>
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
<artifactId>sslr-squid-bridge</artifactId>
<version>2.7.0.377</version>
<exclusions>
<exclusion>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
</exclusion>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>-->
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
<type>sonar-plugin</type>
<artifactId>java-frontend</artifactId>
<version>${sonar-java.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar.sslr-squid-bridge</groupId>
<artifactId>sslr-squid-bridge</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
Expand Down Expand Up @@ -149,20 +164,14 @@
<version>1.0</version>
</dependency>

<!-- TODO http://jira.codehaus.org/browse/SONAR-2011
We need following dependency, otherwise we will receive
java.lang.NoClassDefFoundError: org/apache/maven/project/MavenProject
during call mock(org.sonar.api.resources.Project.class)
-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.7</version>
<scope>test</scope>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>

<dependency>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
<version>${sonar.version}</version>
Expand All @@ -176,9 +185,23 @@
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.30</version>
<scope>test</scope>
</dependency>

<!-- Only here for transition purposes. -->
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -215,7 +238,7 @@
<configuration>
<rules>
<requireFilesSize>
<maxsize>5000000</maxsize>
<maxsize>7000000</maxsize>
<minsize>4200000</minsize>
<files>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
Expand Down
Loading

0 comments on commit c88d547

Please sign in to comment.