Skip to content

Commit

Permalink
[MPMD-391] Log what developers care about and not what they don't
Browse files Browse the repository at this point in the history
* Don't log PMD/CPD version for report mojos since report output will
  contain it anyway.
* Log PMD/CPD failures and warnings at WARNING level to draw attention.
* Don't log PMD/CPD version for check mojos by default.
* Integrate PMD/CPD version into failure message only.

This closes #156
  • Loading branch information
michael-o committed Jul 9, 2024
1 parent 7a3b2c2 commit 277a725
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 113 deletions.
13 changes: 10 additions & 3 deletions src/it/MPMD-163/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

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

import groovy.xml.XmlSlurper

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()

assert 1 == buildLog.getText().count('You have 1 warning')
assert 1 == buildLog.getText().count("PMD Warning: Foo:23 Rule:UnusedFormalParameter Priority:3 Avoid unused constructor parameters such as 'foo'..")
File pmdXml = new File( basedir, "target/pmd.xml" )
assert pmdXml.exists()

def pmd = new XmlSlurper().parse( pmdXml )
def version = pmd.@version

assert buildLog.getText().contains('[WARNING] PMD ' + version + ' has issued 1 warning. For more details see:')
assert buildLog.getText().contains("[WARNING] PMD Warning: Foo:23 Rule:UnusedFormalParameter Priority:3 Avoid unused constructor parameters such as 'foo'..")
2 changes: 1 addition & 1 deletion src/it/MPMD-205-pmd-js-check/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()

assert buildLog.getText().contains("[INFO] PMD Failure: PmdJsCheck.js:23 Rule:GlobalVariable Priority:1 Avoid using global variables.");
assert buildLog.getText().contains("[WARNING] PMD Failure: PmdJsCheck.js:23 Rule:GlobalVariable Priority:1 Avoid using global variables.");
1 change: 0 additions & 1 deletion src/it/MPMD-243-excludeFromFailureFile/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
# under the License.

invoker.goals = clean pmd:check
invoker.maven.version = 3+
13 changes: 11 additions & 2 deletions src/it/MPMD-243-excludeFromFailureFile/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
* under the License.
*/

import groovy.xml.XmlSlurper

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "PMD Warning: com.example.ClassWithLotsOfStaticImports" )
assert buildLog.text.contains( "You have 1 warning. For more details see" )

File pmdXml = new File( basedir, "target/pmd.xml" )
assert pmdXml.exists()

def pmd = new XmlSlurper().parse( pmdXml )
def version = pmd.@version

assert buildLog.text.contains( "[WARNING] PMD Warning: com.example.ClassWithLotsOfStaticImports" )
assert buildLog.text.contains( "[WARNING] PMD " + version + " has issued 1 warning. For more details see:" )
3 changes: 1 addition & 2 deletions src/it/MPMD-270-325-JDK11/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
3 changes: 1 addition & 2 deletions src/it/MPMD-280-JDK12/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
2 changes: 0 additions & 2 deletions src/it/MPMD-290-cpd-for-csharp/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.

invoker.maven.version = 3.3+
invoker.goals = clean verify
invoker.buildResult = failure
invoker.debug = true
12 changes: 8 additions & 4 deletions src/it/MPMD-290-cpd-for-csharp/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

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

import groovy.xml.XmlSlurper

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()

assert buildLog.text.contains( "[INFO] CPD Failure: Found 7 lines of duplicated code at locations" )
assert buildLog.text.contains( "[DEBUG] PMD failureCount: 1, warningCount: 0" )

File cpdXml = new File( basedir, 'target/cpd.xml' )
assert cpdXml.exists()

def cpd = new XmlSlurper().parse( cpdXml )
def pmdVersion = cpd.@pmdVersion

assert buildLog.text.contains( "[WARNING] CPD Failure: Found 7 lines of duplicated code at locations" )
assert buildLog.text.contains( "CPD " + pmdVersion + " has found 1 duplication. For more details see:" )

// no duplication for the license header - if this is reported, then CPD uses the wrong language/tokenizer
assert !cpdXml.text.contains( '<duplication lines="20" tokens="148">' )
assert !cpdXml.text.contains( 'line="1"' )
Expand Down
3 changes: 1 addition & 2 deletions src/it/MPMD-295-JDK13/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
3 changes: 1 addition & 2 deletions src/it/MPMD-302-JDK14/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
3 changes: 1 addition & 2 deletions src/it/MPMD-302-JDK15/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
2 changes: 0 additions & 2 deletions src/it/MPMD-304-toolchain-support/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.

invoker.java.version = 1.7+

# available toolchains under linux:
# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml
# https://github.com/apache/infrastructure-puppet/blob/deployment/modules/build_slaves/files/toolchains.xml
Expand Down
36 changes: 23 additions & 13 deletions src/it/MPMD-304-toolchain-support/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

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

import groovy.xml.XmlSlurper

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()

File pmdXml = new File( basedir, "target/pmd.xml" )
assert pmdXml.exists()

def pmd = new XmlSlurper().parse( pmdXml )
def version = pmd.@version

File cpdXml = new File( basedir, 'target/cpd.xml' )
assert cpdXml.exists()

def cpd = new XmlSlurper().parse( cpdXml )
def pmdVersion = cpd.@pmdVersion

assert buildLog.text.contains( '[INFO] Toolchain in maven-pmd-plugin: JDK[' )
assert buildLog.text.contains( '[INFO] PMD Failure: sample.Sample:24 Rule:ExtendsObject' )
assert buildLog.text.contains( '[INFO] PMD Failure: sample.Sample:36 Rule:DontCallThreadRun' )
assert buildLog.text.contains( '[INFO] You have 2 PMD violations.' )
assert buildLog.text.contains( '[INFO] You have 1 CPD duplication' )
assert buildLog.text.contains( '[WARNING] PMD Failure: sample.Sample:24 Rule:ExtendsObject' )
assert buildLog.text.contains( '[WARNING] PMD Failure: sample.Sample:36 Rule:DontCallThreadRun' )

assert buildLog.text.contains('[WARNING] PMD ' + version + ' has found 2 violations. For more details see:')
assert buildLog.text.contains('[WARNING] CPD ' + pmdVersion + ' has found 1 duplication. For more details see:')

File pmdReport = new File( basedir, 'target/pmd.xml' )
assert pmdReport.exists()
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"' )
assert pmdXml.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="35" rule="ExtendsObject"' )
assert pmdXml.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()
assert pmdSite.text.contains( 'Sample.java' )
assert pmdSite.text.contains( 'ExtendsObject' )
assert pmdSite.text.contains( 'DontCallThreadRun' )

File cpdReport = new File( basedir, 'target/cpd.xml' )
assert cpdReport.exists()
assert cpdReport.text.contains( 'Name.java' )
assert cpdReport.text.contains( 'Name2.java' )
assert cpdXml.text.contains( 'Name.java' )
assert cpdXml.text.contains( 'Name2.java' )

File cpdSite = new File( basedir, 'target/site/cpd.html' )
assert cpdSite.exists()
Expand Down
3 changes: 1 addition & 2 deletions src/it/MPMD-312-JDK16/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
3 changes: 1 addition & 2 deletions src/it/MPMD-312-JDK17/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
3 changes: 1 addition & 2 deletions src/it/MPMD-332-JDK18/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
2 changes: 0 additions & 2 deletions src/it/MPMD-348-JDK19/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.

invoker.java.version = 1.8+

# available toolchains under linux:
# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml
# https://github.com/apache/infrastructure-puppet/blob/deployment/modules/build_slaves/files/toolchains.xml
Expand Down
3 changes: 1 addition & 2 deletions src/it/MPMD-348-JDK19/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
3 changes: 1 addition & 2 deletions src/it/MPMD-365-JDK20/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# specific language governing permissions and limitations
# under the License.

invoker.java.version = 1.8+

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

# the jdk toolchain "20:openjdk" is selected in pom.xml
invoker.toolchain.jdk.version = 20
Expand Down
3 changes: 1 addition & 2 deletions src/it/MPMD-365-JDK20/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
1 change: 1 addition & 0 deletions src/it/MPMD-379-JDK21/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

# the jdk toolchain "21" is selected in pom.xml
invoker.toolchain.jdk.version = 21
Expand Down
3 changes: 1 addition & 2 deletions src/it/MPMD-379-JDK21/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

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' )
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )
44 changes: 36 additions & 8 deletions src/it/mpmd-138/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

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

import groovy.xml.XmlSlurper

File buildLog = new File( basedir, 'build.log' )
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 Unnecessary return statement')
assert 1 == buildLog.getText().count('[INFO] You have 2 PMD violations. For more details see:')
File pmdXml = new File( basedir, "mod-1/target/pmd.xml" )
assert pmdXml.exists()

def pmd = new XmlSlurper().parse( pmdXml )
def version = pmd.@version

assert buildLog.getText().contains('[WARNING] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon')
assert buildLog.getText().contains('[WARNING] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Unnecessary return statement')
assert buildLog.getText().contains('[WARNING] PMD ' + version + ' has found 2 violations. For more details see:')

// Module 2
assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'')
assert 1 == buildLog.getText().count('[INFO] You have 1 PMD violation. For more details see:')
pmdXml = new File( basedir, "mod-2/target/pmd.xml" )
assert pmdXml.exists()

pmd = new XmlSlurper().parse( pmdXml )
version = pmd.@version

assert buildLog.getText().contains('[WARNING] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'')
assert buildLog.getText().contains('[WARNING] PMD ' + version + ' has found 1 violation. For more details see:')

// Module 3
assert 1 == buildLog.getText().count('[INFO] You have 1 CPD duplication. For more details see:')
File cpdXml = new File( basedir, "mod-3/target/cpd.xml" )
assert cpdXml.exists()

def cpd = new XmlSlurper().parse( cpdXml )
def pmdVersion = cpd.@pmdVersion

assert buildLog.getText().contains('[WARNING] CPD Failure: Found 37 lines of duplicated code at locations:')
assert buildLog.getText().contains('[WARNING] CPD ' + pmdVersion + ' has found 1 duplication. For more details see:')

// Module 4
assert 1 == buildLog.getText().count('[INFO] You have 2 CPD duplications. For more details see:')
cpdXml = new File( basedir, "mod-4/target/cpd.xml" )
assert cpdXml.exists()

cpd = new XmlSlurper().parse( cpdXml )
pmdVersion = cpd.@pmdVersion

assert buildLog.getText().contains('[WARNING] CPD Failure: Found 35 lines of duplicated code at locations:')
assert buildLog.getText().contains('[WARNING] CPD Failure: Found 34 lines of duplicated code at locations:')
assert buildLog.getText().contains('[WARNING] CPD ' + pmdVersion + ' has found 2 duplications. For more details see:')
Loading

0 comments on commit 277a725

Please sign in to comment.