Skip to content

Commit 06d5baa

Browse files
committed
Merge pull request #4 from adangel:update-to-pmd7
Update to latest PMD 7 #4
2 parents 35a36c8 + 3b0a7e1 commit 06d5baa

File tree

14 files changed

+107
-98
lines changed

14 files changed

+107
-98
lines changed

custom-rules/maven-java/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ The result is a zip file: `target/pmd-java-bin-1.0.0-SNAPSHOT.zip`.
5757

5858
```xml
5959
<properties>
60-
<pmd.version>7.0.0-rc3</pmd.version>
60+
<pmd.version>7.0.0-SNAPSHOT</pmd.version>
6161
</properties>
6262
...
6363
<plugin>
6464
<groupId>org.apache.maven.plugins</groupId>
6565
<artifactId>maven-pmd-plugin</artifactId>
66-
<version>3.21.1-pmd-7-SNAPSHOT</version>
66+
<version>3.21.2</version>
6767
<executions>
6868
<execution>
6969
<phase>verify</phase>
@@ -86,6 +86,11 @@ The result is a zip file: `target/pmd-java-bin-1.0.0-SNAPSHOT.zip`.
8686
<artifactId>pmd-java-custom</artifactId>
8787
<version>1.0.0-SNAPSHOT</version>
8888
</dependency>
89+
<dependency>
90+
<groupId>net.sourceforge.pmd</groupId>
91+
<artifactId>pmd-compat6</artifactId>
92+
<version>${pmd.version}</version>
93+
</dependency>
8994
<dependency>
9095
<groupId>net.sourceforge.pmd</groupId>
9196
<artifactId>pmd-core</artifactId>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.checkerframework.checker.nullness.qual.NonNull;
44

5-
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
5+
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
66
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
77
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
88
import net.sourceforge.pmd.properties.PropertyDescriptor;
@@ -21,11 +21,11 @@ public MyRule() {
2121

2222
@Override
2323
protected @NonNull RuleTargetSelector buildTargetSelector() {
24-
return RuleTargetSelector.forTypes(ASTVariableDeclaratorId.class);
24+
return RuleTargetSelector.forTypes(ASTVariableId.class);
2525
}
2626

2727
@Override
28-
public Object visit(ASTVariableDeclaratorId node, Object data) {
28+
public Object visit(ASTVariableId node, Object data) {
2929
String badName = getProperty(BAD_NAME);
3030
if (badName.equals(node.getName())) {
3131
asCtx(data).addViolation(node, node.getName());

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Rule set which defines VariableNamingRule
1111

1212
<rule name="VariableNaming"
1313
language="java"
14-
class="net.sourceforge.pmd.lang.rule.XPathRule"
14+
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
1515
message="Variables should be all lowercase">
1616
<description>
1717
Variables should be all lowercase.
@@ -21,11 +21,10 @@ Variables should be all lowercase.
2121
<property name="xpath">
2222
<value>
2323
<![CDATA[
24-
//VariableDeclaratorId[not(matches(@Name, $pattern))]
24+
//VariableId[not(matches(@Name, $pattern))]
2525
]]>
2626
</value>
2727
</property>
28-
<property name="version" value="2.0" />
2928
<property name="pattern" type="Regex" value="^[a-z_]+$" description="Pattern for valid variable names"/>
3029
</properties>
3130
<example>

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@
9999
<groupId>net.sourceforge.pmd</groupId>
100100
<artifactId>pmd-cli</artifactId>
101101
</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>
109102
</dependencies>
110103

111104
</project>

custom-rules/maven-java/pom.xml

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@
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>7.0.0-rc3</pmd.version>
18-
<pmd.ui.version>7.0.0-rc1</pmd.ui.version>
17+
<pmd.version>7.0.0-SNAPSHOT</pmd.version>
18+
<pmd.ui.version>7.0.0-SNAPSHOT</pmd.ui.version>
1919
</properties>
2020

21+
<repositories>
22+
<repository>
23+
<id>oss-snapshots</id>
24+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
25+
<releases><enabled>false</enabled></releases>
26+
<snapshots><enabled>true</enabled></snapshots>
27+
</repository>
28+
</repositories>
29+
<pluginRepositories>
30+
<pluginRepository>
31+
<id>oss-snapshots</id>
32+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
33+
<releases><enabled>false</enabled></releases>
34+
<snapshots><enabled>true</enabled></snapshots>
35+
</pluginRepository>
36+
</pluginRepositories>
37+
2138
<dependencyManagement>
2239
<dependencies>
2340
<dependency>
@@ -48,22 +65,6 @@
4865
</exclusion>
4966
</exclusions>
5067
</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>
6768
<dependency>
6869
<groupId>net.sourceforge.pmd</groupId>
6970
<artifactId>pmd-test</artifactId>
@@ -97,17 +98,18 @@
9798
<artifactId>maven-dependency-plugin</artifactId>
9899
<version>3.6.0</version>
99100
</plugin>
100-
<plugin>
101-
<groupId>org.cyclonedx</groupId>
102-
<artifactId>cyclonedx-maven-plugin</artifactId>
103-
<version>2.7.6</version>
104-
</plugin>
105101
</plugins>
106102
</pluginManagement>
107103
<plugins>
104+
<!-- Optional: -->
105+
<!--
108106
<plugin>
109107
<groupId>org.cyclonedx</groupId>
110108
<artifactId>cyclonedx-maven-plugin</artifactId>
109+
<version>2.7.11</version>
110+
<configuration>
111+
<outputName>pmd-${project.version}-cyclonedx</outputName>
112+
</configuration>
111113
<executions>
112114
<execution>
113115
<phase>package</phase>
@@ -116,15 +118,8 @@
116118
</goals>
117119
</execution>
118120
</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>
127121
</plugin>
122+
-->
128123
</plugins>
129124
</build>
130125

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclaratorId;
1111
import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule;
1212
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
13+
import net.sourceforge.pmd.properties.NumericConstraints;
1314
import net.sourceforge.pmd.properties.PropertyDescriptor;
1415
import net.sourceforge.pmd.properties.PropertyFactory;
15-
import net.sourceforge.pmd.properties.constraints.NumericConstraints;
1616

1717
public class ShortVariableRule extends AbstractPLSQLRule {
1818

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Rule set which defines VariableNamingRule
1212
<rule name="VariableNaming"
1313
language="plsql"
1414
message="Variables should be all lowercase"
15-
class="net.sourceforge.pmd.lang.rule.XPathRule">
15+
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
1616
<description>
1717
Variables should be all lowercase.
1818
</description>
@@ -25,7 +25,6 @@ Variables should be all lowercase.
2525
]]>
2626
</value>
2727
</property>
28-
<property name="version" value="2.0" />
2928
<property name="pattern" type="Regex" value="^[a-z_]+$" description="Pattern for valid variable names"/>
3029
</properties>
3130
<example>

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@
101101
<groupId>net.sourceforge.pmd</groupId>
102102
<artifactId>pmd-cli</artifactId>
103103
</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>
111104
</dependencies>
112105

113106
</project>

custom-rules/maven-plsql/pom.xml

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@
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>7.0.0-rc3</pmd.version>
18-
<pmd.ui.version>7.0.0-rc1</pmd.ui.version>
17+
<pmd.version>7.0.0-SNAPSHOT</pmd.version>
18+
<pmd.ui.version>7.0.0-SNAPSHOT</pmd.ui.version>
1919
</properties>
2020

21+
<repositories>
22+
<repository>
23+
<id>oss-snapshots</id>
24+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
25+
<releases><enabled>false</enabled></releases>
26+
<snapshots><enabled>true</enabled></snapshots>
27+
</repository>
28+
</repositories>
29+
<pluginRepositories>
30+
<pluginRepository>
31+
<id>oss-snapshots</id>
32+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
33+
<releases><enabled>false</enabled></releases>
34+
<snapshots><enabled>true</enabled></snapshots>
35+
</pluginRepository>
36+
</pluginRepositories>
37+
2138
<dependencyManagement>
2239
<dependencies>
2340
<dependency>
@@ -41,15 +58,6 @@
4158
<version>${pmd.version}</version>
4259
<scope>runtime</scope>
4360
</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>
5361
<dependency>
5462
<groupId>net.sourceforge.pmd</groupId>
5563
<artifactId>pmd-test</artifactId>
@@ -83,17 +91,19 @@
8391
<artifactId>maven-dependency-plugin</artifactId>
8492
<version>3.6.0</version>
8593
</plugin>
86-
<plugin>
87-
<groupId>org.cyclonedx</groupId>
88-
<artifactId>cyclonedx-maven-plugin</artifactId>
89-
<version>2.7.6</version>
90-
</plugin>
9194
</plugins>
9295
</pluginManagement>
9396
<plugins>
97+
<!-- Optional: -->
98+
<!-- Optional: -->
99+
<!--
94100
<plugin>
95101
<groupId>org.cyclonedx</groupId>
96102
<artifactId>cyclonedx-maven-plugin</artifactId>
103+
<version>2.7.11</version>
104+
<configuration>
105+
<outputName>pmd-${project.version}-cyclonedx</outputName>
106+
</configuration>
97107
<executions>
98108
<execution>
99109
<phase>package</phase>
@@ -102,15 +112,8 @@
102112
</goals>
103113
</execution>
104114
</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>
113115
</plugin>
116+
-->
114117
</plugins>
115118
</build>
116119

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

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

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

99
echo
1010
echo "======================================================="
@@ -22,7 +22,11 @@ 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-dist-${PMD_VERSION}-bin.zip -O ${BASEDIR}/code/pmd-dist-${PMD_VERSION}-bin.zip
25+
if [[ "${PMD_VERSION}" == *-SNAPSHOT ]]; then
26+
wget --no-verbose https://sourceforge.net/projects/pmd/files/pmd/${PMD_VERSION}/pmd-dist-${PMD_VERSION}-bin.zip/download -O ${BASEDIR}/code/pmd-dist-${PMD_VERSION}-bin.zip
27+
else
28+
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
29+
fi
2630
unzip -q -d ${BASEDIR}/code ${BASEDIR}/code/pmd-dist-${PMD_VERSION}-bin.zip
2731
echo "PMD ${PMD_VERSION} installed at: ${PMD_HOME}"
2832
else

custom-rules/plain-java/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ Just with `javac` and `jar`.
1111

1212
For the following steps, it is assumed, you are in that directory.
1313

14-
2. Get the binary distribution of PMD from <https://github.com/pmd/pmd/releases>, e.g. pmd-dist-7.0.0-rc3-bin.zip:
14+
2. Get the binary distribution of PMD from <https://github.com/pmd/pmd/releases>, e.g. pmd-dist-7.0.0-bin.zip:
1515

16-
$ wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.0.0-rc3/pmd-dist-7.0.0-rc3-bin.zip
16+
$ wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.0.0/pmd-dist-7.0.0-bin.zip
1717

18-
3. Extract the zip file, e.g. `unzip pmd-dist-7.0.0-rc3-bin.zip`
18+
3. Extract the zip file, e.g. `unzip pmd-dist-7.0.0-bin.zip`
1919

20-
$ unzip pmd-dist-7.0.0-rc3-bin.zip
20+
$ unzip pmd-dist-7.0.0-bin.zip
2121

22-
4. Now, the pmd binaries are installed under `~/code/pmd-bin-7.0.0-rc3`.
22+
4. Now, the pmd binaries are installed under `~/code/pmd-bin-7.0.0`.
2323

24-
This also includes the libraries in `~/code/pmd-bin-7.0.0-rc3/lib`.
24+
This also includes the libraries in `~/code/pmd-bin-7.0.0/lib`.
2525

2626
## Get the code from this example and build it
2727

@@ -37,7 +37,7 @@ Just with `javac` and `jar`.
3737

3838
3. Compile the sources, that are located in `src`, using the PMD libraries
3939

40-
$ javac -d build -cp '../../../pmd-bin-7.0.0-rc3/lib/*' src/*.java
40+
$ javac -d build -cp '../../../pmd-bin-7.0.0/lib/*' src/*.java
4141

4242
4. Create a jar file
4343

@@ -48,5 +48,5 @@ Just with `javac` and `jar`.
4848

4949
1. Run PMD with the just created jar file on the classpath, e.g. on the folder `testsrc`
5050

51-
$ CLASSPATH=custom-rule-example.jar ../../pmd-bin-7.0.0-rc3/bin/pmd check --no-cache -f text -d testsrc -R myrule.xml
51+
$ CLASSPATH=custom-rule-example.jar ../../pmd-bin-7.0.0/bin/pmd check --no-cache -f text -d testsrc -R myrule.xml
5252
/home/andreas/code/pmd-examples/testsrc/Test.java:2: Avoid the identifier foo.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
1+
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
22
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
33

44
public class MyRule extends AbstractJavaRule {
55

66
@Override
7-
public Object visit(ASTVariableDeclaratorId node, Object data) {
7+
public Object visit(ASTVariableId node, Object data) {
88
if ("foo".equals(node.getName())) {
99
asCtx(data).addViolationWithMessage(node, "Avoid the identifier 'foo'.");
1010
}

0 commit comments

Comments
 (0)