Skip to content

Commit 51d5c64

Browse files
authored
Merge pull request #494 from jborgers/pmd-7-pmd7
Merge pmd-7-pmd7 branch into master
2 parents 1a258eb + 60385a6 commit 51d5c64

File tree

73 files changed

+1473
-990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1473
-990
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ jobs:
3939
echo "Tag '$TAG_NAME' does not contain 'SNAPSHOT', failing build."
4040
exit 1
4141
42-
- name: Set up JDK 11
42+
- name: Set up JDK 17
4343
uses: actions/setup-java@v4
4444
with:
4545
distribution: 'zulu'
46-
java-version: 11
46+
java-version: 17
4747
server-id: sonatype-nexus
4848
server-username: MAVEN_USERNAME
4949
server-password: MAVEN_PASSWORD

.mvn/wrapper/maven-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
# under the License.
1717
wrapperVersion=3.3.2
1818
distributionType=only-script
19-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SonarQube PMD Plugin
1+
# SonarQube PMD Plugin [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.sonarsource.pmd/sonar-pmd-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.sonarsource.pmd/sonar-pmd-plugin) [![Build Status](https://api.travis-ci.org/jborgers/sonar-pmd.svg?branch=master)](https://travis-ci.org/jborgers/sonar-pmd) [![SonarStatus](https://sonarcloud.io/api/project_badges/measure?project=org.sonarsource.pmd%3Asonar-pmd&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.sonarsource.pmd%3Asonar-pmd) [![SonarStatus](https://sonarcloud.io/api/project_badges/measure?project=org.sonarsource.pmd%3Asonar-pmd&metric=coverage)](https://sonarcloud.io/dashboard?id=org.sonarsource.pmd%3Asonar-pmd)
22

33
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.sonarsource.pmd/sonar-pmd-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.sonarsource.pmd/sonar-pmd-plugin)
44
![Build Status](https://github.com/jborgers/sonar-pmd/actions/workflows/build.yml/badge.svg)
@@ -13,7 +13,6 @@ For a list of all rules and their status, see: [RULES.md](https://github.com/jbo
1313
## Installation
1414
The plugin should be available in the SonarQube marketplace and is preferably installed from within SonarQube (Administration --> Marketplace --> Search _pmd_).
1515

16-
This plugin is available again from the Marketplace with the release of version 3.4.0.
1716
Alternatively, download the [latest JAR file](https://github.com/jborgers/sonar-pmd/releases/latest), put it into the plugin directory (`./extensions/plugins`) and restart SonarQube.
1817

1918
## Usage
@@ -25,15 +24,15 @@ Usage should be straight forward:
2524
Sonar-PMD analyzes the given source code with the Java source version defined in your Gradle or Maven project.
2625
In case you are not using one of these build tools, or if that does not match the version you are using, set the `sonar.java.source` property to tell PMD which version of Java your source code complies to.
2726

28-
Possible values : 1.6 to 1.8/8 to 20-preview
27+
Possible values : 1.6 to 1.8/8 to 24-preview
2928

3029
## Table of supported versions
31-
| Sonar-PMD Plugin | 3.1.x | 3.3.x | 3.4.0 | 3.5.0 | 3.5.1 | 4.0.0 (planned) |
32-
|------------------------|-------|--------|-----------------|---------------|---------------|-----------------|
33-
| PMD | 6.9.0 | 6.30.0 | 6.45.0 | 6.55.0 | 6.55.0 | 7.2.0 |
34-
| Max. Java Version | 11 | 15 | 18 | 20-preview *2 | 20-preview *2 | 22 |
35-
| Min. SonarQube Version | 6.6 | 6.7 | _8.9(*1)_ / 9.3 | 9.8 | 9.9.4 | 10.0 |
36-
| Max. SonarQube Version | | | 9.9 | 10.4 | 10.5+ | 10.5+ |
30+
| Sonar-PMD Plugin | 3.4.0 | 3.5.0 | 3.5.1 | 4.0.0 |
31+
|------------------------|-----------------|---------------|---------------|------------|
32+
| PMD | 6.45.0 | 6.55.0 | 6.55.0 | 7.10.0 |
33+
| Max. Java Version | 18 | 20-preview *2 | 20-preview *2 | 24-preview |
34+
| Min. SonarQube Version | _8.9(*1)_ / 9.3 | 9.8 | 9.9.4 | 9.9.4 |
35+
| Max. SonarQube Version | 9.9 | 10.4 | 10.5+ | 10.8+ |
3736

3837
(*1) Note: Plugin version 3.4.x runs in SonarQube 8.9, however, Java 17+ is only fully supported in SonarQube 9.3+.
3938
(*2) Note: Supports all tested Java 21 features; on parsing errors, warns instead of breaks

integration-test/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<dependency>
5050
<groupId>org.codehaus.sonar</groupId>
5151
<artifactId>sonar-ws-client</artifactId>
52+
<scope>provided</scope>
5253
</dependency>
5354
<dependency>
5455
<groupId>org.sonarsource.api.plugin</groupId>
@@ -69,6 +70,11 @@
6970

7071
<build>
7172
<plugins>
73+
<plugin>
74+
<groupId>org.sonarsource.scanner.maven</groupId>
75+
<artifactId>sonar-maven-plugin</artifactId>
76+
<version>${sonar.maven.plugin.version}</version>
77+
</plugin>
7278
<plugin>
7379
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
7480
<artifactId>sonar-packaging-maven-plugin</artifactId>
@@ -78,6 +84,9 @@
7884
<pluginDescription>Integration Test PmdExtensionPlugin</pluginDescription>
7985
<!-- This is important. It means that this plugin extends the PMD plugin -->
8086
<basePlugin>pmd</basePlugin>
87+
88+
<!-- This is important. It means that this plugin extends the PMD plugin -->
89+
<basePlugin>pmd</basePlugin>
8190
</configuration>
8291
</plugin>
8392
<!-- prevent deploy: https://stackoverflow.com/questions/25305850/how-to-disable-nexus-staging-maven-plugin-in-sub-modules -->

integration-test/projects/pmd-extensions/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1212
</properties>
1313

14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.sonarsource.scanner.maven</groupId>
18+
<artifactId>sonar-maven-plugin</artifactId>
19+
<version>5.0.0.4389</version>
20+
</plugin>
21+
</plugins>
22+
</build>
23+
1424
<profiles>
1525
<profile>
1626
<id>skipSonar</id>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package pmd;
22

33
public class Bar extends Foo {
4-
4+
public void method() {
5+
// PMD7-MIGRATION: added to force one violation in pmdShouldHaveAccessToExternalLibrariesInItsClasspath: is this testing the correct thing?
6+
if (true) System.out.println("violation on AvoidIfWithoutBrace");
7+
}
58
}

integration-test/src/main/java/org/sonar/examples/pmd/MaximumMethodsCountCheck.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SonarQube PMD Plugin Integration Test
2+
* SonarQube PMD7 Plugin Integration Test
33
* Copyright (C) 2013-2021 SonarSource SA and others
44
* mailto:jborgers AT jpinpoint DOT com; peter.paul.bakker AT stokpop DOT nl
55
*
@@ -22,13 +22,14 @@
2222

2323
import java.util.List;
2424

25-
import net.sourceforge.pmd.RuleContext;
26-
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
25+
26+
import net.sourceforge.pmd.lang.java.ast.ASTClassBody;
2727
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
2828
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
29+
import net.sourceforge.pmd.properties.NumericConstraints;
2930
import net.sourceforge.pmd.properties.PropertyDescriptor;
3031
import net.sourceforge.pmd.properties.PropertyFactory;
31-
import net.sourceforge.pmd.properties.constraints.NumericConstraints;
32+
import net.sourceforge.pmd.reporting.RuleContext;
3233
import org.sonar.api.utils.log.Logger;
3334
import org.sonar.api.utils.log.Loggers;
3435

@@ -58,8 +59,8 @@ public void end(RuleContext ctx) {
5859
}
5960

6061
@Override
61-
public Object visit(ASTClassOrInterfaceBody node, Object data) {
62-
List<ASTMethodDeclaration> methods = node.findDescendantsOfType(ASTMethodDeclaration.class);
62+
public Object visit(ASTClassBody node, Object data) {
63+
List<ASTMethodDeclaration> methods = node.descendants(ASTMethodDeclaration.class).toList();
6364
if (methods.size() > getProperty(propertyDescriptor)) {
6465
asCtx(data).addViolation(node);
6566
}

integration-test/src/main/java/org/sonar/examples/pmd/PmdExtensionPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SonarQube PMD Plugin Integration Test
2+
* SonarQube PMD7 Plugin Integration Test
33
* Copyright (C) 2013-2021 SonarSource SA and others
44
* mailto:jborgers AT jpinpoint DOT com; peter.paul.bakker AT stokpop DOT nl
55
*

integration-test/src/main/java/org/sonar/examples/pmd/PmdExtensionRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SonarQube PMD Plugin Integration Test
2+
* SonarQube PMD7 Plugin Integration Test
33
* Copyright (C) 2013-2021 SonarSource SA and others
44
* mailto:jborgers AT jpinpoint DOT com; peter.paul.bakker AT stokpop DOT nl
55
*

integration-test/src/main/resources/org/sonar/examples/pmd/extensions.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
<priority>MAJOR</priority>
4343
<description>Prevent use of EmptyClass class</description>
4444
<name><![CDATA[Prevent use of EmptyClass]]></name>
45-
<configKey><![CDATA[net.sourceforge.pmd.lang.rule.XPathRule]]></configKey>
45+
<configKey><![CDATA[net.sourceforge.pmd.lang.rule.xpath.XPathRule]]></configKey>
4646
<priority>MINOR</priority>
4747
<param>
4848
<key>xpath</key>
4949
<description><![CDATA[XPath expressions.]]></description>
50-
<defaultValue>//VariableDeclarator[../Type/ReferenceType/ClassOrInterfaceType[@Image='EmptyClass']]</defaultValue>
50+
<defaultValue>//VariableDeclarator[../ClassOrInterfaceType[@SimpleName='EmptyClass']]</defaultValue>
5151
</param>
5252
<param>
5353
<key>message</key>

0 commit comments

Comments
 (0)