Skip to content

Commit 3ddb25d

Browse files
authored
Merge pull request #3 from adangel/pmd7
Update to PMD 7.0.0-rc3
2 parents 2cfd612 + 345cf61 commit 3ddb25d

File tree

16 files changed

+216
-36
lines changed

16 files changed

+216
-36
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ echo "Running PMD..."
1818
echo "======================================================="
1919
echo
2020
cd pmd-java-dist/target
21-
unzip -q pmd-java-bin-1.0.0-SNAPSHOT.zip
22-
pmd-java-bin-1.0.0-SNAPSHOT/bin/run.sh pmd --no-cache \
21+
unzip -q pmd-java-dist-1.0.0-SNAPSHOT-bin.zip
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/README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ The result is a zip file: `target/pmd-java-bin-1.0.0-SNAPSHOT.zip`.
3434
### Option A
3535

3636
1. Install PMD using the created `pmd-java-bin-1.0.0-SNAPSHOT.zip` file like a normal PMD binary distribution.
37-
2. Run PMD: `./run.sh pmd -f text -d src -R custom-java-ruleset.xml`
37+
2. Run PMD: `bin/pmd check -f text -d src -R custom-java-ruleset.xml`
3838

3939
### Option B
4040

4141
1. Install PMD as usual.
4242
2. Copy the jar file `pmd-java-custom-1.0.0-SNAPSHOT.jar` to the `lib` directory, where you have
4343
installed PMD.
44-
3. Run PMD: `./run.sh pmd -f text -d src -R custom-java-ruleset.xml`
44+
3. Run PMD: `bin/pmd check -f text -d src -R custom-java-ruleset.xml`
4545

4646
## Using with the maven-pmd-plugin
4747

@@ -56,11 +56,14 @@ The result is a zip file: `target/pmd-java-bin-1.0.0-SNAPSHOT.zip`.
5656
the maven-pmd-plugin:
5757

5858
```xml
59+
<properties>
60+
<pmd.version>7.0.0-rc3</pmd.version>
61+
</properties>
5962
...
6063
<plugin>
6164
<groupId>org.apache.maven.plugins</groupId>
6265
<artifactId>maven-pmd-plugin</artifactId>
63-
<version>3.11.0</version>
66+
<version>3.21.1-pmd-7-SNAPSHOT</version>
6467
<executions>
6568
<execution>
6669
<phase>verify</phase>
@@ -83,6 +86,26 @@ The result is a zip file: `target/pmd-java-bin-1.0.0-SNAPSHOT.zip`.
8386
<artifactId>pmd-java-custom</artifactId>
8487
<version>1.0.0-SNAPSHOT</version>
8588
</dependency>
89+
<dependency>
90+
<groupId>net.sourceforge.pmd</groupId>
91+
<artifactId>pmd-core</artifactId>
92+
<version>${pmd.version}</version>
93+
</dependency>
94+
<dependency>
95+
<groupId>net.sourceforge.pmd</groupId>
96+
<artifactId>pmd-java</artifactId>
97+
<version>${pmd.version}</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>net.sourceforge.pmd</groupId>
101+
<artifactId>pmd-javascript</artifactId>
102+
<version>${pmd.version}</version>
103+
</dependency>
104+
<dependency>
105+
<groupId>net.sourceforge.pmd</groupId>
106+
<artifactId>pmd-jsp</artifactId>
107+
<version>${pmd.version}</version>
108+
</dependency>
86109
</dependencies>
87110
</plugin>
88111
```

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 & 3 deletions
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>
@@ -56,12 +56,10 @@
5656
</dependency>
5757
</dependencies>
5858
<configuration>
59-
<appendAssemblyId>false</appendAssemblyId>
6059
<attach>false</attach>
6160
<archiverConfig>
6261
<defaultDirectoryMode>493</defaultDirectoryMode> <!-- 0755 -->
6362
</archiverConfig>
64-
<finalName>${pmd.dist.bin.baseDirectory}</finalName>
6563
<descriptorRefs>
6664
<descriptorRef>pmd-bin</descriptorRef>
6765
</descriptorRefs>
@@ -97,6 +95,17 @@
9795
<groupId>net.sourceforge.pmd</groupId>
9896
<artifactId>pmd-ui</artifactId>
9997
</dependency>
98+
<dependency>
99+
<groupId>net.sourceforge.pmd</groupId>
100+
<artifactId>pmd-cli</artifactId>
101+
</dependency>
102+
<!-- include bash/zsh completions -->
103+
<dependency>
104+
<groupId>net.sourceforge.pmd</groupId>
105+
<artifactId>pmd-cli</artifactId>
106+
<type>sh</type>
107+
<classifier>completion</classifier>
108+
</dependency>
100109
</dependencies>
101110

102111
</project>

custom-rules/maven-java/pom.xml

Lines changed: 61 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,45 @@
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+
<exclusions>
44+
<!-- exclude pmd-languages-deps because we only want to include pmd-java in our custom distribution -->
45+
<exclusion>
46+
<groupId>net.sourceforge.pmd</groupId>
47+
<artifactId>pmd-languages-deps</artifactId>
48+
</exclusion>
49+
</exclusions>
50+
</dependency>
51+
<!-- include bash/zsh completions -->
52+
<dependency>
53+
<groupId>net.sourceforge.pmd</groupId>
54+
<artifactId>pmd-cli</artifactId>
55+
<version>${pmd.version}</version>
56+
<type>sh</type>
57+
<classifier>completion</classifier>
58+
<scope>runtime</scope>
59+
<exclusions>
60+
<!-- exclude pmd-languages-deps because we only want to include pmd-java in our custom distribution -->
61+
<exclusion>
62+
<groupId>net.sourceforge.pmd</groupId>
63+
<artifactId>pmd-languages-deps</artifactId>
64+
</exclusion>
65+
</exclusions>
66+
</dependency>
3867
<dependency>
3968
<groupId>net.sourceforge.pmd</groupId>
4069
<artifactId>pmd-test</artifactId>
4170
<version>${pmd.version}</version>
4271
<scope>test</scope>
4372
</dependency>
4473
<dependency>
45-
<groupId>junit</groupId>
46-
<artifactId>junit</artifactId>
47-
<version>4.13.1</version>
74+
<groupId>org.junit.jupiter</groupId>
75+
<artifactId>junit-jupiter</artifactId>
76+
<version>5.8.2</version>
4877
<scope>test</scope>
4978
</dependency>
5079
</dependencies>
@@ -68,8 +97,35 @@
6897
<artifactId>maven-dependency-plugin</artifactId>
6998
<version>3.6.0</version>
7099
</plugin>
100+
<plugin>
101+
<groupId>org.cyclonedx</groupId>
102+
<artifactId>cyclonedx-maven-plugin</artifactId>
103+
<version>2.7.6</version>
104+
</plugin>
71105
</plugins>
72106
</pluginManagement>
107+
<plugins>
108+
<plugin>
109+
<groupId>org.cyclonedx</groupId>
110+
<artifactId>cyclonedx-maven-plugin</artifactId>
111+
<executions>
112+
<execution>
113+
<phase>package</phase>
114+
<goals>
115+
<goal>makeAggregateBom</goal>
116+
</goals>
117+
</execution>
118+
</executions>
119+
<!-- https://github.com/CycloneDX/cyclonedx-maven-plugin/issues/326 -->
120+
<dependencies>
121+
<dependency>
122+
<groupId>org.ow2.asm</groupId>
123+
<artifactId>asm</artifactId>
124+
<version>9.5</version>
125+
</dependency>
126+
</dependencies>
127+
</plugin>
128+
</plugins>
73129
</build>
74130

75131
<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());

0 commit comments

Comments
 (0)