You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2009/07/10 09:05:14 UTC

svn commit: r792819 - /maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java

Author: dennisl
Date: Fri Jul 10 07:05:14 2009
New Revision: 792819

URL: http://svn.apache.org/viewvc?rev=792819&view=rev
Log:
[MCHECKSTYLE-113] Set the number of accepted violations for checkstyle:check
Submitted by: Enno
Reviewed by: Dennis Lundberg

o Partially applied. I did not add the documentation, because it wasn't complete.

Modified:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java?rev=792819&r1=792818&r2=792819&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java Fri Jul 10 07:05:14 2009
@@ -73,6 +73,15 @@
     private boolean failOnViolation;
 
     /**
+     * The number of allowed violations. The execution fails only if the number
+     * of violations is above this limit.
+     *
+     * @parameter expression="${checkstyle.allowedViolations}" default-value="0"
+     * @since 2.3
+     */
+    private int allowedViolations = 0;
+
+    /**
      * The lowest severity level that is considered a violation.
      * Valid values are "error", "warning" and "info".
      *
@@ -127,12 +136,17 @@
                 xpp.setInput( breader );
 
                 int violations = countViolations( xpp );
-                if ( violations > 0 )
+                if ( violations > allowedViolations )
                 {
                     if ( failOnViolation )
                     {
-                        throw new MojoFailureException( "You have " + violations + " Checkstyle violation"
-                            + ( ( violations > 1 ) ? "s" : "" ) + "." );
+                        String msg = "You have " + violations + " Checkstyle violation"
+                            + ( ( violations > 1 ) ? "s" : "" ) + ".";
+                        if ( allowedViolations > 0 )
+                        {
+                            msg += " The number of allowed violations is " + allowedViolations + ".";
+                        }
+                        throw new MojoFailureException( msg );
                     }
 
                     getLog().warn( "checkstyle:check violations detected but failOnViolation set to false" );