Skip to content

Commit

Permalink
[MPMD-379] Upgrade to use PMD 7.0.0 by default (#144)
Browse files Browse the repository at this point in the history
Merged pull request #144 from mkolesnikov:feature/MPMD-379_pmd_7
  • Loading branch information
adangel committed Apr 18, 2024
2 parents a3ac53c + f884af3 commit 89a7cdb
Show file tree
Hide file tree
Showing 39 changed files with 382 additions and 302 deletions.
10 changes: 2 additions & 8 deletions pom.xml
Expand Up @@ -28,7 +28,7 @@ under the License.
</parent>

<artifactId>maven-pmd-plugin</artifactId>
<version>3.21.3-SNAPSHOT</version>
<version>3.22.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven PMD Plugin</name>
Expand Down Expand Up @@ -83,7 +83,7 @@ under the License.
<properties>
<mavenVersion>3.2.5</mavenVersion>
<javaVersion>8</javaVersion>
<pmdVersion>6.55.0</pmdVersion>
<pmdVersion>7.0.0</pmdVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion>
<doxiaVersion>1.12.0</doxiaVersion>
Expand Down Expand Up @@ -187,12 +187,6 @@ under the License.
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
<!-- Support logging of PMD through slf4j. See also MPMD-244 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4jVersion}</version>
</dependency>

<!-- doxia -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-219-pmd-processing-error/verify.groovy
Expand Up @@ -20,5 +20,5 @@
File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "PMD processing errors" )
assert buildLog.text.contains( "Error while parsing" )
assert buildLog.text.contains( "ParseException: Parse exception in file" )
assert buildLog.text.contains( "BrokenFile.java" )
2 changes: 1 addition & 1 deletion src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml
Expand Up @@ -26,5 +26,5 @@ under the License.
MPMD-243
</description>

<rule ref="rulesets/java/imports.xml/TooManyStaticImports"/>
<rule ref="category/java/codestyle.xml/TooManyStaticImports"/>
</ruleset>
61 changes: 0 additions & 61 deletions src/it/MPMD-244-logging/logging-disabled/pom.xml

This file was deleted.

1 change: 0 additions & 1 deletion src/it/MPMD-244-logging/logging-enabled/pom.xml
Expand Up @@ -45,7 +45,6 @@ under the License.
<version>@project.version@</version>
<configuration>
<skipPmdError>true</skipPmdError>
<showPmdLog>true</showPmdLog>
</configuration>
<executions>
<execution>
Expand Down
1 change: 0 additions & 1 deletion src/it/MPMD-244-logging/pom.xml
Expand Up @@ -36,7 +36,6 @@ under the License.
</properties>

<modules>
<module>logging-disabled</module>
<module>logging-enabled</module>
</modules>
</project>
15 changes: 9 additions & 6 deletions src/it/MPMD-244-logging/verify.groovy
Expand Up @@ -20,12 +20,15 @@
File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "PMD processing errors" )
assert buildLog.text.contains( "Error while parsing" )
assert buildLog.text.contains( "ParseException: Parse exception" )
assert buildLog.text.contains( "at line 24, column 5: Encountered" )

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

// logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246)
assert 1 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${disabledPath}" )
// logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging
assert 2 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${enabledPath}" )
// 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
assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in" )

// build.log contains the logging from the two PMD executions
// only one execution has logging enabled, so we expect only one log output
assert 1 == buildLog.text.count( "[DEBUG] Rules loaded from" )
// with --debug switch or -X the logging is always enabled and can't be disabled , because PMD 7 switched to slf4j
1 change: 1 addition & 0 deletions src/it/MPMD-258-multiple-executions/invoker.properties
Expand Up @@ -15,5 +15,6 @@
# specific language governing permissions and limitations
# under the License.

invoker.debug = true
invoker.goals = clean compile pmd:pmd
invoker.maven.version = 3.1.0+
2 changes: 2 additions & 0 deletions src/it/MPMD-258-multiple-executions/verify.groovy
Expand Up @@ -21,7 +21,9 @@ File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()

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

// since we are running clean pmd:pmd, the cache is always created, never updated
// note: this is only logged in debug mode by net.sourceforge.pmd.cache.FileAnalysisCache
assert 0 == buildLog.text.count( "Analysis cache updated" )
2 changes: 1 addition & 1 deletion src/it/MPMD-268-deprecated-rules/verify.groovy
Expand Up @@ -19,4 +19,4 @@

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "[WARNING] Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated" )
assert buildLog.text.contains( "Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated Rule name" )
4 changes: 2 additions & 2 deletions src/it/MPMD-304-toolchain-support/verify.groovy
Expand Up @@ -29,8 +29,8 @@ assert buildLog.text.contains( '[INFO] You have 1 CPD duplication' )

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

File pmdSite = new File( basedir, 'target/site/pmd.html' )
assert pmdSite.exists()
Expand Down
25 changes: 25 additions & 0 deletions src/it/MPMD-379-JDK21/invoker.properties
@@ -0,0 +1,25 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# available toolchains under linux:
# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml

# the jdk toolchain "21" is selected in pom.xml
invoker.toolchain.jdk.version = 21

invoker.goals = clean verify
invoker.buildResult = failure
93 changes: 93 additions & 0 deletions src/it/MPMD-379-JDK21/pom.xml
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins.pmd.it</groupId>
<artifactId>MPMD-379-JDK21</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javaVersion>21</javaVersion>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@compilerPluginVersion@</version>
<configuration>
<release>${javaVersion}</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<linkXRef>false</linkXRef>
<skipPmdError>false</skipPmdError>
<skip>false</skip>
<failOnViolation>true</failOnViolation>
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${javaVersion}</targetJdk>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
<execution>
<id>default</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>${javaVersion}</version>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -1,3 +1,5 @@
package com.mycompany.app;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -17,10 +19,7 @@
* under the License.
*/

public class BrokenFile
public class App
{

// This file has a parse error, so PMD will fail to parse it
broken!!

}
30 changes: 30 additions & 0 deletions src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/Foo.java
@@ -0,0 +1,30 @@
package com.mycompany.app;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.util.ArrayList;

public class Foo
{
public Foo( final ArrayList<String> foo )
{
}

}
24 changes: 24 additions & 0 deletions src/it/MPMD-379-JDK21/verify.groovy
@@ -0,0 +1,24 @@

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( '[INFO] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
assert !buildLog.text.contains( '[WARNING] PMD' )
2 changes: 1 addition & 1 deletion src/it/MPMD-89-232-typeresolution/src/main/pmd/ruleset.xml
Expand Up @@ -24,5 +24,5 @@ under the License.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>Custom Ruleset for test case MPMD-89 and MPMP-232</description>
<rule ref="rulesets/java/junit.xml/TestClassWithoutTestCases"/>
<rule ref="category/java/errorprone.xml/TestClassWithoutTestCases"/>
</ruleset>
4 changes: 2 additions & 2 deletions src/it/mpmd-138/verify.groovy
Expand Up @@ -23,7 +23,7 @@ assert buildLog.exists()

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

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

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

0 comments on commit 89a7cdb

Please sign in to comment.