You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ni...@apache.org on 2009/05/31 12:26:12 UTC
svn commit: r780402 -
/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
Author: nicolas
Date: Sun May 31 10:26:12 2009
New Revision: 780402
URL: http://svn.apache.org/viewvc?rev=780402&view=rev
Log:
[MCHECKSTYLE-110] option to redirect checktyle violations to console for quick review
o build a log String during XML report analysis and log to console
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=780402&r1=780401&r2=780402&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 May 31 10:26:12 2009
@@ -90,6 +90,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()
*/
public void 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();