Skip to content

Commit

Permalink
Merge pull request #56 from jensgerdes/feature/PMD_6.x
Browse files Browse the repository at this point in the history
This closes #34, closes #38, closes #48 and fixes #44.
  • Loading branch information
jensgerdes authored Nov 3, 2018
2 parents b118e67 + 5bcc2ef commit 7cb35b8
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 77 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ addons:
secure: "U299FqcJAMNfblrZF8R/ivqRk7KNdSOdcyWI4h5dgOLlQHj+HHrF2GJB2fOVeaB53snOkCycM/ZQgqTLlS1PU2NUca3TroNXj6jpNK1Erb/TXqFMKK+rmsN+hcxudDYGnQFIVnWy4lsg72jlK3Qvktt0XyfuYjMqQbsp3zwhlxw="

jdk:
- openjdk8
- openjdk11

install: true
script: ./travis.sh
env:
- TEST=ci
- TEST=plugin SQ_VERSION=LATEST_RELEASE[6.6] SJ_VERSION=LATEST_RELEASE[4.3]
- TEST=plugin SQ_VERSION=LATEST_RELEASE[6.6] SJ_VERSION=LATEST_RELEASE[4.15]
- TEST=plugin SQ_VERSION=LATEST_RELEASE[6.7]
- TEST=plugin SQ_VERSION=LATEST_RELEASE[7.2]
- TEST=plugin SQ_VERSION=LATEST_RELEASE[7.3]
- TEST=plugin SQ_VERSION=LATEST_RELEASE[7.4]
- TEST=plugin SQ_VERSION=DEV
- TEST=javadoc

cache:
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# Changelog

## [3.1.0-SNAPSHOT](https://github.com/jensgerdes/sonar-pmd/tree/master) (2018-11-03)
[Full Changelog](https://github.com/jensgerdes/sonar-pmd/compare/3.0.1...master)

**Implemented enhancements:**
- Java 11 support
- Updated PMD (6.9.0)

**Closed issues:**
- Upgrade pmd version to the latest one for parsing Java 8 code successfully [\#34](https://github.com/jensgerdes/sonar-pmd/issues/34)
- Please update PMD to at least 5.5.2 [\#38](https://github.com/jensgerdes/sonar-pmd/issues/38)
- Java 10 compatibility [\#44](https://github.com/jensgerdes/sonar-pmd/issues/44)
- Upgrade to a recent PMD version? [\#48](https://github.com/jensgerdes/sonar-pmd/issues/48)

**Merged pull requests:**
- Upgrade to latest PMD [\#51](https://github.com/jensgerdes/sonar-pmd/pull/51) ([spasam](https://github.com/spasam))

## [3.0.1](https://github.com/jensgerdes/sonar-pmd/tree/3.0.1) (2018-10-29)
[Full Changelog](https://github.com/jensgerdes/sonar-pmd/compare/3.0.0...3.0.1)

**Fixed bugs:**
- Plugin does not work with SonarQube 7.4 [\#55](https://github.com/jensgerdes/sonar-pmd/issues/55)


## [3.0.0](https://github.com/jensgerdes/sonar-pmd/tree/3.0.0) (2018-10-29)
[Full Changelog](https://github.com/jensgerdes/sonar-pmd/compare/2.6...3.0.0)

Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
Sonar-PMD is a plugin that provides coding rules from [PMD](https://pmd.github.io/).

## Description / Features
PMD Plugin|2.0|2.1|2.2|2.3|2.4.1|2.5|2.6|3.0.0
-------|---|---|---|---|---|---|---|---
PMD|4.3|4.3|5.1.1|5.2.1|5.3.1|5.4.0|5.4.2|5.4.2
Supported Java Version | | | | | | 1.7 | 1.8 | 1.8
Min. SonarQube Version | | | | | | 4.5.4 | 4.5.4 | 6.6
PMD Plugin|2.0|2.1|2.2|2.3|2.4.1|2.5|2.6|3.0.0|3.1.0-SNAPSHOT
-------|---|---|---|---|---|---|---|---|---
PMD|4.3|4.3|5.1.1|5.2.1|5.3.1|5.4.0|5.4.2|5.4.2|6.9.0
Supported Java Version | | | | | | 1.7 | 1.8 | 1.8 | 11
Min. SonarQube Version | | | | | | 4.5.4 | 4.5.4 | 6.6 | 6.6

A majority of the PMD rules have been rewritten in the Java plugin. Rewritten rules are marked "Deprecated" in the PMD plugin, but a [concise summary of replaced rules](http://dist.sonarsource.com/reports/coverage/pmd.html) is available.

## Usage
In the quality profile, activate some rules from PMD and run an analysis on your project.
Set the sonar.java.source property to tell PMD which version of Java your source code complies to. The default value is 1.5.
Set the sonar.java.source property to tell PMD which version of Java your source code complies to. The default value is 1.6.

Possible values:
- 1.4
- 1.5 or 5
- 1.6 or 6
- 1.7 or 7
- 1.8 or 8
- 9
- 10
- 11

## Rules on test
PMD tool provides some rules that can check the code of JUnit tests. Please note that these rules (and only these rules) will be applied only on the test files of your project.
Expand Down
20 changes: 8 additions & 12 deletions its/plugin/plugins/pmd-extension-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>5.1.1</version>
<artifactId>pmd-core</artifactId>
<version>6.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>6.9.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -44,16 +50,6 @@
<basePlugin>pmd</basePlugin>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
*/
package org.sonar.examples.pmd;



import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,7 +35,7 @@ public class MaximumMethodsCountCheck extends AbstractJavaRule {

private static final Logger LOG = LoggerFactory.getLogger(MaximumMethodsCountCheck.class);

public static final IntegerProperty propertyDescriptor = new IntegerProperty("maxAuthorisedMethodsCount",
public static final IntegerProperty propertyDescriptor = new IntegerProperty("maxAuthorisedMethodsCount",
"Maximum number of methods authorised", 1, Integer.MAX_VALUE, 2, 1.0f);

public MaximumMethodsCountCheck() {
Expand Down
4 changes: 4 additions & 0 deletions its/plugin/projects/pmd-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<groupId>com.sonarsource.it.projects</groupId>
<artifactId>pmd-extensions</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
50 changes: 18 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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/xsd/maven-4.0.0.xsd">
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -10,7 +11,7 @@

<groupId>org.sonarsource.pmd</groupId>
<artifactId>sonar-pmd-plugin</artifactId>
<version>3.0.2-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube PMD Plugin</name>
Expand Down Expand Up @@ -60,7 +61,7 @@
<properties>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>

<pmd.version>5.4.2</pmd.version>
<pmd.version>6.9.0</pmd.version>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
</properties>

Expand Down Expand Up @@ -88,6 +89,12 @@
<artifactId>java-frontend</artifactId>
<version>5.5.0.14655</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
Expand All @@ -114,21 +121,13 @@
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
Expand All @@ -137,41 +136,29 @@
<groupId>net.java.dev.javacc</groupId>
<artifactId>javacc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>net.java.dev.javacc</groupId>
<artifactId>javacc</artifactId>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -184,7 +171,6 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand All @@ -204,7 +190,7 @@
<pluginName>PMD</pluginName>
<pluginClass>org.sonar.plugins.pmd.PmdPlugin</pluginClass>
<pluginDescription>Analyze Java code with PMD.</pluginDescription>
<requirePlugins>java:4.3.0.7717</requirePlugins>
<requirePlugins>java:4.15.0.12310</requirePlugins>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -256,7 +242,7 @@
<distributionManagement>
<repository>
<id>bintray</id>
<url />
<url/>
</repository>
</distributionManagement>
<!--
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sonar/plugins/pmd/PmdConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class PmdConstants {
/**
* Default value for property {@link #JAVA_SOURCE_VERSION}.
*/
public static final String JAVA_SOURCE_VERSION_DEFAULT_VALUE = "1.5";
public static final String JAVA_SOURCE_VERSION_DEFAULT_VALUE = "1.6";

/**
* The Java Language key.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/sonar/plugins/pmd/PmdTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
public class PmdTemplate {

private static final Logger LOG = Loggers.get(PmdTemplate.class);

private static final Map<String, String> JAVA_VERSIONS = prepareVersions();

private static Map<String, String> prepareVersions() {
Expand All @@ -50,6 +49,9 @@ private static Map<String, String> prepareVersions() {
versions.put("6", "1.6");
versions.put("7", "1.7");
versions.put("8", "1.8");
versions.put("9", "9");
versions.put("10", "10");
versions.put("11", "11");

return versions;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/sonar/plugins/pmd/PmdConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void createTempDir() {
WORK_DIR.mkdir();
}

@SuppressWarnings("ResultOfMethodCallIgnored")
@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstantConditions"})
@AfterAll
static void deleteTempDir() {
if (WORK_DIR.exists()) {
Expand Down Expand Up @@ -102,7 +102,7 @@ void should_dump_xml_report() throws IOException {

assertThat(reportFile.toFile()).isEqualTo(new File(WORK_DIR, "pmd-result.xml"));
List<String> writtenLines = Files.readAllLines(reportFile, StandardCharsets.UTF_8);
assertThat(writtenLines).hasSize(3);
assertThat(writtenLines).hasSize(6);
assertThat(writtenLines.get(1)).contains("<pmd");
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/sonar/plugins/pmd/PmdConstantsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void checkDefinedKeys() {
assertThat(PmdConstants.XPATH_EXPRESSION_PARAM).isEqualTo("xpath");
assertThat(PmdConstants.XPATH_MESSAGE_PARAM).isEqualTo("message");
assertThat(PmdConstants.JAVA_SOURCE_VERSION).isEqualTo("sonar.java.source");
assertThat(PmdConstants.JAVA_SOURCE_VERSION_DEFAULT_VALUE).isEqualTo("1.5");
assertThat(PmdConstants.JAVA_SOURCE_VERSION_DEFAULT_VALUE).isEqualTo("1.6");
assertThat(PmdConstants.LANGUAGE_KEY).isEqualTo("java");
}
}
Loading

0 comments on commit 7cb35b8

Please sign in to comment.