Author: brianf Date: Sun Mar 11 18:11:25 2007 New Revision: 517061 URL: http://svn.apache.org/viewvc?view=rev&rev=517061 Log: MCHECKSTYLE-71 - added skip flag
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?view=diff&rev=517061&r1=517060&r2=517061 ============================================================================== --- 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 11 18:11:25 2007 @@ -32,10 +32,10 @@ import java.io.IOException; /** - * Perform a violation check against the last Checkstyle run to see if there are any violations. - * It reads the Checkstyle output file, counts the number of violations found and displays it on the - * console. - * + * Perform a violation check against the last Checkstyle run to see if there are + * any violations. It reads the Checkstyle output file, counts the number of + * violations found and displays it on the console. + * * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a> * @goal check * @phase verify @@ -45,76 +45,88 @@ extends AbstractMojo { /** - * Specifies the path and filename to save the Checkstyle output. The format of the output file is - * determined by the <code>outputFileFormat</code> - * + * 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}" - * default-value="${project.build.directory}/checkstyle-result.xml" + * default-value="${project.build.directory}/checkstyle-result.xml" */ private File outputFile; /** - * Specifies the format of the output to be used when writing to the output file. Valid values are - * "plain" and "xml" - * + * Specifies the format of the output to be used when writing to the output + * file. Valid values are "plain" and "xml" + * * @parameter expression="${checkstyle.output.format}" default-value="xml" */ private String outputFileFormat; /** * do we fail the build on a violation? - * - * @parameter expression="${checkstyle.failOnViolation}" default-value="true" + * + * @parameter expression="${checkstyle.failOnViolation}" + * default-value="true" */ private boolean failOnViolation; /** + * skip entire check + * + * @parameter expression="${checkstyle.skip}" default-value="false" + */ + private boolean skip; + + /** * @see org.apache.maven.plugin.Mojo#execute() */ public void execute() throws MojoExecutionException, MojoFailureException { - if ( !"xml".equals( outputFileFormat ) ) - { - throw new MojoExecutionException( - "Output format is '" + outputFileFormat + "', checkstyle:check requires format to be 'xml'." ); - } - - if ( !outputFile.exists() ) + if ( !skip ) { - getLog().info( - "Unable to perform checkstyle:check, " + "unable to find checkstyle:checkstyle outputFile." ); - return; - } + if ( !"xml".equals( outputFileFormat ) ) + { + throw new MojoExecutionException( "Output format is '" + outputFileFormat + + "', checkstyle:check requires format to be 'xml'." ); + } - try - { - XmlPullParser xpp = new MXParser(); - FileReader freader = new FileReader( outputFile ); - BufferedReader breader = new BufferedReader( freader ); - xpp.setInput( breader ); + if ( !outputFile.exists() ) + { + getLog().info( + "Unable to perform checkstyle:check, " + + "unable to find checkstyle:checkstyle outputFile." ); + return; + } - int violations = countViolations( xpp ); - if ( violations > 0 ) + try { - if ( failOnViolation ) + XmlPullParser xpp = new MXParser(); + FileReader freader = new FileReader( outputFile ); + BufferedReader breader = new BufferedReader( freader ); + xpp.setInput( breader ); + + 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" : "" ) + "." ); + } - getLog().warn( "checkstyle:check violations detected but failOnViolation set to false" ); + getLog().warn( "checkstyle:check violations detected but failOnViolation set to false" ); + } + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Unable to read Checkstyle results xml: " + + outputFile.getAbsolutePath(), e ); + } + catch ( XmlPullParserException e ) + { + throw new MojoExecutionException( "Unable to read Checkstyle results xml: " + + outputFile.getAbsolutePath(), e ); } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Unable to read Checkstyle results xml: " + outputFile.getAbsolutePath(), - e ); - } - catch ( XmlPullParserException e ) - { - throw new MojoExecutionException( "Unable to read Checkstyle results xml: " + outputFile.getAbsolutePath(), - e ); } }