mirror of https://github.com/apache/maven.git
Corrected getConfigFile() by specifying sun as default config file; added log4j.properties to remove warn for org.apache.commons.beanutils.BeanUtils; formated code; added copyright to pom.xml
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@279769 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cbf7453e2d
commit
f4239df692
|
@ -1,4 +1,25 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>maven-plugin-parent</artifactId>
|
||||
|
@ -52,4 +73,16 @@
|
|||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>vsiveton</id>
|
||||
<name>Vincent Siveton</name>
|
||||
<email>vsiveton@apache.org</email>
|
||||
<organization>Apache Software Foundation</organization>
|
||||
<roles>
|
||||
<role>Java Developer</role>
|
||||
</roles>
|
||||
<timezone>-5</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
</project>
|
||||
|
|
|
@ -47,11 +47,11 @@ import java.util.Locale;
|
|||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
/**
|
||||
* @goal checkstyle
|
||||
*
|
||||
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
|
||||
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
|
||||
* @version $Id: DependenciesReport.java,v 1.2 2005/02/23 00:08:02 brett Exp $
|
||||
*/
|
||||
public class CheckstyleReport
|
||||
|
@ -64,7 +64,7 @@ public class CheckstyleReport
|
|||
* @required
|
||||
*/
|
||||
private String outputDirectory;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the names filter of the source files to be used for checkstyle
|
||||
*
|
||||
|
@ -72,14 +72,14 @@ public class CheckstyleReport
|
|||
* @required
|
||||
*/
|
||||
private String includes;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the names filter of the source files to be excluded for checkstyle
|
||||
*
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String excludes;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies what predefined check set to use. Available sets are
|
||||
* "sun" (for the Sun coding conventions), "turbine", and "avalon".
|
||||
|
@ -88,21 +88,21 @@ public class CheckstyleReport
|
|||
* @parameter default-value="sun"
|
||||
*/
|
||||
private String format;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the location of the checkstyle properties that will be used to check the source.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private File propertiesFile;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the URL of the checkstyle properties that will be used to check the source.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private URL propertiesURL;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the location of the License file (a.k.a. the header file) that is used by Checkstyle
|
||||
* to verify that source code has the correct copyright.
|
||||
|
@ -117,7 +117,7 @@ public class CheckstyleReport
|
|||
* @parameter expression="${project.build.directory}/checkstyle-cachefile"
|
||||
*/
|
||||
private String cacheFile;
|
||||
|
||||
|
||||
/**
|
||||
* If null, the checkstyle task will display violations on stdout. Otherwise, the text file will be
|
||||
* created with the violations. Note: This is in addition to the XML result file (containing
|
||||
|
@ -126,7 +126,7 @@ public class CheckstyleReport
|
|||
* @parameter
|
||||
*/
|
||||
private String useFile;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the location of the supperssions XML file to use. The plugin defines a Checkstyle
|
||||
* property named <code>checkstyle.supperssions.file</code> with the value of this
|
||||
|
@ -136,7 +136,7 @@ public class CheckstyleReport
|
|||
* @parameter
|
||||
*/
|
||||
private String suppressionsFile;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the path and filename to save the checkstyle output. The format of the output file is
|
||||
* determined by the <code>outputFileFormat</code>
|
||||
|
@ -155,7 +155,7 @@ public class CheckstyleReport
|
|||
|
||||
/**
|
||||
* Specifies the location of the package names XML to be used to configure Checkstyle
|
||||
*
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String packageNamesFile;
|
||||
|
@ -166,7 +166,7 @@ public class CheckstyleReport
|
|||
* @parameter default-value="false"
|
||||
*/
|
||||
private boolean failsOnError;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the location of the source files to be used for Checkstyle
|
||||
*
|
||||
|
@ -232,7 +232,8 @@ public class CheckstyleReport
|
|||
/**
|
||||
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
|
||||
*/
|
||||
public void executeReport( Locale locale ) throws MavenReportException
|
||||
public void executeReport( Locale locale )
|
||||
throws MavenReportException
|
||||
{
|
||||
File[] files = getFilesToProcess( includes, excludes );
|
||||
|
||||
|
@ -241,25 +242,27 @@ public class CheckstyleReport
|
|||
Properties overridingProperties = getOverridingProperties();
|
||||
|
||||
ModuleFactory moduleFactory = getModuleFactory();
|
||||
|
||||
|
||||
FilterSet filterSet = getSuppressions();
|
||||
|
||||
|
||||
Checker checker = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Configuration config = ConfigurationLoader.loadConfiguration( configFile,
|
||||
new PropertiesExpander( overridingProperties ) );
|
||||
Configuration config = ConfigurationLoader
|
||||
.loadConfiguration( configFile, new PropertiesExpander( overridingProperties ) );
|
||||
|
||||
checker = new Checker();
|
||||
|
||||
if ( moduleFactory != null ) checker.setModuleFactory( moduleFactory );
|
||||
|
||||
if ( filterSet != null ) checker.addFilter( filterSet );
|
||||
if ( moduleFactory != null )
|
||||
checker.setModuleFactory( moduleFactory );
|
||||
|
||||
if ( filterSet != null )
|
||||
checker.addFilter( filterSet );
|
||||
|
||||
checker.configure( config );
|
||||
}
|
||||
catch( CheckstyleException ce )
|
||||
catch ( CheckstyleException ce )
|
||||
{
|
||||
throw new MavenReportException( "Failed during checkstyle configuration", ce );
|
||||
}
|
||||
|
@ -270,13 +273,13 @@ public class CheckstyleReport
|
|||
{
|
||||
checker.addListener( listener );
|
||||
}
|
||||
|
||||
|
||||
if ( StringUtils.isNotEmpty( useFile ) )
|
||||
{
|
||||
File outputFile = new File( useFile );
|
||||
|
||||
|
||||
OutputStream out = getOutputStream( outputFile );
|
||||
|
||||
|
||||
checker.addListener( new DefaultLogger( out, true ) );
|
||||
}
|
||||
|
||||
|
@ -301,17 +304,18 @@ public class CheckstyleReport
|
|||
{
|
||||
return "checkstyle";
|
||||
}
|
||||
|
||||
private AuditListener getListener() throws MavenReportException
|
||||
|
||||
private AuditListener getListener()
|
||||
throws MavenReportException
|
||||
{
|
||||
AuditListener listener = null;
|
||||
|
||||
if ( StringUtils.isNotEmpty( outputFileFormat ) )
|
||||
{
|
||||
File resultFile = new File( outputFile );
|
||||
|
||||
|
||||
OutputStream out = getOutputStream( resultFile );
|
||||
|
||||
|
||||
if ( "xml".equals( outputFileFormat ) )
|
||||
{
|
||||
listener = new XMLLogger( out, true );
|
||||
|
@ -322,23 +326,26 @@ public class CheckstyleReport
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new MavenReportException( "Invalid output file format: (" + outputFileFormat + "). Must be 'plain' or 'xml'." );
|
||||
throw new MavenReportException( "Invalid output file format: (" + outputFileFormat
|
||||
+ "). Must be 'plain' or 'xml'." );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return listener;
|
||||
}
|
||||
|
||||
private OutputStream getOutputStream( File file ) throws MavenReportException
|
||||
|
||||
private OutputStream getOutputStream( File file )
|
||||
throws MavenReportException
|
||||
{
|
||||
FileOutputStream out;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
File parentFile = file.getParentFile();
|
||||
|
||||
if ( !parentFile.exists() ) parentFile.mkdirs();
|
||||
|
||||
|
||||
if ( !parentFile.exists() )
|
||||
parentFile.mkdirs();
|
||||
|
||||
return new FileOutputStream( file );
|
||||
}
|
||||
catch ( IOException ioe )
|
||||
|
@ -347,27 +354,28 @@ public class CheckstyleReport
|
|||
}
|
||||
}
|
||||
|
||||
private File[] getFilesToProcess( String includes, String excludes ) throws MavenReportException
|
||||
private File[] getFilesToProcess( String includes, String excludes )
|
||||
throws MavenReportException
|
||||
{
|
||||
StringBuffer excludesStr = new StringBuffer();
|
||||
|
||||
|
||||
if ( StringUtils.isNotEmpty( excludes ) )
|
||||
{
|
||||
excludesStr.append(excludes);
|
||||
excludesStr.append( excludes );
|
||||
}
|
||||
|
||||
|
||||
for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++ )
|
||||
{
|
||||
if ( excludesStr.length() > 0 )
|
||||
{
|
||||
excludesStr.append( "," );
|
||||
}
|
||||
|
||||
|
||||
excludesStr.append( DEFAULT_EXCLUDES[i] );
|
||||
}
|
||||
|
||||
List files;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
files = FileUtils.getFiles( new File( sourceDirectory ), includes, excludesStr.toString() );
|
||||
|
@ -376,17 +384,18 @@ public class CheckstyleReport
|
|||
{
|
||||
throw new MavenReportException( "Failed to get source files", ioe );
|
||||
}
|
||||
|
||||
return (File[]) ( files.toArray( new File[ 0 ] ) );
|
||||
|
||||
return (File[]) ( files.toArray( new File[0] ) );
|
||||
}
|
||||
|
||||
private Properties getOverridingProperties() throws MavenReportException
|
||||
private Properties getOverridingProperties()
|
||||
throws MavenReportException
|
||||
{
|
||||
Properties p = new Properties();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if ( propertiesFile != null )
|
||||
if ( propertiesFile != null )
|
||||
{
|
||||
p.load( new FileInputStream( propertiesFile ) );
|
||||
}
|
||||
|
@ -405,37 +414,41 @@ public class CheckstyleReport
|
|||
{
|
||||
throw new MavenReportException( "Failed to get overriding properties", e );
|
||||
}
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private String getConfigFile() throws MavenReportException
|
||||
|
||||
private String getConfigFile()
|
||||
throws MavenReportException
|
||||
{
|
||||
URL configFile;
|
||||
|
||||
if ( "turbine".equalsIgnoreCase( format ) )
|
||||
|
||||
if ( StringUtils.isEmpty( format ) || ( "sun".equalsIgnoreCase( format.trim() ) ) )
|
||||
{
|
||||
// By default
|
||||
configFile = getClass().getResource( "/config/sun_checks.xml" );
|
||||
}
|
||||
else if ( "turbine".equalsIgnoreCase( format.trim() ) )
|
||||
{
|
||||
configFile = getClass().getResource( "/config/turbine_checks.xml" );
|
||||
}
|
||||
else if ( "avalon".equalsIgnoreCase( format ) )
|
||||
else if ( "avalon".equalsIgnoreCase( format.trim() ) )
|
||||
{
|
||||
configFile = getClass().getResource( "/config/avalon_checks.xml" );
|
||||
}
|
||||
else if ( "".equalsIgnoreCase( format ) )
|
||||
{
|
||||
configFile = getClass().getResource( "/config/sun_checks.xml" );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MavenReportException( "Invalid configuration file format: " + format );
|
||||
}
|
||||
|
||||
|
||||
return configFile.toString();
|
||||
}
|
||||
|
||||
private ModuleFactory getModuleFactory() throws MavenReportException
|
||||
|
||||
private ModuleFactory getModuleFactory()
|
||||
throws MavenReportException
|
||||
{
|
||||
if ( StringUtils.isEmpty( packageNamesFile ) ) return null;
|
||||
if ( StringUtils.isEmpty( packageNamesFile ) )
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -446,11 +459,13 @@ public class CheckstyleReport
|
|||
throw new MavenReportException( "failed to load package names XML: " + packageNamesFile, ce );
|
||||
}
|
||||
}
|
||||
|
||||
private FilterSet getSuppressions() throws MavenReportException
|
||||
|
||||
private FilterSet getSuppressions()
|
||||
throws MavenReportException
|
||||
{
|
||||
if ( StringUtils.isEmpty( suppressionsFile ) ) return null;
|
||||
|
||||
if ( StringUtils.isEmpty( suppressionsFile ) )
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return SuppressionsLoader.loadSuppressions( suppressionsFile );
|
||||
|
@ -463,6 +478,6 @@ public class CheckstyleReport
|
|||
|
||||
private static ResourceBundle getBundle( Locale locale )
|
||||
{
|
||||
return ResourceBundle.getBundle("checkstyle-report", locale, CheckstyleReport.class.getClassLoader() );
|
||||
return ResourceBundle.getBundle( "checkstyle-report", locale, CheckstyleReport.class.getClassLoader() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# -------------------------------------------------------------------
|
||||
# Copyright 2001-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.
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
log4j.rootCategory=INFO, stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%5p [%c{1}:%L] %d{ISO8601} - %m%n
|
||||
|
||||
log4j.logger.org.apache.commons.beanutils=ERROR
|
Loading…
Reference in New Issue