diff --git a/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java b/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
index c6cedcabb3..98e73eb74e 100644
--- a/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
+++ b/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
@@ -30,6 +30,7 @@ import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.DefaultLogger;
import com.puppycrawl.tools.checkstyle.ModuleFactory;
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
+import com.puppycrawl.tools.checkstyle.PropertiesExpander;
import com.puppycrawl.tools.checkstyle.XMLLogger;
import java.io.File;
@@ -38,6 +39,7 @@ import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
/**
* @author Emmanuel Venisse
@@ -46,33 +48,23 @@ import java.util.List;
public class CheckstyleReport
extends AbstractMavenReport
{
- protected static final String[] DEFAULT_EXCLUDES = {
- // Miscellaneous typical temporary files
- "**/*~",
- "**/#*#",
- "**/.#*",
- "**/%*%",
- "**/._*",
+ protected static final String[] DEFAULT_EXCLUDES = {// Miscellaneous typical temporary files
+ "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
// CVS
- "**/CVS",
- "**/CVS/**",
- "**/.cvsignore",
+ "**/CVS", "**/CVS/**", "**/.cvsignore",
// SCCS
- "**/SCCS",
- "**/SCCS/**",
+ "**/SCCS", "**/SCCS/**",
// Visual SourceSafe
"**/vssver.scc",
// Subversion
- "**/.svn",
- "**/.svn/**",
+ "**/.svn", "**/.svn/**",
// Mac
- "**/.DS_Store"
- };
+ "**/.DS_Store"};
private URL configFile = getClass().getResource( "/config/sun_checks.xml" );
@@ -140,8 +132,8 @@ public class CheckstyleReport
try
{
- //TODO: implements a PropertyResolver for resolve property like ${checkstyle.cache.file}
- config = ConfigurationLoader.loadConfiguration( configFile.toString(), null );
+ config = ConfigurationLoader.loadConfiguration( configFile.toString(),
+ new PropertiesExpander( createOverridingProperties() ) );
}
catch ( CheckstyleException e )
{
@@ -172,17 +164,14 @@ public class CheckstyleReport
checker.configure( config );
- FileOutputStream xmlOut = new FileOutputStream( new File( getConfiguration().getOutputDirectory(), "checkstyle-result.xml" ) );
-
- //TODO: Use a Listener with sink
- AuditListener xmlListener = new XMLLogger( xmlOut, true );
+ AuditListener sinkListener = new CheckstyleReportListener( getSink(), getConfiguration().getSourceDirectory() );
if ( listener != null )
{
checker.addListener( listener );
}
- checker.addListener( xmlListener );
+ checker.addListener( sinkListener );
}
catch ( Exception e )
{
@@ -226,4 +215,12 @@ public class CheckstyleReport
return FileUtils.getFiles( new File( getConfiguration().getSourceDirectory() ), includes, excludesStr.toString() );
}
+
+ private Properties createOverridingProperties()
+ {
+ Properties props = new Properties();
+ props.setProperty( "checkstyle.header.file", "LICENSE.txt" );
+ props.setProperty( "checkstyle.cache.file", "target/checkstyle-cachefile" );
+ return props;
+ }
}
\ No newline at end of file
diff --git a/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java b/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java
new file mode 100644
index 0000000000..288a1db71f
--- /dev/null
+++ b/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java
@@ -0,0 +1,145 @@
+package org.apache.maven.plugin.checkstyle;
+
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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 org.codehaus.doxia.sink.Sink;
+import org.codehaus.plexus.util.StringUtils;
+
+import com.puppycrawl.tools.checkstyle.api.AuditEvent;
+import com.puppycrawl.tools.checkstyle.api.AuditListener;
+import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
+import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
+
+/**
+ * @author Emmanuel Venisse
+ * @version $Id: DependenciesReport.java,v 1.2 2005/02/23 00:08:02 brett Exp $
+ */
+public class CheckstyleReportListener
+ extends AutomaticBean
+ implements AuditListener
+{
+ private static final String TITLE = "Checkstyle Results";
+
+ private Sink sink;
+
+ private String sourceDirectory;
+
+ private String currentFilename;
+
+ private boolean fileInitialized;
+
+ public CheckstyleReportListener( Sink sink, String sourceDirectory )
+ {
+ this.sink = sink;
+ this.sourceDirectory = sourceDirectory;
+ }
+
+ public void auditStarted( AuditEvent event )
+ {
+ sink.head();
+ sink.title();
+ sink.text( TITLE );
+ sink.title_();
+ sink.head_();
+
+ sink.body();
+
+ sink.section1();
+ sink.sectionTitle();
+ sink.text( TITLE );
+ sink.sectionTitle_();
+
+ sink.paragraph();
+ sink.text( "The following document contains the results of " );
+ sink.link( "http://checkstyle.sourceforge.net/" );
+ sink.text( "Checkstyle" );
+ sink.link_();
+ sink.paragraph_();
+
+ // TODO overall summary
+
+ sink.section1_();
+ sink.sectionTitle();
+ sink.text( "Files" );
+ sink.sectionTitle_();
+
+ // TODO files summary
+ }
+
+ public void auditFinished( AuditEvent event )
+ {
+ sink.section1_();
+ sink.body_();
+ }
+
+ public void fileStarted( AuditEvent event )
+ {
+ currentFilename = StringUtils.substring( event.getFileName(), sourceDirectory.length() + 1 );
+ currentFilename = StringUtils.replace( currentFilename, "\\", "/" );
+ fileInitialized = false;
+ }
+
+ public void fileFinished( AuditEvent event )
+ {
+ if ( fileInitialized )
+ {
+ sink.table_();
+ sink.section2_();
+ }
+ }
+
+ public void addError( AuditEvent event )
+ {
+ if ( !SeverityLevel.IGNORE.equals( event.getSeverityLevel() ) )
+ {
+ if ( !fileInitialized )
+ {
+ sink.section2();
+ sink.sectionTitle();
+ sink.text( currentFilename );
+ sink.sectionTitle_();
+
+ sink.table();
+ sink.tableRow();
+ sink.tableHeaderCell();
+ sink.text( "Violation" );
+ sink.tableHeaderCell_();
+ sink.tableHeaderCell();
+ sink.text( "Line" );
+ sink.tableHeaderCell_();
+ sink.tableRow_();
+
+ fileInitialized = true;
+ }
+
+ sink.tableRow();
+ sink.tableCell();
+ sink.text( event.getMessage() );
+ sink.tableCell_();
+ sink.tableCell();
+ sink.text( String.valueOf( event.getLine() ) );
+ sink.tableCell_();
+ sink.tableRow_();
+ }
+ }
+
+ public void addException( AuditEvent event, Throwable throwable )
+ {
+ //Do Nothing
+ }
+}
+