Author: dennisl Date: Mon Jan 7 15:37:24 2013 New Revision: 1429846 URL: http://svn.apache.org/viewvc?rev=1429846&view=rev Log: [MCHECKSTYLE-184] Allow src/main/resources to be searched by Checkstyle
Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/App_en.properties (with props) Modified: maven/plugins/trunk/maven-checkstyle-plugin/ (props changed) maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/pom.xml maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/verify.groovy maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.java maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleAggregateReport.java maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven_checks.xml Propchange: maven/plugins/trunk/maven-checkstyle-plugin/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Mon Jan 7 15:37:24 2013 @@ -9,3 +9,4 @@ target .externalToolBuilders maven-eclipse.xml bin +.idea Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/App_en.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/App_en.properties?rev=1429846&view=auto ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/App_en.properties (added) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/App_en.properties Mon Jan 7 15:37:24 2013 @@ -0,0 +1 @@ +key=value Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/App_en.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/child-a/src/main/resources/org/apache/maven/plugins/checkstyle/its/App_en.properties ------------------------------------------------------------------------------ svn:keywords = Date Revision Author Id Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/pom.xml?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/pom.xml (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/pom.xml Mon Jan 7 15:37:24 2013 @@ -38,11 +38,7 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>@pom.version@</version> - <configuration> - <configLocation>http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.5/src/main/resources/config/maven_checks.xml</configLocation> - <headerLocation>http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.5/src/main/resources/config/maven-header.txt</headerLocation> - </configuration> - </plugin> + </plugin> </plugins> </pluginManagement> <plugins> @@ -66,6 +62,9 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>@pom.version@</version> + <configuration> + <configLocation>config/maven_checks.xml</configLocation> + </configuration> <inherited>false</inherited> <reportSets> <reportSet> Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/verify.groovy URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/verify.groovy?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/verify.groovy (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/multi-modules-aggregate/verify.groovy Mon Jan 7 15:37:24 2013 @@ -28,6 +28,7 @@ assert new File(basedir, 'target/site/ch content = new File(basedir, 'target/site/checkstyle-aggregate.html').text; assert content.contains( 'org/apache/maven/plugins/checkstyle/its/App.java' ); +assert content.contains( 'org/apache/maven/plugins/checkstyle/its/App_en.properties' ); assert content.contains( 'org/apache/maven/plugins/checkstyle/its/AppTest.java' ); return true; \ No newline at end of file Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.java?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.java (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.java Mon Jan 7 15:37:24 2013 @@ -26,6 +26,7 @@ import com.puppycrawl.tools.checkstyle.a import org.apache.maven.doxia.siterenderer.Renderer; import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.model.ReportPlugin; +import org.apache.maven.model.Resource; import org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator; import org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGeneratorRequest; import org.apache.maven.plugins.annotations.Component; @@ -46,6 +47,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Calendar; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.ResourceBundle; @@ -88,6 +90,14 @@ public abstract class AbstractCheckstyle private File outputFile; /** + * Specifies the location of the resources to be used for Checkstyle. + * + * @since 2.10 + */ + @Parameter( defaultValue = "${project.resources}" ) + protected List<Resource> resources; + + /** * If <code>null</code>, the Checkstyle plugin will display violations on stdout. * Otherwise, a text file will be created with the violations. */ Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleAggregateReport.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleAggregateReport.java?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleAggregateReport.java (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleAggregateReport.java Mon Jan 7 15:37:24 2013 @@ -253,7 +253,7 @@ public class CheckstyleAggregateReport .setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput ) .setExcludes( excludes ).setFailsOnError( failsOnError ).setIncludes( includes ) .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() ) - .setLog( getLog() ).setProject( project ).setSourceDirectory( sourceDirectory ) + .setLog( getLog() ).setProject( project ).setSourceDirectory( sourceDirectory ).setResources( resources ) .setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation ) .setTestSourceDirectory( testSourceDirectory ).setConfigLocation( configLocation ) .setPropertyExpansion( propertyExpansion ).setHeaderLocation( headerLocation ) Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java Mon Jan 7 15:37:24 2013 @@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.util.List; +import org.apache.maven.model.Resource; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; @@ -59,6 +60,8 @@ public class CheckstyleExecutorRequest private File sourceDirectory; + private List<Resource> resources; + private boolean failsOnError; private AuditListener listener; @@ -196,6 +199,16 @@ public class CheckstyleExecutorRequest return this; } + public List<Resource> getResources() { + return resources; + } + + public CheckstyleExecutorRequest setResources( List<Resource> resources ) + { + this.resources = resources; + return this; + } + public boolean isFailsOnError() { return failsOnError; Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java Mon Jan 7 15:37:24 2013 @@ -349,7 +349,7 @@ public class CheckstyleReport request.setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput ) .setExcludes( excludes ).setFailsOnError( failsOnError ).setIncludes( includes ) .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() ) - .setLog( getLog() ).setProject( project ).setSourceDirectory( sourceDirectory ) + .setLog( getLog() ).setProject( project ).setSourceDirectory( sourceDirectory ).setResources( resources ) .setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation ) .setTestSourceDirectory( testSourceDirectory ).setConfigLocation( configLocation ) .setPropertyExpansion( propertyExpansion ).setHeaderLocation( headerLocation ) Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java Mon Jan 7 15:37:24 2013 @@ -33,6 +33,7 @@ import java.util.Properties; import org.apache.commons.io.IOUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.model.Resource; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -188,12 +189,12 @@ public class DefaultCheckstyleExecutor for ( MavenProject childProject : request.getReactorProjects() ) { addSourceDirectory( sinkListener, new File( childProject.getBuild().getSourceDirectory() ), - new File( childProject.getBuild().getSourceDirectory() ), request ); + new File( childProject.getBuild().getSourceDirectory() ), childProject.getResources(), request); } } else { - addSourceDirectory( sinkListener, sourceDirectory, testSourceDirectory, request ); + addSourceDirectory( sinkListener, sourceDirectory, testSourceDirectory, request.getResources(), request); } checker.addListener( sinkListener ); @@ -224,17 +225,35 @@ public class DefaultCheckstyleExecutor } protected void addSourceDirectory( CheckstyleReportListener sinkListener, File sourceDirectory, - File testSourceDirectory, CheckstyleExecutorRequest request ) + File testSourceDirectory, List<Resource> resources, + CheckstyleExecutorRequest request ) { if ( sourceDirectory != null ) { sinkListener.addSourceDirectory( sourceDirectory ); } + if ( request.isIncludeTestSourceDirectory() && ( testSourceDirectory != null ) && ( testSourceDirectory.exists() ) && ( testSourceDirectory.isDirectory() ) ) { sinkListener.addSourceDirectory( testSourceDirectory ); } + + if ( resources != null ) + { + for ( Resource resource : resources ) + { + if ( resource.getDirectory() != null ) + { + File resourcesDirectory = new File( resource.getDirectory() ); + if ( resourcesDirectory.exists() && resourcesDirectory.isDirectory() ) + { + sinkListener.addSourceDirectory( resourcesDirectory ); + getLogger().debug( "Added '" + resourcesDirectory.getAbsolutePath() + "' as a source directory." ); + } + } + } + } } public Configuration getConfiguration( CheckstyleExecutorRequest request ) @@ -483,19 +502,19 @@ public class DefaultCheckstyleExecutor { for ( MavenProject project : request.getReactorProjects() ) { - addFilesToProcess( request, excludesStr, new File( project.getBuild().getSourceDirectory() ), files ); + addFilesToProcess( request, excludesStr, new File( project.getBuild().getSourceDirectory() ), project.getResources(), files); } } else { - addFilesToProcess( request, excludesStr, sourceDirectory, files ); + addFilesToProcess( request, excludesStr, sourceDirectory, request.getResources(), files); } return (File[]) files.toArray( EMPTY_FILE_ARRAY ); } private void addFilesToProcess( CheckstyleExecutorRequest request, StringBuilder excludesStr, File sourceDirectory, - List<File> files ) + List<Resource> resources, List<File> files) throws IOException { if ( sourceDirectory == null || !sourceDirectory.exists() ) @@ -504,6 +523,7 @@ public class DefaultCheckstyleExecutor } files.addAll( FileUtils.getFiles( sourceDirectory, request.getIncludes(), excludesStr.toString() ) ); + File testSourceDirectory = request.getTestSourceDirectory(); if ( request.isIncludeTestSourceDirectory() && ( testSourceDirectory != null ) && ( testSourceDirectory.exists() ) && ( testSourceDirectory.isDirectory() ) ) @@ -511,6 +531,33 @@ public class DefaultCheckstyleExecutor files.addAll( FileUtils.getFiles( testSourceDirectory, request.getIncludes(), excludesStr.toString() ) ); } + + // @todo Should we add a check to see if resources should be included or not, similar to request.isIncludeTestSourceDirectory()? + if ( resources != null ) + { + for ( Resource resource : resources) + { + if ( resource.getDirectory() != null ) + { + File resourcesDirectory = new File( resource.getDirectory() ); + if ( resourcesDirectory.exists() && resourcesDirectory.isDirectory() ) + { + // @todo Perhaps extend the functionality in the future so that the included types of files can be configured. For now it is hard-coded to properties files. + List resourceFiles = FileUtils.getFiles( resourcesDirectory, "**/*.properties", null ); + files.addAll( resourceFiles ); + getLogger().debug( "Added " + resourceFiles.size() + " resource files found in '" + resourcesDirectory.getAbsolutePath() + "'." ); + } + else + { + getLogger().debug( "The resources directory '" + resourcesDirectory.getAbsolutePath() + "' does not exist or is not a directory." ); + } + } + } + } + else + { + getLogger().debug( "No resources found in this project." ); + } } private FilterSet getSuppressions( CheckstyleExecutorRequest request ) Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven_checks.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven_checks.xml?rev=1429846&r1=1429845&r2=1429846&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven_checks.xml (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven_checks.xml Mon Jan 7 15:37:24 2013 @@ -40,7 +40,7 @@ under the License. <!-- Checks that property files contain the same keys. --> <!-- See http://checkstyle.sf.net/config_misc.html#Translation --> - <!-- module name="Translation"/ --> + <module name="Translation"/> <module name="FileLength"/>