mirror of https://github.com/apache/maven.git
o Use sink for generate the report
o Define some default properties that use by checkstyle config file git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168671 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f1d5f829f2
commit
ecc12bd005
|
@ -30,6 +30,7 @@ import com.puppycrawl.tools.checkstyle.Checker;
|
||||||
import com.puppycrawl.tools.checkstyle.DefaultLogger;
|
import com.puppycrawl.tools.checkstyle.DefaultLogger;
|
||||||
import com.puppycrawl.tools.checkstyle.ModuleFactory;
|
import com.puppycrawl.tools.checkstyle.ModuleFactory;
|
||||||
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
|
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
|
||||||
|
import com.puppycrawl.tools.checkstyle.PropertiesExpander;
|
||||||
import com.puppycrawl.tools.checkstyle.XMLLogger;
|
import com.puppycrawl.tools.checkstyle.XMLLogger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -38,6 +39,7 @@ import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
|
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
|
||||||
|
@ -46,33 +48,23 @@ import java.util.List;
|
||||||
public class CheckstyleReport
|
public class CheckstyleReport
|
||||||
extends AbstractMavenReport
|
extends AbstractMavenReport
|
||||||
{
|
{
|
||||||
protected static final String[] DEFAULT_EXCLUDES = {
|
protected static final String[] DEFAULT_EXCLUDES = {// Miscellaneous typical temporary files
|
||||||
// Miscellaneous typical temporary files
|
"**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
|
||||||
"**/*~",
|
|
||||||
"**/#*#",
|
|
||||||
"**/.#*",
|
|
||||||
"**/%*%",
|
|
||||||
"**/._*",
|
|
||||||
|
|
||||||
// CVS
|
// CVS
|
||||||
"**/CVS",
|
"**/CVS", "**/CVS/**", "**/.cvsignore",
|
||||||
"**/CVS/**",
|
|
||||||
"**/.cvsignore",
|
|
||||||
|
|
||||||
// SCCS
|
// SCCS
|
||||||
"**/SCCS",
|
"**/SCCS", "**/SCCS/**",
|
||||||
"**/SCCS/**",
|
|
||||||
|
|
||||||
// Visual SourceSafe
|
// Visual SourceSafe
|
||||||
"**/vssver.scc",
|
"**/vssver.scc",
|
||||||
|
|
||||||
// Subversion
|
// Subversion
|
||||||
"**/.svn",
|
"**/.svn", "**/.svn/**",
|
||||||
"**/.svn/**",
|
|
||||||
|
|
||||||
// Mac
|
// Mac
|
||||||
"**/.DS_Store"
|
"**/.DS_Store"};
|
||||||
};
|
|
||||||
|
|
||||||
private URL configFile = getClass().getResource( "/config/sun_checks.xml" );
|
private URL configFile = getClass().getResource( "/config/sun_checks.xml" );
|
||||||
|
|
||||||
|
@ -140,8 +132,8 @@ public class CheckstyleReport
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//TODO: implements a PropertyResolver for resolve property like ${checkstyle.cache.file}
|
config = ConfigurationLoader.loadConfiguration( configFile.toString(),
|
||||||
config = ConfigurationLoader.loadConfiguration( configFile.toString(), null );
|
new PropertiesExpander( createOverridingProperties() ) );
|
||||||
}
|
}
|
||||||
catch ( CheckstyleException e )
|
catch ( CheckstyleException e )
|
||||||
{
|
{
|
||||||
|
@ -172,17 +164,14 @@ public class CheckstyleReport
|
||||||
|
|
||||||
checker.configure( config );
|
checker.configure( config );
|
||||||
|
|
||||||
FileOutputStream xmlOut = new FileOutputStream( new File( getConfiguration().getOutputDirectory(), "checkstyle-result.xml" ) );
|
AuditListener sinkListener = new CheckstyleReportListener( getSink(), getConfiguration().getSourceDirectory() );
|
||||||
|
|
||||||
//TODO: Use a Listener with sink
|
|
||||||
AuditListener xmlListener = new XMLLogger( xmlOut, true );
|
|
||||||
|
|
||||||
if ( listener != null )
|
if ( listener != null )
|
||||||
{
|
{
|
||||||
checker.addListener( listener );
|
checker.addListener( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
checker.addListener( xmlListener );
|
checker.addListener( sinkListener );
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
|
@ -226,4 +215,12 @@ public class CheckstyleReport
|
||||||
|
|
||||||
return FileUtils.getFiles( new File( getConfiguration().getSourceDirectory() ), includes, excludesStr.toString() );
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue