Skip to content

Commit

Permalink
[MPMD-321] Display PMD version that is being used also for pmd:pmd and
Browse files Browse the repository at this point in the history
pmd:cpd
  • Loading branch information
adangel committed Sep 2, 2021
1 parent 251f954 commit b8fc018
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ protected void executeCheck( final String filename, final String tagName, final
final int failurePriority )
throws MojoFailureException, MojoExecutionException
{
getLog().info( "PMD version: " + AbstractPmdReport.getPmdVersion() );

if ( aggregate && !project.isExecutionRoot() )
{
return;
Expand All @@ -141,6 +139,8 @@ protected void executeCheck( final String filename, final String tagName, final

if ( outputFile.exists() )
{
getLog().info( "PMD version: " + AbstractPmdReport.getPmdVersion() );

try
{
final ViolationDetails<D> violations = getViolations( outputFile, failurePriority );
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ private void executeCpd()
request.setJavaExecutable( javaExecutable );
}

getLog().info( "PMD version: " + AbstractPmdReport.getPmdVersion() );
cpdResult = CpdExecutor.execute( request );
}
catch ( UnsupportedEncodingException e )
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ private void executePmd()
request.setJavaExecutable( javaExecutable );
}

getLog().info( "PMD version: " + AbstractPmdReport.getPmdVersion() );
pmdResult = PmdExecutor.execute( request );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public PmdViolationCheckMojo()
* Only values from 1 to 5 are valid.
*/
@Parameter( property = "pmd.failurePriority", defaultValue = "5", required = true )
private int failurePriority;
private int failurePriority = 5;

/**
* Skip the PMD checks. Most useful on the command line via "-Dpmd.skip=true".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Captures log output from simple slf4j for asserting in unit tests.
*/
class CapturingPrintStream extends PrintStream {
private final boolean quiet;
private boolean quiet;
private StringBuilder buffer = new StringBuilder();

private CapturingPrintStream( boolean quiet ) {
Expand All @@ -51,6 +51,7 @@ public static void init( boolean quiet )
if ( capture != null )
{
capture.buffer.setLength( 0 );
capture.quiet = quiet;
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public void testDefaultConfiguration()
assertTrue( lowerCaseContains( str, "App.java" ) );
assertTrue( lowerCaseContains( str, "public String dup( String str )" ) );
assertTrue( lowerCaseContains( str, "tmp = tmp + str.substring( i, i + 1);" ) );

// the version should be logged
String output = CapturingPrintStream.getOutput();
assertTrue ( output.contains( "PMD version: " + AbstractPmdReport.getPmdVersion() ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected void setUp()
throws Exception
{
super.setUp();
CapturingPrintStream.init( true );
}

public void testDefaultConfiguration()
Expand All @@ -53,7 +54,11 @@ public void testDefaultConfiguration()
}
catch ( final Exception e )
{
assertTrue( true );
// the version should be logged
String output = CapturingPrintStream.getOutput();
assertTrue ( output.contains( "PMD version: " + AbstractPmdReport.getPmdVersion() ) );

assertTrue( e.getMessage().startsWith( "You have 1 CPD duplication." ) );
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void testDefaultConfiguration()
assertFalse( output.contains( "deprecated Rule name" ) );
assertFalse( output.contains( "Discontinue using Rule name" ) );
assertFalse( output.contains( "is referenced multiple times" ) );

// the version should be logged
assertTrue ( output.contains( "PMD version: " + AbstractPmdReport.getPmdVersion() ) );
}

public void testDefaultConfigurationNotRenderRuleViolationPriority()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ protected void setUp()
throws Exception
{
super.setUp();
CapturingPrintStream.init( true );
}

public void testDefaultConfiguration()
throws Exception
{
File testPomPmd =
new File( getBasedir(),
"src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" );
final PmdReport pmdMojo = (PmdReport) lookupMojo( "pmd", testPomPmd );
pmdMojo.execute();

// clear the output from previous pmd:pmd execution
CapturingPrintStream.init( true );

try
{
final File testPom =
Expand All @@ -56,7 +66,11 @@ public void testDefaultConfiguration()
}
catch ( final Exception e )
{
assertTrue( true );
// the version should be logged
String output = CapturingPrintStream.getOutput();
assertTrue ( output.contains( "PMD version: " + AbstractPmdReport.getPmdVersion() ) );

assertTrue( e.getMessage().startsWith( "You have 8 PMD violations." ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<sourceDirectory>${basedir}/src/test/resources/unit/default-configuration</sourceDirectory>
<configuration>
<project implementation="org.apache.maven.plugins.pmd.stubs.DefaultConfigurationMavenProjectStub"/>
<targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory>
<failOnViolation>true</failOnViolation>
<language>java</language>
<sourceEncoding>UTF-8</sourceEncoding>
<printFailingErrors>true</printFailingErrors>
<!-- <failurePriority>5</failurePriority> -->
</configuration>
</plugin>
</plugins>
Expand Down

0 comments on commit b8fc018

Please sign in to comment.