Skip to content

Commit 11e7c4c

Browse files
author
陆小睿
committed
Fix sonarqube 10
1 parent 081ebb6 commit 11e7c4c

25 files changed

+362
-341
lines changed

CHANGELOG.md

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
11
# Changelog
22

3-
## [3.4.1-SNAPSHOT](https://github.com/jborgers/sonar-pmd/tree/master) (tbd)
4-
[Full Changelog](https://github.com/jborgers/sonar-pmd/compare/3.4.0...master)
53

6-
- nothing yet
4+
## [3.5.2-SNAPSHOT](https://github.com/jborgers/sonar-pmd/tree/3.5.2-SNAPSHOT) (2024-xx-xx)
5+
[Full Changelog](https://github.com/jborgers/sonar-pmd/compare/3.5.1..master)
6+
7+
**Implemented highlights:**
8+
9+
10+
## [3.5.1](https://github.com/jborgers/sonar-pmd/tree/3.5.1) (2024-05-07)
11+
[Full Changelog](https://github.com/jborgers/sonar-pmd/compare/3.5.0..3.5.1)
12+
13+
**Implemented highlights:**
14+
- Supports latest SonarQube [9.9.4 - 10.5+]
15+
- Supports running on Java 11 on analysis side for SQ 9.9.4 - 10.2.x
16+
- Supports running on Java 17 for all supported versions
17+
- Updated Sonar Plugin API+impl for SonarQube 9.9.4+
18+
- Upgraded various dependencies
19+
20+
- ## [3.5.0](https://github.com/jborgers/sonar-pmd/tree/3.5.0) (2024-04-23)
21+
[Full Changelog](https://github.com/jborgers/sonar-pmd/compare/3.4.0...3.5.0)
22+
23+
**Contributors:**
24+
- [jborgers](https://github.com/jborgers)
25+
- [renewolfert](https://github.com/renewolfert)
26+
27+
**Implemented highlights:**
28+
- Updated PMD (6.55.0) (last PMD-6) #422
29+
- Support analyzing up to Java 20-preview (close to 21) #422
30+
- Java 21+ falls back to 20-preview with warning (no error) #422
31+
- Updated Sonar Plugin API+impl (9.8.0.63668) (SonarQube 9.8+)
32+
- Upgraded various dependencies
33+
- Needs Java 17, the class file version is 61
734

835
## [3.4.0](https://github.com/jborgers/sonar-pmd/tree/3.4.0) (2022-05-11)
936
[Full Changelog](https://github.com/jborgers/sonar-pmd/compare/3.3.1...3.4.0)
1037

1138
**Contributors:**
39+
- [jborgers](https://github.com/jborgers)
40+
- [stokpop](https://github.com/stokpop)
1241
- [jensgerdes](https://github.com/jensgerdes) (Many thanks for his great maintenance and decision to transfer)
1342

1443
**Implemented highlights:**

README.md

+16-41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
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)
1+
# SonarQube PMD Plugin
2+
3+
[![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)
4+
![Build Status](https://github.com/jborgers/sonar-pmd/actions/workflows/build.yml/badge.svg)
5+
26
Sonar-PMD is a plugin that provides coding rules from [PMD](https://pmd.github.io/) for use in SonarQube.
37

48
Starting April 2022, the project has found a new home. We, [jborgers](https://github.com/jborgers) and [stokpop](https://github.com/stokpop),
@@ -9,8 +13,7 @@ For a list of all rules and their status, see: [RULES.md](https://github.com/jbo
913
## Installation
1014
The plugin should be available in the SonarQube marketplace and is preferably installed from within SonarQube (Administration --> Marketplace --> Search _pmd_).
1115

12-
Because of changed integration of the Java-plugin in SonarQube and our dependency on it, this plugin is temporarily not available from the Marketplace.
13-
Hopefully this will be fixed quickly with the release of version 3.4.0.
16+
This plugin is available again from the Marketplace with the release of version 3.4.0.
1417
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.
1518

1619
## Usage
@@ -22,18 +25,20 @@ Usage should be straight forward:
2225
Sonar-PMD analyzes the given source code with the Java source version defined in your Gradle or Maven project.
2326
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.
2427

25-
Possible values : 1.4 to 1.8/8 to 18
28+
Possible values : 1.6 to 1.8/8 to 20-preview
2629

2730
## Table of supported versions
28-
| PMD Plugin |2.5|2.6|3.0.0|3.1.x|3.2.x|3.3.x| 3.4.0 |
29-
|-----------------------------|---|---|---|---|---|---|----------------|
30-
| PMD |5.4.0|5.4.2|5.4.2|6.9.0|6.10.0|6.30.0| 6.45.0 |
31-
| Max. supported Java Version | 1.7 | 1.8 | 1.8 | 11 | | 15| 18 |
32-
| Min. SonarQube Version | 4.5.4 | 4.5.4 | 6.6 | | | 6.7| _8.9(*)_ / 9.3 |
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.1.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+ |
3337

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

36-
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.
41+
A majority of the PMD rules have been rewritten in the Sonar 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.
3742

3843
## Rules on test
3944
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.
@@ -48,33 +53,3 @@ To build the plugin and run the integration tests:
4853

4954
./mvnw clean verify
5055

51-
## 关于Alibaba P3c
52-
53-
本repo在sonar-pmd基础上增加了alibaba-p3c规则,详细的修改包括:
54-
55-
1. sonar-pmd-plugin 增加依赖
56-
57-
```xml
58-
<dependency>
59-
<groupId>com.alibaba.p3c</groupId>
60-
<artifactId>p3c-pmd</artifactId>
61-
<!-- 请保持最新 -->
62-
<version>2.1.1</version>
63-
</dependency>
64-
<dependency>
65-
<groupId>com.google.code.gson</groupId>
66-
<artifactId>gson</artifactId>
67-
<version>2.9.0</version>
68-
</dependency>
69-
```
70-
71-
2. 修改 `/resources/org/sonar/l10n/pmd/rules/pmd.properties` ,增加 p3c 的规则。同时修改 `org.sonar.plugins.pmd.PmdRulesDefinitionTest.test` 里面对规则条数的断言,从268改实际的324。
72-
3. 增加 `/resources/org/sonar/plugins/pmd/rules-p3c.xml`
73-
4. 增加规则描述 html `/resources/org/sonar/l10n/pmd-p3c`
74-
5. 修改 `/resources/com/sonar/sqale/pmd-model.xml` 增加P3c相关
75-
6. 修改 PmdRulesDefinition.java,加入p3c规则:
76-
77-
```java
78-
//org.sonar.plugins.pmd.rule.PmdRulesDefinition#define
79-
extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c");
80-
```

RELEASE.md

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1-
To release a build
1+
# Create release
22

3-
- change all `x.y.z-SNAPSHOT` to `x.y.z` in all poms
4-
- change tag `HEAD` to `x.y.z` in scm tag in parent pom
5-
- finish and update `CHANGELOG.md`, update `..master` to `..x.y.z`
6-
- commit and push with comment "Release x.y.z"
3+
To create a new release, set git tag with new version number and push the tag.
4+
The Github Actions `release.yml` will build and release to Github actions and Maven Central.
5+
6+
Make sure that all commits have been pushed and build
7+
with `build.yml` workflow before setting and pushing the tag.
8+
9+
Steps:
10+
- create release notes in `CHANGELOG.md`, update `..master` to `..x.y.z`; and update `README.md`
11+
- commit both
712
- `git tag x.y.z`
813
- `git push --tags`
9-
- use github action `release` to deploy to maven central
10-
- release staging repo in Sonatype ui
11-
- change all `x.y.z` in all poms to `x.y.z+1-SNAPSHOT`
12-
- change tag `x.y.z` in scm tag in parent pom to `HEAD`
14+
15+
The release workflow will be triggered, using the git tag for `-Drevision=<tag>`.
16+
17+
- manually release staging repo in [Sonatype](https://oss.sonatype.org/#welcome) for Maven Central
18+
- manually change Github actions release from draft to final and limit the changelog here: [releases](https://github.com/jborgers/sonar-pmd/releases)
19+
20+
Next prepare for next SNAPSHOT:
21+
22+
- change `revision` property in `x.y.z+1-SNAPSHOT` in parent pom
1323
- prepare `CHANGELOG.md` for `x.y.z+1-SNAPSHOT`
14-
- commit and push with comment "Prepare for release x.y.z+1-SNAPSHOT"
24+
- commit and push with comment "Prepare release x.y.z+1-SNAPSHOT"
1525

16-
When release fails before "release staging in Sonatype ui"
26+
When release fails before "release staging in Sonatype"
1727
- drop staging repo
18-
- `git tag -d x.y.z`
19-
- `git push origin :refs/tags/x.y.z`
28+
- `git tag -d x.y.z` or delete tag in IntelliJ
29+
- `git push origin :refs/tags/x.y.z` or delete tag in context menu, delete remotes
2030
- fix-commit-push and start release again with tagging steps above
2131

2232
In GitHub:
2333

24-
- create release from tag via Actions
25-
- update release notes with `CHANGELOG.md` contents
26-
- download `sonar-pmd-plugin-x.y.z.jar` and upload in release notes
2734
- close milestone `x.y.z`
2835
- create new milestone `x.y.z+1`
2936

integration-test/pom.xml

+7-48
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>org.sonarsource.pmd</groupId>
2727
<artifactId>sonar-pmd</artifactId>
28-
<version>1.0.1-SNAPSHOT</version>
28+
<version>${revision}</version>
2929
</parent>
3030

3131
<artifactId>integration-test</artifactId>
@@ -42,13 +42,18 @@
4242
<groupId>org.sonarsource.orchestrator</groupId>
4343
<artifactId>sonar-orchestrator</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>org.sonarsource.orchestrator</groupId>
47+
<artifactId>sonar-orchestrator-junit4</artifactId>
48+
</dependency>
4549
<dependency>
4650
<groupId>org.codehaus.sonar</groupId>
4751
<artifactId>sonar-ws-client</artifactId>
4852
</dependency>
4953
<dependency>
50-
<groupId>org.sonarsource.sonarqube</groupId>
54+
<groupId>org.sonarsource.api.plugin</groupId>
5155
<artifactId>sonar-plugin-api</artifactId>
56+
<scope>provided</scope>
5257
</dependency>
5358
<dependency>
5459
<groupId>net.sourceforge.pmd</groupId>
@@ -58,54 +63,8 @@
5863
<dependency>
5964
<groupId>org.apache.commons</groupId>
6065
<artifactId>commons-lang3</artifactId>
61-
<version>3.14.0</version>
62-
<scope>test</scope>
63-
</dependency>
64-
<dependency>
65-
<groupId>commons-io</groupId>
66-
<artifactId>commons-io</artifactId>
67-
<version>2.15.1</version>
68-
<scope>test</scope>
69-
</dependency>
70-
<dependency>
71-
<groupId>commons-lang</groupId>
72-
<artifactId>commons-lang</artifactId>
73-
<version>2.6</version>
74-
<scope>test</scope>
75-
</dependency>
76-
<dependency>
77-
<groupId>commons-codec</groupId>
78-
<artifactId>commons-codec</artifactId>
79-
<version>1.16.0</version>
80-
</dependency>
81-
<dependency>
82-
<groupId>org.apache.commons</groupId>
83-
<artifactId>commons-exec</artifactId>
84-
<version>1.4.0</version>
85-
</dependency>
86-
<dependency>
87-
<groupId>org.slf4j</groupId>
88-
<artifactId>slf4j-api</artifactId>
89-
<version>2.0.11</version>
9066
<scope>test</scope>
9167
</dependency>
92-
<dependency>
93-
<groupId>com.h2database</groupId>
94-
<artifactId>h2</artifactId>
95-
<version>2.2.224</version>
96-
<scope>test</scope>
97-
</dependency>
98-
<dependency>
99-
<groupId>com.squareup.okhttp3</groupId>
100-
<artifactId>okhttp</artifactId>
101-
<version>4.12.0</version>
102-
<scope>test</scope>
103-
</dependency>
104-
<dependency>
105-
<groupId>com.eclipsesource.minimal-json</groupId>
106-
<artifactId>minimal-json</artifactId>
107-
<version>0.9.5</version>
108-
</dependency>
10968
</dependencies>
11069

11170
<build>

integration-test/projects/pmd-junit-rules/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<dependency>
1111
<groupId>junit</groupId>
1212
<artifactId>junit</artifactId>
13-
<version>3.8</version>
13+
<version>4.13.2</version>
1414
<scope>test</scope>
1515
</dependency>
1616
</dependencies>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void end(RuleContext ctx) {
6161
public Object visit(ASTClassOrInterfaceBody node, Object data) {
6262
List<ASTMethodDeclaration> methods = node.findDescendantsOfType(ASTMethodDeclaration.class);
6363
if (methods.size() > getProperty(propertyDescriptor)) {
64-
addViolation(data, node);
64+
asCtx(data).addViolation(node);
6565
}
6666
return super.visit(node, data);
6767
}

integration-test/src/test/java/com/sonar/it/java/suite/PmdIT.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@
1919
*/
2020
package com.sonar.it.java.suite;
2121

22-
import static com.sonar.it.java.suite.TestUtils.keyFor;
23-
import static com.sonar.it.java.suite.TestUtils.keyForTest;
24-
import static org.assertj.core.api.Assertions.assertThat;
25-
2622
import com.sonar.it.java.suite.orchestrator.PmdTestOrchestrator;
2723
import com.sonar.orchestrator.build.BuildResult;
2824
import com.sonar.orchestrator.build.MavenBuild;
29-
import java.util.List;
30-
import java.util.stream.Collectors;
3125
import org.apache.commons.lang3.JavaVersion;
3226
import org.junit.jupiter.api.BeforeAll;
3327
import org.junit.jupiter.api.Test;
@@ -36,6 +30,13 @@
3630
import org.sonar.wsclient.issue.Issue;
3731
import org.sonar.wsclient.issue.IssueQuery;
3832

33+
import java.util.List;
34+
import java.util.stream.Collectors;
35+
36+
import static com.sonar.it.java.suite.TestUtils.keyFor;
37+
import static com.sonar.it.java.suite.TestUtils.keyForTest;
38+
import static org.assertj.core.api.Assertions.assertThat;
39+
3940
class PmdIT {
4041

4142
private static final PmdTestOrchestrator ORCHESTRATOR = PmdTestOrchestrator.init();
@@ -46,7 +47,7 @@ static void startSonar() {
4647
}
4748

4849
@ParameterizedTest
49-
@EnumSource(value = JavaVersion.class, mode = EnumSource.Mode.INCLUDE, names = {"JAVA_1_8", "JAVA_11", "JAVA_16"})
50+
@EnumSource(value = JavaVersion.class, mode = EnumSource.Mode.INCLUDE, names = {"JAVA_1_8", "JAVA_11", "JAVA_17", "JAVA_20"})
5051
void testPmdExtensionsWithDifferentJavaVersions(JavaVersion version) {
5152

5253
// given
@@ -144,7 +145,7 @@ void testJunitRules() {
144145
// then
145146
final List<Issue> testIssues = retrieveIssues(keyForTest());
146147
assertThat(testIssues).hasSize(1);
147-
assertThat(testIssues.get(0).message()).matches("The class '.+?Test' might be a test class, but it contains no test cases.");
148+
assertThat(testIssues.get(0).message()).matches("The class 'ProductionCodeTest' might be a test class, but it contains no test cases.");
148149
assertThat(testIssues.get(0).ruleKey()).isEqualTo("pmd-unit-tests:TestClassWithoutTestCases");
149150

150151
final List<Issue> prodIssues = retrieveIssues(keyFor(projectName, "", "ProductionCode"));

0 commit comments

Comments
 (0)