Skip to content

Commit 796fa54

Browse files
committed
Update to PMD 7.0.0-rc3
1 parent 2cfd612 commit 796fa54

File tree

15 files changed

+175
-30
lines changed

15 files changed

+175
-30
lines changed

custom-rules/maven-java/.ci/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ echo "======================================================="
1919
echo
2020
cd pmd-java-dist/target
2121
unzip -q pmd-java-bin-1.0.0-SNAPSHOT.zip
22-
pmd-java-bin-1.0.0-SNAPSHOT/bin/run.sh pmd --no-cache \
22+
pmd-java-bin-1.0.0-SNAPSHOT/bin/pmd check --no-cache \
2323
-f text \
2424
-d ../../ \
2525
-R custom-java-ruleset.xml \
26-
--fail-on-violation false \
26+
--no-fail-on-violation \
2727
--report-file pmdreport.txt
2828

2929
grep "examples/java/rules/MyRule.java" pmdreport.txt || (echo -e "\n\n\x1b[31mMissing expected rule violation\e[0m"; exit 1)

custom-rules/maven-java/pmd-java-custom/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</dependency>
1919

2020
<dependency>
21-
<groupId>junit</groupId>
22-
<artifactId>junit</artifactId>
21+
<groupId>org.junit.jupiter</groupId>
22+
<artifactId>junit-jupiter</artifactId>
2323
<scope>test</scope>
2424
</dependency>
2525
<dependency>

custom-rules/maven-java/pmd-java-custom/src/main/java/net/sourceforge/pmd/examples/java/rules/MyRule.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package net.sourceforge.pmd.examples.java.rules;
22

3+
import org.checkerframework.checker.nullness.qual.NonNull;
4+
35
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
46
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
7+
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
58
import net.sourceforge.pmd.properties.PropertyDescriptor;
69
import net.sourceforge.pmd.properties.PropertyFactory;
710

@@ -14,13 +17,17 @@ public class MyRule extends AbstractJavaRule {
1417

1518
public MyRule() {
1619
definePropertyDescriptor(BAD_NAME);
17-
addRuleChainVisit(ASTVariableDeclaratorId.class);
20+
}
21+
22+
@Override
23+
protected @NonNull RuleTargetSelector buildTargetSelector() {
24+
return RuleTargetSelector.forTypes(ASTVariableDeclaratorId.class);
1825
}
1926

2027
@Override
2128
public Object visit(ASTVariableDeclaratorId node, Object data) {
2229
String badName = getProperty(BAD_NAME);
23-
if (node.hasImageEqualTo(badName)) {
30+
if (badName.equals(node.getName())) {
2431
asCtx(data).addViolation(node, node.getName());
2532
}
2633
return data;

custom-rules/maven-java/pmd-java-custom/src/main/resources/net/sourceforge/pmd/examples/java/rules/VariableNaming.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Variables should be all lowercase.
2121
<property name="xpath">
2222
<value>
2323
<![CDATA[
24-
//VariableDeclaratorId[not(pmd:matches(@Name, $pattern))]
24+
//VariableDeclaratorId[not(matches(@Name, $pattern))]
2525
]]>
2626
</value>
2727
</property>

custom-rules/maven-java/pmd-java-dist/pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<type>jar</type>
4040
<overWrite>false</overWrite>
4141
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
42-
<includes>scripts/**,LICENSE</includes>
42+
<includes>scripts/**,LICENSE,conf/**</includes>
4343
</artifactItem>
4444
</artifactItems>
4545
</configuration>
@@ -97,6 +97,17 @@
9797
<groupId>net.sourceforge.pmd</groupId>
9898
<artifactId>pmd-ui</artifactId>
9999
</dependency>
100+
<dependency>
101+
<groupId>net.sourceforge.pmd</groupId>
102+
<artifactId>pmd-cli</artifactId>
103+
</dependency>
104+
<!-- include bash/zsh completions -->
105+
<dependency>
106+
<groupId>net.sourceforge.pmd</groupId>
107+
<artifactId>pmd-cli</artifactId>
108+
<type>sh</type>
109+
<classifier>completion</classifier>
110+
</dependency>
100111
</dependencies>
101112

102113
</project>

custom-rules/maven-java/pom.xml

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<java.version>8</java.version>
1616
<maven.compiler.release>${java.version}</maven.compiler.release>
17-
<pmd.version>6.55.0</pmd.version>
18-
<pmd.ui.version>6.49.0</pmd.ui.version>
17+
<pmd.version>7.0.0-rc3</pmd.version>
18+
<pmd.ui.version>7.0.0-rc1</pmd.ui.version>
1919
</properties>
2020

2121
<dependencyManagement>
@@ -35,16 +35,31 @@
3535
<artifactId>pmd-ui</artifactId>
3636
<version>${pmd.ui.version}</version>
3737
</dependency>
38+
<dependency>
39+
<groupId>net.sourceforge.pmd</groupId>
40+
<artifactId>pmd-cli</artifactId>
41+
<version>${pmd.version}</version>
42+
<scope>runtime</scope>
43+
</dependency>
44+
<!-- include bash/zsh completions -->
45+
<dependency>
46+
<groupId>net.sourceforge.pmd</groupId>
47+
<artifactId>pmd-cli</artifactId>
48+
<version>${pmd.version}</version>
49+
<type>sh</type>
50+
<classifier>completion</classifier>
51+
<scope>runtime</scope>
52+
</dependency>
3853
<dependency>
3954
<groupId>net.sourceforge.pmd</groupId>
4055
<artifactId>pmd-test</artifactId>
4156
<version>${pmd.version}</version>
4257
<scope>test</scope>
4358
</dependency>
4459
<dependency>
45-
<groupId>junit</groupId>
46-
<artifactId>junit</artifactId>
47-
<version>4.13.1</version>
60+
<groupId>org.junit.jupiter</groupId>
61+
<artifactId>junit-jupiter</artifactId>
62+
<version>5.8.2</version>
4863
<scope>test</scope>
4964
</dependency>
5065
</dependencies>
@@ -68,8 +83,35 @@
6883
<artifactId>maven-dependency-plugin</artifactId>
6984
<version>3.6.0</version>
7085
</plugin>
86+
<plugin>
87+
<groupId>org.cyclonedx</groupId>
88+
<artifactId>cyclonedx-maven-plugin</artifactId>
89+
<version>2.7.6</version>
90+
</plugin>
7191
</plugins>
7292
</pluginManagement>
93+
<plugins>
94+
<plugin>
95+
<groupId>org.cyclonedx</groupId>
96+
<artifactId>cyclonedx-maven-plugin</artifactId>
97+
<executions>
98+
<execution>
99+
<phase>package</phase>
100+
<goals>
101+
<goal>makeAggregateBom</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
<!-- https://github.com/CycloneDX/cyclonedx-maven-plugin/issues/326 -->
106+
<dependencies>
107+
<dependency>
108+
<groupId>org.ow2.asm</groupId>
109+
<artifactId>asm</artifactId>
110+
<version>9.5</version>
111+
</dependency>
112+
</dependencies>
113+
</plugin>
114+
</plugins>
73115
</build>
74116

75117
<url>https://github.com/pmd/pmd-examples</url>

custom-rules/maven-plsql/.ci/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ echo "======================================================="
1919
echo
2020
cd pmd-plsql-dist/target
2121
unzip -q pmd-plsql-bin-1.0.0-SNAPSHOT.zip
22-
pmd-plsql-bin-1.0.0-SNAPSHOT/bin/run.sh pmd --no-cache \
23-
--use-version plsql- \
22+
pmd-plsql-bin-1.0.0-SNAPSHOT/bin/pmd check --no-cache \
23+
--use-version plsql-21c \
2424
-f text \
2525
-d ../../pmd-plsql-custom/src/test/plsql \
2626
-R custom-plsql-ruleset.xml \
27-
--fail-on-violation false \
27+
--no-fail-on-violation \
2828
--report-file pmdreport.txt
2929

3030
grep "pmd-plsql-custom/src/test/plsql/short_variables.pls" pmdreport.txt || (echo -e "\n\n\x1b[31mMissing expected rule violation\e[0m"; exit 1)

custom-rules/maven-plsql/pmd-plsql-custom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<groupId>net.sourceforge.pmd</groupId>
2121
<artifactId>pmd-plsql</artifactId>
2222
</dependency>
23+
<dependency>
24+
<groupId>org.junit.jupiter</groupId>
25+
<artifactId>junit-jupiter</artifactId>
26+
<scope>test</scope>
27+
</dependency>
2328
<dependency>
2429
<groupId>net.sourceforge.pmd</groupId>
2530
<artifactId>pmd-test</artifactId>

custom-rules/maven-plsql/pmd-plsql-custom/src/main/java/net/sourceforge/pmd/examples/plsql/rules/ShortVariableRule.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
package net.sourceforge.pmd.examples.plsql.rules;
66

7+
import org.checkerframework.checker.nullness.qual.NonNull;
8+
79
import net.sourceforge.pmd.lang.plsql.ast.ASTID;
810
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclaratorId;
911
import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule;
12+
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
1013
import net.sourceforge.pmd.properties.PropertyDescriptor;
1114
import net.sourceforge.pmd.properties.PropertyFactory;
1215
import net.sourceforge.pmd.properties.constraints.NumericConstraints;
@@ -21,14 +24,18 @@ public class ShortVariableRule extends AbstractPLSQLRule {
2124

2225
public ShortVariableRule() {
2326
definePropertyDescriptor(MINIMUM_LENGTH);
24-
addRuleChainVisit(ASTVariableOrConstantDeclaratorId.class);
27+
}
28+
29+
@Override
30+
protected @NonNull RuleTargetSelector buildTargetSelector() {
31+
return RuleTargetSelector.forTypes(ASTVariableOrConstantDeclaratorId.class);
2532
}
2633

2734
@Override
2835
public Object visit(ASTVariableOrConstantDeclaratorId node, Object data) {
2936
Integer min = getProperty(MINIMUM_LENGTH);
3037

31-
ASTID id = node.getFirstChildOfType(ASTID.class);
38+
ASTID id = node.firstChild(ASTID.class);
3239
if (id != null) {
3340
if (node.getImage().length() < min) {
3441
asCtx(data).addViolation(node, node.getImage());

custom-rules/maven-plsql/pmd-plsql-custom/src/main/resources/net/sourceforge/pmd/examples/plsql/rules/VariableNaming.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Variables should be all lowercase.
2121
<property name="xpath">
2222
<value>
2323
<![CDATA[
24-
//VariableOrConstantDeclaratorId[ID[not(pmd:matches(@Image, $pattern))]]
24+
//VariableOrConstantDeclaratorId[ID[not(matches(@Image, $pattern))]]
2525
]]>
2626
</value>
2727
</property>

custom-rules/maven-plsql/pmd-plsql-dist/pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<type>jar</type>
4040
<overWrite>false</overWrite>
4141
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
42-
<includes>scripts/**,LICENSE</includes>
42+
<includes>scripts/**,LICENSE,conf/**</includes>
4343
</artifactItem>
4444
</artifactItems>
4545
</configuration>
@@ -97,6 +97,17 @@
9797
<groupId>net.sourceforge.pmd</groupId>
9898
<artifactId>pmd-ui</artifactId>
9999
</dependency>
100+
<dependency>
101+
<groupId>net.sourceforge.pmd</groupId>
102+
<artifactId>pmd-cli</artifactId>
103+
</dependency>
104+
<!-- include bash/zsh completions -->
105+
<dependency>
106+
<groupId>net.sourceforge.pmd</groupId>
107+
<artifactId>pmd-cli</artifactId>
108+
<type>sh</type>
109+
<classifier>completion</classifier>
110+
</dependency>
100111
</dependencies>
101112

102113
</project>

custom-rules/maven-plsql/pom.xml

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<java.version>8</java.version>
1616
<maven.compiler.release>${java.version}</maven.compiler.release>
17-
<pmd.version>6.55.0</pmd.version>
18-
<pmd.ui.version>6.49.0</pmd.ui.version>
17+
<pmd.version>7.0.0-rc3</pmd.version>
18+
<pmd.ui.version>7.0.0-rc1</pmd.ui.version>
1919
</properties>
2020

2121
<dependencyManagement>
@@ -35,12 +35,33 @@
3535
<artifactId>pmd-ui</artifactId>
3636
<version>${pmd.ui.version}</version>
3737
</dependency>
38+
<dependency>
39+
<groupId>net.sourceforge.pmd</groupId>
40+
<artifactId>pmd-cli</artifactId>
41+
<version>${pmd.version}</version>
42+
<scope>runtime</scope>
43+
</dependency>
44+
<!-- include bash/zsh completions -->
45+
<dependency>
46+
<groupId>net.sourceforge.pmd</groupId>
47+
<artifactId>pmd-cli</artifactId>
48+
<version>${pmd.version}</version>
49+
<type>sh</type>
50+
<classifier>completion</classifier>
51+
<scope>runtime</scope>
52+
</dependency>
3853
<dependency>
3954
<groupId>net.sourceforge.pmd</groupId>
4055
<artifactId>pmd-test</artifactId>
4156
<version>${pmd.version}</version>
4257
<scope>test</scope>
4358
</dependency>
59+
<dependency>
60+
<groupId>org.junit.jupiter</groupId>
61+
<artifactId>junit-jupiter</artifactId>
62+
<version>5.8.2</version>
63+
<scope>test</scope>
64+
</dependency>
4465
</dependencies>
4566
</dependencyManagement>
4667

@@ -62,8 +83,35 @@
6283
<artifactId>maven-dependency-plugin</artifactId>
6384
<version>3.6.0</version>
6485
</plugin>
86+
<plugin>
87+
<groupId>org.cyclonedx</groupId>
88+
<artifactId>cyclonedx-maven-plugin</artifactId>
89+
<version>2.7.6</version>
90+
</plugin>
6591
</plugins>
6692
</pluginManagement>
93+
<plugins>
94+
<plugin>
95+
<groupId>org.cyclonedx</groupId>
96+
<artifactId>cyclonedx-maven-plugin</artifactId>
97+
<executions>
98+
<execution>
99+
<phase>package</phase>
100+
<goals>
101+
<goal>makeAggregateBom</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
<!-- https://github.com/CycloneDX/cyclonedx-maven-plugin/issues/326 -->
106+
<dependencies>
107+
<dependency>
108+
<groupId>org.ow2.asm</groupId>
109+
<artifactId>asm</artifactId>
110+
<version>9.5</version>
111+
</dependency>
112+
</dependencies>
113+
</plugin>
114+
</plugins>
67115
</build>
68116

69117
<url>https://github.com/pmd/pmd-examples</url>

custom-rules/plain-java/.ci/build.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -e
55
java -version
66

7-
PMD_VERSION=6.55.0
7+
PMD_VERSION=7.0.0-rc3
88

99
echo
1010
echo "======================================================="
@@ -22,8 +22,8 @@ echo "======================================================="
2222
echo
2323
export PMD_HOME=${BASEDIR}/code/pmd-bin-${PMD_VERSION}
2424
if [ ! -d ${PMD_HOME} ]; then
25-
wget --no-verbose https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip -O ${BASEDIR}/code/pmd-bin-${PMD_VERSION}.zip
26-
unzip -q -d ${BASEDIR}/code ${BASEDIR}/code/pmd-bin-${PMD_VERSION}.zip
25+
wget --no-verbose https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-dist-${PMD_VERSION}-bin.zip -O ${BASEDIR}/code/pmd-dist-${PMD_VERSION}-bin.zip
26+
unzip -q -d ${BASEDIR}/code ${BASEDIR}/code/pmd-dist-${PMD_VERSION}-bin.zip
2727
echo "PMD ${PMD_VERSION} installed at: ${PMD_HOME}"
2828
else
2929
echo "PMD ${PMD_VERSION} already installed: ${PMD_HOME}"
@@ -48,10 +48,10 @@ cp src/myrule.xml build/
4848
echo "Creating jar custom-rule-example.jar..."
4949
jar -c -f custom-rule-example.jar -C build .
5050
echo "Executing PMD"
51-
CLASSPATH=custom-rule-example.jar ${PMD_HOME}/bin/run.sh pmd \
51+
CLASSPATH=custom-rule-example.jar ${PMD_HOME}/bin/pmd check \
5252
--no-cache \
5353
-f text -d testsrc -R myrule.xml \
54-
--fail-on-violation false \
54+
--no-fail-on-violation \
5555
--report-file build/report.txt
5656

5757
grep "testsrc/Test.java" build/report.txt || (echo -e "\n\n\x1b[31mMissing expected rule violation\e[0m"; exit 1)

custom-rules/plain-java/src/MyRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class MyRule extends AbstractJavaRule {
55

66
@Override
77
public Object visit(ASTVariableDeclaratorId node, Object data) {
8-
if (node.hasImageEqualTo("foo")) {
8+
if ("foo".equals(node.getName())) {
99
asCtx(data).addViolationWithMessage(node, "Avoid the identifier 'foo'.");
1010
}
1111
return super.visit(node, data);

0 commit comments

Comments
 (0)