Return-Path: Delivered-To: apmail-maven-commits-archive@www.apache.org Received: (qmail 82462 invoked from network); 8 Apr 2006 09:30:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Apr 2006 09:30:31 -0000 Received: (qmail 85651 invoked by uid 500); 8 Apr 2006 09:30:30 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 85375 invoked by uid 500); 8 Apr 2006 09:30:29 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 85364 invoked by uid 99); 8 Apr 2006 09:30:29 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Apr 2006 02:30:29 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 08 Apr 2006 02:30:28 -0700 Received: (qmail 81786 invoked by uid 65534); 8 Apr 2006 09:30:07 -0000 Message-ID: <20060408093007.81780.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r392502 - in /maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd: AbstractPmdViolationCheckMojo.java CpdReport.java Date: Sat, 08 Apr 2006 09:30:06 -0000 To: commits@maven.apache.org From: brett@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 Brett Porter */ @@ -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();