Skip to content

Commit 89a7cdb

Browse files
committed
[MPMD-379] Upgrade to use PMD 7.0.0 by default (#144)
Merged pull request #144 from mkolesnikov:feature/MPMD-379_pmd_7
2 parents a3ac53c + f884af3 commit 89a7cdb

File tree

39 files changed

+382
-302
lines changed

39 files changed

+382
-302
lines changed

pom.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ under the License.
2828
</parent>
2929

3030
<artifactId>maven-pmd-plugin</artifactId>
31-
<version>3.21.3-SNAPSHOT</version>
31+
<version>3.22.0-SNAPSHOT</version>
3232
<packaging>maven-plugin</packaging>
3333

3434
<name>Apache Maven PMD Plugin</name>
@@ -83,7 +83,7 @@ under the License.
8383
<properties>
8484
<mavenVersion>3.2.5</mavenVersion>
8585
<javaVersion>8</javaVersion>
86-
<pmdVersion>6.55.0</pmdVersion>
86+
<pmdVersion>7.0.0</pmdVersion>
8787
<slf4jVersion>1.7.36</slf4jVersion>
8888
<aetherVersion>1.0.0.v20140518</aetherVersion>
8989
<doxiaVersion>1.12.0</doxiaVersion>
@@ -187,12 +187,6 @@ under the License.
187187
<artifactId>slf4j-api</artifactId>
188188
<version>${slf4jVersion}</version>
189189
</dependency>
190-
<!-- Support logging of PMD through slf4j. See also MPMD-244 -->
191-
<dependency>
192-
<groupId>org.slf4j</groupId>
193-
<artifactId>jul-to-slf4j</artifactId>
194-
<version>${slf4jVersion}</version>
195-
</dependency>
196190

197191
<!-- doxia -->
198192
<dependency>

src/it/MPMD-219-pmd-processing-error/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
File buildLog = new File( basedir, 'build.log' )
2121
assert buildLog.exists()
2222
assert buildLog.text.contains( "PMD processing errors" )
23-
assert buildLog.text.contains( "Error while parsing" )
23+
assert buildLog.text.contains( "ParseException: Parse exception in file" )
2424
assert buildLog.text.contains( "BrokenFile.java" )

src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ under the License.
2626
MPMD-243
2727
</description>
2828

29-
<rule ref="rulesets/java/imports.xml/TooManyStaticImports"/>
29+
<rule ref="category/java/codestyle.xml/TooManyStaticImports"/>
3030
</ruleset>

src/it/MPMD-244-logging/logging-disabled/pom.xml

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/it/MPMD-244-logging/logging-enabled/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ under the License.
4545
<version>@project.version@</version>
4646
<configuration>
4747
<skipPmdError>true</skipPmdError>
48-
<showPmdLog>true</showPmdLog>
4948
</configuration>
5049
<executions>
5150
<execution>

src/it/MPMD-244-logging/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ under the License.
3636
</properties>
3737

3838
<modules>
39-
<module>logging-disabled</module>
4039
<module>logging-enabled</module>
4140
</modules>
4241
</project>

src/it/MPMD-244-logging/verify.groovy

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
File buildLog = new File( basedir, 'build.log' )
2121
assert buildLog.exists()
2222
assert buildLog.text.contains( "PMD processing errors" )
23-
assert buildLog.text.contains( "Error while parsing" )
23+
assert buildLog.text.contains( "ParseException: Parse exception" )
24+
assert buildLog.text.contains( "at line 24, column 5: Encountered" )
2425

25-
String disabledPath = new File( basedir, 'logging-disabled/src/main/java/BrokenFile.java' ).getCanonicalPath()
2626
String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFile.java' ).getCanonicalPath()
2727

28-
// logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246)
29-
assert 1 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${disabledPath}" )
30-
// logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging
31-
assert 2 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${enabledPath}" )
28+
// logging enabled: the pmd exception is still output only once: through the processing error reporting (since MPMD-246) - PMD 7 doesn't log the processing error additionally
29+
assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in" )
30+
31+
// build.log contains the logging from the two PMD executions
32+
// only one execution has logging enabled, so we expect only one log output
33+
assert 1 == buildLog.text.count( "[DEBUG] Rules loaded from" )
34+
// with --debug switch or -X the logging is always enabled and can't be disabled , because PMD 7 switched to slf4j

src/it/MPMD-258-multiple-executions/invoker.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
invoker.debug = true
1819
invoker.goals = clean compile pmd:pmd
1920
invoker.maven.version = 3.1.0+

src/it/MPMD-258-multiple-executions/verify.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ File buildLog = new File( basedir, 'build.log' )
2121
assert buildLog.exists()
2222

2323
// we have 2 modules and for each module this should be output once
24+
// note: this is only logged in debug mode by net.sourceforge.pmd.cache.FileAnalysisCache
2425
assert 2 == buildLog.text.count( "Analysis cache created" )
2526

2627
// since we are running clean pmd:pmd, the cache is always created, never updated
28+
// note: this is only logged in debug mode by net.sourceforge.pmd.cache.FileAnalysisCache
2729
assert 0 == buildLog.text.count( "Analysis cache updated" )

src/it/MPMD-268-deprecated-rules/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
File buildLog = new File( basedir, 'build.log' )
2121
assert buildLog.exists()
22-
assert buildLog.text.contains( "[WARNING] Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated" )
22+
assert buildLog.text.contains( "Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated Rule name" )

src/it/MPMD-304-toolchain-support/verify.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ assert buildLog.text.contains( '[INFO] You have 1 CPD duplication' )
2929

3030
File pmdReport = new File( basedir, 'target/pmd.xml' )
3131
assert pmdReport.exists()
32-
assert pmdReport.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="34" rule="ExtendsObject"' )
33-
assert pmdReport.text.contains( '<violation beginline="36" endline="36" begincolumn="9" endcolumn="31" rule="DontCallThreadRun"' )
32+
assert pmdReport.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="35" rule="ExtendsObject"' )
33+
assert pmdReport.text.contains( '<violation beginline="36" endline="36" begincolumn="9" endcolumn="32" rule="DontCallThreadRun"' )
3434

3535
File pmdSite = new File( basedir, 'target/site/pmd.html' )
3636
assert pmdSite.exists()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# available toolchains under linux:
19+
# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml
20+
21+
# the jdk toolchain "21" is selected in pom.xml
22+
invoker.toolchain.jdk.version = 21
23+
24+
invoker.goals = clean verify
25+
invoker.buildResult = failure

src/it/MPMD-379-JDK21/pom.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<groupId>org.apache.maven.plugins.pmd.it</groupId>
26+
<artifactId>MPMD-379-JDK21</artifactId>
27+
<version>1.0-SNAPSHOT</version>
28+
29+
<properties>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<javaVersion>21</javaVersion>
32+
</properties>
33+
34+
<build>
35+
<pluginManagement>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-compiler-plugin</artifactId>
40+
<version>@compilerPluginVersion@</version>
41+
<configuration>
42+
<release>${javaVersion}</release>
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
</pluginManagement>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-pmd-plugin</artifactId>
51+
<version>@project.version@</version>
52+
<configuration>
53+
<linkXRef>false</linkXRef>
54+
<skipPmdError>false</skipPmdError>
55+
<skip>false</skip>
56+
<failOnViolation>true</failOnViolation>
57+
<failurePriority>4</failurePriority>
58+
<printFailingErrors>true</printFailingErrors>
59+
<targetJdk>${javaVersion}</targetJdk>
60+
<minimumTokens>100</minimumTokens>
61+
</configuration>
62+
<executions>
63+
<execution>
64+
<id>default</id>
65+
<phase>verify</phase>
66+
<goals>
67+
<goal>check</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-toolchains-plugin</artifactId>
75+
<version>3.1.0</version>
76+
<executions>
77+
<execution>
78+
<goals>
79+
<goal>toolchain</goal>
80+
</goals>
81+
</execution>
82+
</executions>
83+
<configuration>
84+
<toolchains>
85+
<jdk>
86+
<version>${javaVersion}</version>
87+
</jdk>
88+
</toolchains>
89+
</configuration>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
</project>

src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java renamed to src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/App.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package com.mycompany.app;
2+
13
/*
24
* Licensed to the Apache Software Foundation (ASF) under one
35
* or more contributor license agreements. See the NOTICE file
@@ -17,10 +19,7 @@
1719
* under the License.
1820
*/
1921

20-
public class BrokenFile
22+
public class App
2123
{
2224

23-
// This file has a parse error, so PMD will fail to parse it
24-
broken!!
25-
2625
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.mycompany.app;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import java.util.ArrayList;
23+
24+
public class Foo
25+
{
26+
public Foo( final ArrayList<String> foo )
27+
{
28+
}
29+
30+
}

src/it/MPMD-379-JDK21/verify.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
File buildLog = new File( basedir, 'build.log' )
22+
assert buildLog.exists()
23+
assert buildLog.text.contains( '[INFO] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
24+
assert !buildLog.text.contains( '[WARNING] PMD' )

src/it/MPMD-89-232-typeresolution/src/main/pmd/ruleset.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ under the License.
2424
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2525
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
2626
<description>Custom Ruleset for test case MPMD-89 and MPMP-232</description>
27-
<rule ref="rulesets/java/junit.xml/TestClassWithoutTestCases"/>
27+
<rule ref="category/java/errorprone.xml/TestClassWithoutTestCases"/>
2828
</ruleset>

src/it/mpmd-138/verify.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ assert buildLog.exists()
2323

2424
// Module 1
2525
assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon')
26-
assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Avoid unnecessary return statements')
26+
assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Unnecessary return statement')
2727
assert 1 == buildLog.getText().count('[INFO] You have 2 PMD violations. For more details see:')
2828

2929
// Module 2
@@ -34,4 +34,4 @@ assert 1 == buildLog.getText().count('[INFO] You have 1 PMD violation. For more
3434
assert 1 == buildLog.getText().count('[INFO] You have 1 CPD duplication. For more details see:')
3535

3636
// Module 4
37-
assert 1 == buildLog.getText().count('[INFO] You have 2 CPD duplications. For more details see:')
37+
assert 1 == buildLog.getText().count('[INFO] You have 2 CPD duplications. For more details see:')

0 commit comments

Comments
 (0)