You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/04/08 11:30:06 UTC
svn commit: r392502 - in
/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd:
AbstractPmdViolationCheckMojo.java CpdReport.java
Author: brett
Date: Sat Apr 8 02:30:05 2006
New Revision: 392502
URL: http://svn.apache.org/viewcvs?rev=392502&view=rev
Log:
[MPMD-24] only check under the same conditions the report would be generated (java language, source directory exists). Other minor fixes included
Modified:
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java?rev=392502&r1=392501&r2=392502&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java Sat Apr 8 02:30:05 2006
@@ -13,7 +13,7 @@
import java.io.IOException;
/**
- * TODO: Description.
+ * Base class for mojos that check if there were any PMD violations.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
@@ -34,40 +34,61 @@
*/
private boolean failOnViolation;
+ /**
+ * The project language.
+ *
+ * @parameter expression="${project.artifact.artifactHandler.language}"
+ * @required
+ * @readonly
+ */
+ private String language;
+
+ /**
+ * The project source directory.
+ *
+ * @parameter expression="${project.build.sourceDirectory}"
+ * @required
+ * @readonly
+ */
+ private File sourceDirectory;
+
protected void executeCheck( String filename, String tagName )
throws MojoFailureException, MojoExecutionException
{
- File outputFile = new File( targetDirectory, filename );
- if ( outputFile.exists() )
+ if ( "java".equals( language ) && sourceDirectory.exists() )
{
- try
+ File outputFile = new File( targetDirectory, filename );
+ if ( outputFile.exists() )
{
- XmlPullParser xpp = new MXParser();
- FileReader freader = new FileReader( outputFile );
- BufferedReader breader = new BufferedReader( freader );
- xpp.setInput( breader );
+ try
+ {
+ XmlPullParser xpp = new MXParser();
+ FileReader freader = new FileReader( outputFile );
+ BufferedReader breader = new BufferedReader( freader );
+ xpp.setInput( breader );
- int violations = countViolations( xpp, tagName );
- if ( violations > 0 && failOnViolation )
+ int violations = countViolations( xpp, tagName );
+ if ( violations > 0 && failOnViolation )
+ {
+ throw new MojoFailureException(
+ "You have " + violations + " violation" + ( violations > 1 ? "s" : "" ) + "." );
+ }
+ }
+ catch ( IOException e )
{
- throw new MojoFailureException(
- "You have " + violations + " violation" + ( violations > 1 ? "s" : "" ) + "." );
+ throw new MojoExecutionException( "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
+ e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new MojoExecutionException( "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
+ e );
}
}
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
- e );
- }
- catch ( XmlPullParserException e )
+ else
{
- throw new MojoExecutionException( "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
- e );
+ throw new MojoFailureException( "Unable to perform check, " + "unable to find " + outputFile );
}
- }
- else
- {
- throw new MojoFailureException( "Unable to perform check, " + "unable to find " + outputFile );
}
}
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java?rev=392502&r1=392501&r2=392502&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java Sat Apr 8 02:30:05 2006
@@ -43,7 +43,7 @@
extends AbstractPmdReport
{
/**
- * @parameter
+ * @parameter expression="${minimumTokens}"
*/
private int minimumTokens = 100;
@@ -95,6 +95,7 @@
String buffer = r.render( cpd.getMatches() );
try
{
+ targetDirectory.mkdirs();
Writer writer = new FileWriter( new File( targetDirectory, "cpd." + format ) );
writer.write( buffer, 0, buffer.length() );
writer.close();