Author: nicolas Date: Mon May 18 08:48:04 2009 New Revision: 775863 URL: http://svn.apache.org/viewvc?rev=775863&view=rev Log: MCHECKSTYLE-110
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=775863&r1=775862&r2=775863&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 Mon May 18 08:48:04 2009 @@ -19,6 +19,11 @@ * under the License. */ +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.Reader; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -27,11 +32,6 @@ 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.IOException; -import java.io.Reader; - /** * 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 @@ -89,6 +89,15 @@ */ private boolean skip; + + /** + * Ouput detected violations in the console + * + * @parameter expression="${checkstyle.console}" default-value="false" + * @since 2.3 + */ + private boolean logViolationsToConsole; + /** * @see org.apache.maven.plugin.Mojo#execute() */ @@ -149,11 +158,30 @@ int count = 0; int eventType = xpp.getEventType(); + String file = ""; while ( eventType != XmlPullParser.END_DOCUMENT ) { + if ( eventType == XmlPullParser.START_TAG && "file".equals( xpp.getName() ) ) + { + file = xpp.getAttributeValue( "", "name" ); + file = file.substring( file.lastIndexOf( File.separatorChar ) + 1 ); + } + if ( eventType == XmlPullParser.START_TAG && "error".equals( xpp.getName() ) && isViolation( xpp.getAttributeValue( "", "severity" ) ) ) { + if ( logViolationsToConsole ) + { + StringBuffer stb = new StringBuffer(); + stb.append( file ); + stb.append( '[' ); + stb.append( xpp.getAttributeValue( "", "line" ) ); + stb.append( ':' ); + stb.append( xpp.getAttributeValue( "", "column" ) ); + stb.append( "] " ); + stb.append( xpp.getAttributeValue( "", "message" ) ); + getLog().error( stb.toString() ); + } count++; } eventType = xpp.next();