You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by ev...@apache.org on 2005/05/07 00:09:59 UTC

svn commit: r168671 - /maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle

Author: evenisse
Date: Fri May  6 15:09:58 2005
New Revision: 168671

URL: http://svn.apache.org/viewcvs?rev=168671&view=rev
Log:
o Use sink for generate the report
o Define some default properties that use by checkstyle config file

Added:
    maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java
Modified:
    maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java

Modified: maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java?rev=168671&r1=168670&r2=168671&view=diff
==============================================================================
--- maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java (original)
+++ maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java Fri May  6 15:09:58 2005
@@ -30,6 +30,7 @@
 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.net.URL;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -46,33 +48,23 @@
 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 @@
 
         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 @@
 
             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 )
         {
@@ -225,5 +214,13 @@
         }
 
         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;
     }
 }

Added: maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java?rev=168671&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java (added)
+++ maven/components/trunk/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java Fri May  6 15:09:58 2005
@@ -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 <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @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
+    }
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org