From 45a5e545ba3f53ccbe61dc5971ee5b623fa75cf7 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 2 Sep 2021 10:13:48 +0200 Subject: [PATCH] [MPMD-322] Display when PMD/CPD is skipped --- src/main/java/org/apache/maven/plugins/pmd/CpdReport.java | 1 + .../apache/maven/plugins/pmd/CpdViolationCheckMojo.java | 7 +++++-- src/main/java/org/apache/maven/plugins/pmd/PmdReport.java | 1 + .../apache/maven/plugins/pmd/PmdViolationCheckMojo.java | 7 +++++-- .../java/org/apache/maven/plugins/pmd/PmdReportTest.java | 4 ++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java index 20277f9b..1af30da6 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java @@ -170,6 +170,7 @@ public boolean canGenerateReport() { if ( skip ) { + getLog().info( "Skipping CPD execution" ); return false; } diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojo.java b/src/main/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojo.java index 1175dfbc..56bd004b 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojo.java +++ b/src/main/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojo.java @@ -75,10 +75,13 @@ public CpdViolationCheckMojo() public void execute() throws MojoExecutionException, MojoFailureException { - if ( !skip ) + if ( skip ) { - executeCheck( "cpd.xml", "duplication", "CPD duplication", 10 ); + getLog().info( "Skipping CPD execution" ); + return; } + + executeCheck( "cpd.xml", "duplication", "CPD duplication", 10 ); } /** diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java index 12c029bf..6becd509 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java @@ -315,6 +315,7 @@ public boolean canGenerateReport() { if ( skip ) { + getLog().info( "Skipping PMD execution" ); return false; } diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojo.java b/src/main/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojo.java index c4bc9a69..3f6200e6 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojo.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojo.java @@ -84,10 +84,13 @@ public PmdViolationCheckMojo() public void execute() throws MojoExecutionException, MojoFailureException { - if ( !skip ) + if ( skip ) { - executeCheck( "pmd.xml", "violation", "PMD violation", failurePriority ); + getLog().info( "Skipping PMD execution" ); + return; } + + executeCheck( "pmd.xml", "violation", "PMD violation", failurePriority ); } /** diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java index 5420ba65..f8e46835 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java @@ -365,6 +365,10 @@ public void testSkipConfiguration() generatedFile = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/pmd.html" ); assertFalse( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + + // the fact, the PMD execution has been skipped, should be logged + String output = CapturingPrintStream.getOutput(); + assertTrue ( output.contains( "Skipping PMD execution" ) ); } public void testSkipEmptyReportConfiguration()