You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/03/27 05:15:26 UTC

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

Author: epunzalan
Date: Sun Mar 26 19:15:22 2006
New Revision: 389010

URL: http://svn.apache.org/viewcvs?rev=389010&view=rev
Log:
PR: MCHECKSTYLE-33
Submitted by: John Allen

Applied patch to provide the ability to control whether checkstyle violations should cause a build failure.

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/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java?rev=389010&r1=389009&r2=389010&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 Sun Mar 26 19:15:22 2006
@@ -14,14 +14,9 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  */
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -29,9 +24,14 @@
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
 /**
  * Perform a violation check against the last checkstyle run to see if there are any violations.
- * 
+ *
  * @author <a href="mailto:joakim@erdfelt.net">Joakim Erdfelt</a>
  * @goal check
  * @phase verify
@@ -44,7 +44,7 @@
      * Specifies the path and filename to save the checkstyle output.  The format of the output file is
      * determined by the <code>outputFileFormat</code>
      *
-     * @parameter expression="${checkstyle.output.file}" 
+     * @parameter expression="${checkstyle.output.file}"
      *            default-value="${project.build.directory}/checkstyle-result.xml"
      */
     private File outputFile;
@@ -57,6 +57,14 @@
      */
     private String outputFileFormat;
 
+    /**
+     * do we fail the build on a violation?
+     *
+     * @parameter expression="${checkstyle.failOnViolation}" default-value="true"
+     */
+    private boolean failOnViolation;
+
+
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
@@ -83,9 +91,16 @@
             int violations = countViolations( xpp );
             if ( violations > 0 )
             {
-                throw new MojoFailureException( "You have " + violations + " checkstyle violation"
-                    + ( ( violations > 1 ) ? "s" : "" ) + "." );
-            }
+            	if ( failOnViolation )
+            	{
+            	    throw new MojoFailureException( "You have " + violations + " checkstyle violation"
+            	        + ( ( violations > 1 ) ? "s" : "" ) + "." );
+            	}
+            	else
+            	{
+	        	    getLog().warn( "checkstyle:check violations detected but failOnViolation set to false" );
+				}
+			}
         }
         catch ( IOException e )
         {