Skip to content

Commit 277a725

Browse files
committed
[MPMD-391] Log what developers care about and not what they don't
* 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
1 parent 7a3b2c2 commit 277a725

File tree

31 files changed

+144
-113
lines changed

31 files changed

+144
-113
lines changed

src/it/MPMD-163/verify.groovy

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Licensed to the Apache Software Foundation (ASF) under one
43
* or more contributor license agreements. See the NOTICE file
@@ -18,8 +17,16 @@
1817
* under the License.
1918
*/
2019

20+
import groovy.xml.XmlSlurper
21+
2122
File buildLog = new File( basedir, 'build.log' )
2223
assert buildLog.exists()
2324

24-
assert 1 == buildLog.getText().count('You have 1 warning')
25-
assert 1 == buildLog.getText().count("PMD Warning: Foo:23 Rule:UnusedFormalParameter Priority:3 Avoid unused constructor parameters such as 'foo'..")
25+
File pmdXml = new File( basedir, "target/pmd.xml" )
26+
assert pmdXml.exists()
27+
28+
def pmd = new XmlSlurper().parse( pmdXml )
29+
def version = pmd.@version
30+
31+
assert buildLog.getText().contains('[WARNING] PMD ' + version + ' has issued 1 warning. For more details see:')
32+
assert buildLog.getText().contains("[WARNING] PMD Warning: Foo:23 Rule:UnusedFormalParameter Priority:3 Avoid unused constructor parameters such as 'foo'..")

src/it/MPMD-205-pmd-js-check/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
File buildLog = new File( basedir, 'build.log' )
2121
assert buildLog.exists()
2222

23-
assert buildLog.getText().contains("[INFO] PMD Failure: PmdJsCheck.js:23 Rule:GlobalVariable Priority:1 Avoid using global variables.");
23+
assert buildLog.getText().contains("[WARNING] PMD Failure: PmdJsCheck.js:23 Rule:GlobalVariable Priority:1 Avoid using global variables.");

src/it/MPMD-243-excludeFromFailureFile/invoker.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@
1616
# under the License.
1717

1818
invoker.goals = clean pmd:check
19-
invoker.maven.version = 3+

src/it/MPMD-243-excludeFromFailureFile/verify.groovy

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
* under the License.
1818
*/
1919

20+
import groovy.xml.XmlSlurper
21+
2022
File buildLog = new File( basedir, 'build.log' )
2123
assert buildLog.exists()
22-
assert buildLog.text.contains( "PMD Warning: com.example.ClassWithLotsOfStaticImports" )
23-
assert buildLog.text.contains( "You have 1 warning. For more details see" )
24+
25+
File pmdXml = new File( basedir, "target/pmd.xml" )
26+
assert pmdXml.exists()
27+
28+
def pmd = new XmlSlurper().parse( pmdXml )
29+
def version = pmd.@version
30+
31+
assert buildLog.text.contains( "[WARNING] PMD Warning: com.example.ClassWithLotsOfStaticImports" )
32+
assert buildLog.text.contains( "[WARNING] PMD " + version + " has issued 1 warning. For more details see:" )

src/it/MPMD-270-325-JDK11/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-280-JDK12/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-290-cpd-for-csharp/invoker.properties

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

18-
invoker.maven.version = 3.3+
1918
invoker.goals = clean verify
2019
invoker.buildResult = failure
21-
invoker.debug = true

src/it/MPMD-290-cpd-for-csharp/verify.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Licensed to the Apache Software Foundation (ASF) under one
43
* or more contributor license agreements. See the NOTICE file
@@ -18,15 +17,20 @@
1817
* under the License.
1918
*/
2019

20+
import groovy.xml.XmlSlurper
21+
2122
File buildLog = new File( basedir, 'build.log' )
2223
assert buildLog.exists()
2324

24-
assert buildLog.text.contains( "[INFO] CPD Failure: Found 7 lines of duplicated code at locations" )
25-
assert buildLog.text.contains( "[DEBUG] PMD failureCount: 1, warningCount: 0" )
26-
2725
File cpdXml = new File( basedir, 'target/cpd.xml' )
2826
assert cpdXml.exists()
2927

28+
def cpd = new XmlSlurper().parse( cpdXml )
29+
def pmdVersion = cpd.@pmdVersion
30+
31+
assert buildLog.text.contains( "[WARNING] CPD Failure: Found 7 lines of duplicated code at locations" )
32+
assert buildLog.text.contains( "CPD " + pmdVersion + " has found 1 duplication. For more details see:" )
33+
3034
// no duplication for the license header - if this is reported, then CPD uses the wrong language/tokenizer
3135
assert !cpdXml.text.contains( '<duplication lines="20" tokens="148">' )
3236
assert !cpdXml.text.contains( 'line="1"' )

src/it/MPMD-295-JDK13/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-302-JDK14/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-302-JDK15/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-304-toolchain-support/invoker.properties

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

18-
invoker.java.version = 1.7+
19-
2018
# available toolchains under linux:
2119
# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml
2220
# https://github.com/apache/infrastructure-puppet/blob/deployment/modules/build_slaves/files/toolchains.xml

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Licensed to the Apache Software Foundation (ASF) under one
43
* or more contributor license agreements. See the NOTICE file
@@ -18,30 +17,41 @@
1817
* under the License.
1918
*/
2019

20+
import groovy.xml.XmlSlurper
21+
2122
File buildLog = new File( basedir, 'build.log' )
2223
assert buildLog.exists()
2324

25+
File pmdXml = new File( basedir, "target/pmd.xml" )
26+
assert pmdXml.exists()
27+
28+
def pmd = new XmlSlurper().parse( pmdXml )
29+
def version = pmd.@version
30+
31+
File cpdXml = new File( basedir, 'target/cpd.xml' )
32+
assert cpdXml.exists()
33+
34+
def cpd = new XmlSlurper().parse( cpdXml )
35+
def pmdVersion = cpd.@pmdVersion
36+
2437
assert buildLog.text.contains( '[INFO] Toolchain in maven-pmd-plugin: JDK[' )
25-
assert buildLog.text.contains( '[INFO] PMD Failure: sample.Sample:24 Rule:ExtendsObject' )
26-
assert buildLog.text.contains( '[INFO] PMD Failure: sample.Sample:36 Rule:DontCallThreadRun' )
27-
assert buildLog.text.contains( '[INFO] You have 2 PMD violations.' )
28-
assert buildLog.text.contains( '[INFO] You have 1 CPD duplication' )
38+
assert buildLog.text.contains( '[WARNING] PMD Failure: sample.Sample:24 Rule:ExtendsObject' )
39+
assert buildLog.text.contains( '[WARNING] PMD Failure: sample.Sample:36 Rule:DontCallThreadRun' )
40+
41+
assert buildLog.text.contains('[WARNING] PMD ' + version + ' has found 2 violations. For more details see:')
42+
assert buildLog.text.contains('[WARNING] CPD ' + pmdVersion + ' has found 1 duplication. For more details see:')
2943

30-
File pmdReport = new File( basedir, 'target/pmd.xml' )
31-
assert pmdReport.exists()
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"' )
44+
assert pmdXml.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="35" rule="ExtendsObject"' )
45+
assert pmdXml.text.contains( '<violation beginline="36" endline="36" begincolumn="9" endcolumn="32" rule="DontCallThreadRun"' )
3446

3547
File pmdSite = new File( basedir, 'target/site/pmd.html' )
3648
assert pmdSite.exists()
3749
assert pmdSite.text.contains( 'Sample.java' )
3850
assert pmdSite.text.contains( 'ExtendsObject' )
3951
assert pmdSite.text.contains( 'DontCallThreadRun' )
4052

41-
File cpdReport = new File( basedir, 'target/cpd.xml' )
42-
assert cpdReport.exists()
43-
assert cpdReport.text.contains( 'Name.java' )
44-
assert cpdReport.text.contains( 'Name2.java' )
53+
assert cpdXml.text.contains( 'Name.java' )
54+
assert cpdXml.text.contains( 'Name2.java' )
4555

4656
File cpdSite = new File( basedir, 'target/site/cpd.html' )
4757
assert cpdSite.exists()

src/it/MPMD-312-JDK16/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-312-JDK17/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-332-JDK18/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-348-JDK19/invoker.properties

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

18-
invoker.java.version = 1.8+
19-
2018
# available toolchains under linux:
2119
# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml
2220
# https://github.com/apache/infrastructure-puppet/blob/deployment/modules/build_slaves/files/toolchains.xml

src/it/MPMD-348-JDK19/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-365-JDK20/invoker.properties

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

18-
invoker.java.version = 1.8+
19-
2018
# available toolchains under linux:
2119
# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml
20+
# https://github.com/apache/infrastructure-puppet/blob/deployment/modules/build_slaves/files/toolchains.xml
2221

2322
# the jdk toolchain "20:openjdk" is selected in pom.xml
2423
invoker.toolchain.jdk.version = 20

src/it/MPMD-365-JDK20/verify.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/MPMD-379-JDK21/invoker.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

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

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020

2121
File buildLog = new File( basedir, 'build.log' )
2222
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' )
23+
assert buildLog.text.contains( '[WARNING] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' )

src/it/mpmd-138/verify.groovy

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Licensed to the Apache Software Foundation (ASF) under one
43
* or more contributor license agreements. See the NOTICE file
@@ -18,20 +17,49 @@
1817
* under the License.
1918
*/
2019

20+
import groovy.xml.XmlSlurper
21+
2122
File buildLog = new File( basedir, 'build.log' )
2223
assert buildLog.exists()
2324

2425
// Module 1
25-
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 Unnecessary return statement')
27-
assert 1 == buildLog.getText().count('[INFO] You have 2 PMD violations. For more details see:')
26+
File pmdXml = new File( basedir, "mod-1/target/pmd.xml" )
27+
assert pmdXml.exists()
28+
29+
def pmd = new XmlSlurper().parse( pmdXml )
30+
def version = pmd.@version
31+
32+
assert buildLog.getText().contains('[WARNING] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon')
33+
assert buildLog.getText().contains('[WARNING] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Unnecessary return statement')
34+
assert buildLog.getText().contains('[WARNING] PMD ' + version + ' has found 2 violations. For more details see:')
2835

2936
// Module 2
30-
assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'')
31-
assert 1 == buildLog.getText().count('[INFO] You have 1 PMD violation. For more details see:')
37+
pmdXml = new File( basedir, "mod-2/target/pmd.xml" )
38+
assert pmdXml.exists()
39+
40+
pmd = new XmlSlurper().parse( pmdXml )
41+
version = pmd.@version
42+
43+
assert buildLog.getText().contains('[WARNING] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'')
44+
assert buildLog.getText().contains('[WARNING] PMD ' + version + ' has found 1 violation. For more details see:')
3245

3346
// Module 3
34-
assert 1 == buildLog.getText().count('[INFO] You have 1 CPD duplication. For more details see:')
47+
File cpdXml = new File( basedir, "mod-3/target/cpd.xml" )
48+
assert cpdXml.exists()
49+
50+
def cpd = new XmlSlurper().parse( cpdXml )
51+
def pmdVersion = cpd.@pmdVersion
52+
53+
assert buildLog.getText().contains('[WARNING] CPD Failure: Found 37 lines of duplicated code at locations:')
54+
assert buildLog.getText().contains('[WARNING] CPD ' + pmdVersion + ' has found 1 duplication. For more details see:')
3555

3656
// Module 4
37-
assert 1 == buildLog.getText().count('[INFO] You have 2 CPD duplications. For more details see:')
57+
cpdXml = new File( basedir, "mod-4/target/cpd.xml" )
58+
assert cpdXml.exists()
59+
60+
cpd = new XmlSlurper().parse( cpdXml )
61+
pmdVersion = cpd.@pmdVersion
62+
63+
assert buildLog.getText().contains('[WARNING] CPD Failure: Found 35 lines of duplicated code at locations:')
64+
assert buildLog.getText().contains('[WARNING] CPD Failure: Found 34 lines of duplicated code at locations:')
65+
assert buildLog.getText().contains('[WARNING] CPD ' + pmdVersion + ' has found 2 duplications. For more details see:')

0 commit comments

Comments
 (0)