Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pmd-7-pmd7 branch into master #494

Merged
merged 34 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a12bd5d
use pmd-7.0.0-snapshot, fix api change, update pmd_xml_pattern
jborgers Oct 29, 2021
8e641d8
fix unit tests, 5 rules have been removed in pmd-7
jborgers Oct 31, 2021
3dae514
correct max jar size for pmd-7
jborgers Oct 31, 2021
6a2fbd7
Made integration tests work with pmd 7.0 by removing or deactivating …
stokpop Nov 3, 2021
8b454a6
Added Kotlin rule "FunctionNameTooShort" to test pmd-7.0 with kotlin …
stokpop Nov 3, 2021
78f269f
Hooked up report with violations for the Kotlin rule "FunctionNameToo…
stokpop Nov 25, 2021
2b4cd0b
make pmd identifier into pmd7, in many places, including module name/…
jborgers Feb 24, 2022
c8d53bc
make pmd identifier into pmd7 - fix unit tests
jborgers Feb 25, 2022
e36b933
fixed duplicate property failure in startup of sonar
jborgers Feb 25, 2022
a0d984c
Merge pull request #299 from jborgers/pmd-7-pmd7
jensgerdes Apr 13, 2022
3c3ce30
merge main into pmd-7-pmd7 branch #329
stokpop Jun 2, 2022
9950123
merge main into pmd-7-pmd7 branch #329 - moved directory name from so…
stokpop Jun 2, 2022
ee4c0c5
* Partly Fix integration tests after merge #333
jborgers Jun 8, 2022
f6ad69a
* Fix integration tests after merge #333
jborgers Jun 8, 2022
e7a7811
pmd-7-pmd7: upgrade from pmd 7.0.0-kotlin-SNAPSHOT to 7.0.0-SNAPSHOT …
jborgers Jun 8, 2022
e3d1074
Fix Request: Links in Sonar-deprecated PMD rules to Sonar rules don't…
jborgers Jun 8, 2022
d3c276c
Merge branch 'master' into pmd-7-pmd7
stokpop Jun 9, 2022
5946572
merged main into pmd-7-pmd7 branch
stokpop Jun 9, 2022
0b89c36
pmd-7-pmd7: upgrade from pmd 7.0.0-kotlin-SNAPSHOT to 7.0.0-SNAPSHOT …
stokpop Jul 14, 2022
36fd27e
update README
jborgers Jan 13, 2023
1ac48a1
merged main into pmd-7-pmd7 branch and fixed unit tests
PeterPaul-Perfana Dec 5, 2024
78c8560
merged main into pmd-7-pmd7 branch and fixed integration tests
PeterPaul-Perfana Dec 6, 2024
59fb124
speedup integration tests by initializing orchestrator sonarqube only…
PeterPaul-Perfana Dec 6, 2024
f7b49b9
Use `pmd` as plugin key and rule prefix everywhere in favour of `pmd7`
PeterPaul-Perfana Jan 15, 2025
f72f4d5
Update dependencies, now needs java 17 to run build because newest so…
PeterPaul-Perfana Jan 15, 2025
24f980c
Update to run integration tests with SonarQube 10.7 and Sonar Java Pl…
PeterPaul-Perfana Jan 15, 2025
8403fc4
Upped mvnw and remaining sonarqube ui and maven plugins
PeterPaul-Perfana Jan 15, 2025
5c715d5
Merge pull request #489 from jborgers/pmd-7-pmd7-merge-master
jborgers Jan 16, 2025
1aba45d
version 4.0.0-SNAPSHOT
PeterPaul-Perfana Jan 25, 2025
fc95086
build: use java 17 for build (needed by sonar plugin jars)
PeterPaul-Perfana Jan 25, 2025
198f4aa
Update to pmd 7.10.0 and update README
jborgers Feb 21, 2025
ff5349c
Merge pull request #493 from jborgers/pmd-7-pmd7-update7-10
stokpop Feb 21, 2025
26668a5
Update README
jborgers Feb 21, 2025
60385a6
suppress UnresolvedMavenProperty
jborgers Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
echo "Tag '$TAG_NAME' does not contain 'SNAPSHOT', failing build."
exit 1

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-version: 17
server-id: sonatype-nexus
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SonarQube PMD Plugin
# 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)

[![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://github.com/jborgers/sonar-pmd/actions/workflows/build.yml/badge.svg)
Expand All @@ -13,7 +13,6 @@ For a list of all rules and their status, see: [RULES.md](https://github.com/jbo
## Installation
The plugin should be available in the SonarQube marketplace and is preferably installed from within SonarQube (Administration --> Marketplace --> Search _pmd_).

This plugin is available again from the Marketplace with the release of version 3.4.0.
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.

## Usage
Expand All @@ -25,15 +24,15 @@ Usage should be straight forward:
Sonar-PMD analyzes the given source code with the Java source version defined in your Gradle or Maven project.
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.

Possible values : 1.6 to 1.8/8 to 20-preview
Possible values : 1.6 to 1.8/8 to 24-preview

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

(*1) Note: Plugin version 3.4.x runs in SonarQube 8.9, however, Java 17+ is only fully supported in SonarQube 9.3+.
(*2) Note: Supports all tested Java 21 features; on parsing errors, warns instead of breaks
Expand Down
9 changes: 9 additions & 0 deletions integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-ws-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
Expand All @@ -69,6 +70,11 @@

<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.maven.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
Expand All @@ -78,6 +84,9 @@
<pluginDescription>Integration Test PmdExtensionPlugin</pluginDescription>
<!-- This is important. It means that this plugin extends the PMD plugin -->
<basePlugin>pmd</basePlugin>

<!-- This is important. It means that this plugin extends the PMD plugin -->
<basePlugin>pmd</basePlugin>
</configuration>
</plugin>
<!-- prevent deploy: https://stackoverflow.com/questions/25305850/how-to-disable-nexus-staging-maven-plugin-in-sub-modules -->
Expand Down
10 changes: 10 additions & 0 deletions integration-test/projects/pmd-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>5.0.0.4389</version>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>skipSonar</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package pmd;

public class Bar extends Foo {

public void method() {
// PMD7-MIGRATION: added to force one violation in pmdShouldHaveAccessToExternalLibrariesInItsClasspath: is this testing the correct thing?
if (true) System.out.println("violation on AvoidIfWithoutBrace");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SonarQube PMD Plugin Integration Test
* SonarQube PMD7 Plugin Integration Test
* Copyright (C) 2013-2021 SonarSource SA and others
* mailto:jborgers AT jpinpoint DOT com; peter.paul.bakker AT stokpop DOT nl
*
Expand All @@ -22,13 +22,14 @@

import java.util.List;

import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;

import net.sourceforge.pmd.lang.java.ast.ASTClassBody;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.properties.NumericConstraints;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
import net.sourceforge.pmd.properties.constraints.NumericConstraints;
import net.sourceforge.pmd.reporting.RuleContext;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

Expand Down Expand Up @@ -58,8 +59,8 @@ public void end(RuleContext ctx) {
}

@Override
public Object visit(ASTClassOrInterfaceBody node, Object data) {
List<ASTMethodDeclaration> methods = node.findDescendantsOfType(ASTMethodDeclaration.class);
public Object visit(ASTClassBody node, Object data) {
List<ASTMethodDeclaration> methods = node.descendants(ASTMethodDeclaration.class).toList();
if (methods.size() > getProperty(propertyDescriptor)) {
asCtx(data).addViolation(node);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SonarQube PMD Plugin Integration Test
* SonarQube PMD7 Plugin Integration Test
* Copyright (C) 2013-2021 SonarSource SA and others
* mailto:jborgers AT jpinpoint DOT com; peter.paul.bakker AT stokpop DOT nl
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SonarQube PMD Plugin Integration Test
* SonarQube PMD7 Plugin Integration Test
* Copyright (C) 2013-2021 SonarSource SA and others
* mailto:jborgers AT jpinpoint DOT com; peter.paul.bakker AT stokpop DOT nl
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
<priority>MAJOR</priority>
<description>Prevent use of EmptyClass class</description>
<name><![CDATA[Prevent use of EmptyClass]]></name>
<configKey><![CDATA[net.sourceforge.pmd.lang.rule.XPathRule]]></configKey>
<configKey><![CDATA[net.sourceforge.pmd.lang.rule.xpath.XPathRule]]></configKey>
<priority>MINOR</priority>
<param>
<key>xpath</key>
<description><![CDATA[XPath expressions.]]></description>
<defaultValue>//VariableDeclarator[../Type/ReferenceType/ClassOrInterfaceType[@Image='EmptyClass']]</defaultValue>
<defaultValue>//VariableDeclarator[../ClassOrInterfaceType[@SimpleName='EmptyClass']]</defaultValue>
</param>
<param>
<key>message</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0"?>
<ruleset name="PMD extensions"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

<description></description>
<description>Integration test rules</description>

<rule name="MaximumMethodsCountCheck"
message="Avoid too many methods"
class="org.sonar.examples.pmd.MaximumMethodsCountCheck">
class="org.sonar.examples.pmd.MaximumMethodsCountCheck"
language="java">
<description>
Avoid too many methods
</description>
Expand All @@ -18,19 +19,19 @@
</properties>
<example>
<![CDATA[
// too many methods!
public void doSomething() {}
public void doSomething2() {}
public void doSomething3() {}
public void doSomething4() {}
// too many methods!
public void doSomething() {}
public void doSomething2() {}
public void doSomething3() {}
public void doSomething4() {}

]]>
]]>
</example>
</rule>

<rule name="AvoidIfWithoutBrace"
message="Avoid if without using brace"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
language="java">
<description>
Avoid if without using brace
Expand All @@ -55,7 +56,7 @@

<rule name="DoNotExtendIOException"
message="Extend Exception rather than IOException."
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
language="java">
<description>
IOException should never be extended. Either use it, or extend Exception for your own business exceptions.
Expand All @@ -64,7 +65,7 @@
<property name="xpath">
<value>
<![CDATA[
//ClassOrInterfaceType[typeIs('java.io.IOException')]
//ClassOrInterfaceType[pmd-java:typeIs('java.io.IOException')]
]]>
</value>
</property>
Expand Down
Loading