You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2014/08/20 23:55:37 UTC

svn commit: r1619243 - in /maven/plugins/trunk/maven-checkstyle-plugin/src: it/MCHECKSTYLE-214-basedir-resource/ it/MCHECKSTYLE-214-basedir-resource/src/ it/MCHECKSTYLE-214-basedir-resource/src/main/ it/MCHECKSTYLE-214-basedir-resource/src/main/resourc...

Author: rfscholte
Date: Wed Aug 20 21:55:37 2014
New Revision: 1619243

URL: http://svn.apache.org/r1619243
Log:
[MCHECKSTYLE-214] Resources retrieval ignores resources definition in <build>
Consider resources relative to project root as a special case

Added:
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/LICENSE.txt
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/invoker.properties
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/pom.xml
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/main/
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/main/resources/
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/main/resources/README.txt
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/verify.groovy
Modified:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/CheckstyleCheckerListener.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/LICENSE.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/LICENSE.txt?rev=1619243&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/LICENSE.txt (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/LICENSE.txt Wed Aug 20 21:55:37 2014
@@ -0,0 +1 @@
+	A real tab and no new line
\ No newline at end of file

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/invoker.properties?rev=1619243&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/invoker.properties (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/invoker.properties Wed Aug 20 21:55:37 2014
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+invoker.goals = checkstyle:check
+invoker.buildResult = failure

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/pom.xml?rev=1619243&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/pom.xml (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/pom.xml Wed Aug 20 21:55:37 2014
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you 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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.checkstyle</groupId>
+  <artifactId>MCHECKSTYLE-214</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <url>http://jira.codehaus.org/browse/MCHECKSTYLE-214</url>
+  
+  <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <!-- even though README.txt doesn't end up in the jar, it must be verified -->
+        <excludes>
+          <exclude>*</exclude>
+        </excludes>
+      </resource>
+      <resource>
+        <directory>${basedir}</directory>
+        <targetPath>META-INF</targetPath>
+        <includes>
+          <include>LICENSE.txt</include>
+        </includes>
+      </resource>
+    </resources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <resourceIncludes>**/*.txt</resourceIncludes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/main/resources/README.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/main/resources/README.txt?rev=1619243&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/main/resources/README.txt (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/src/main/resources/README.txt Wed Aug 20 21:55:37 2014
@@ -0,0 +1 @@
+	A real tab

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/verify.groovy?rev=1619243&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/verify.groovy (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-214-basedir-resource/verify.groovy Wed Aug 20 21:55:37 2014
@@ -0,0 +1,27 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+def buildLog = new File( basedir, 'build.log' )
+
+// LICENSE.txt has 2 errors, src/main/resources/README.txt has 1 error
+assert buildLog.text.contains( "[INFO] There are 3 checkstyle errors." )
+
+def checkstyle = new XmlSlurper().parse( new File( basedir, "target/checkstyle-result.xml" ) )
+assert 2 == checkstyle.file.size()
+

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/CheckstyleCheckerListener.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/CheckstyleCheckerListener.java?rev=1619243&r1=1619242&r2=1619243&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/CheckstyleCheckerListener.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/CheckstyleCheckerListener.java Wed Aug 20 21:55:37 2014
@@ -134,6 +134,8 @@ public class CheckstyleCheckerListener
                 currentFile = StringUtils.substring( fileName, sourceDirectoryPath.length() + 1 );
 
                 events = getResults().getFileViolations( currentFile );
+                
+                break;
             }
         }
 

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java?rev=1619243&r1=1619242&r2=1619243&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java Wed Aug 20 21:55:37 2014
@@ -105,7 +105,7 @@ public class DefaultCheckstyleExecutor
         // Config is less critical than License, locator can still be used.
         // configureResourceLocator( configurationLocator, request, request.getConfigurationArtifacts() );
 
-        File[] files;
+        List<File> files;
         try
         {
             files = getFilesToProcess( request );
@@ -244,8 +244,7 @@ public class DefaultCheckstyleExecutor
 
         checker.addListener( checkerListener );
 
-        List<File> filesList = Arrays.asList( files );
-        int nbErrors = checker.process( filesList );
+        int nbErrors = checker.process( files );
 
         checker.destroy();
 
@@ -559,7 +558,7 @@ public class DefaultCheckstyleExecutor
         return p;
     }
 
-    private File[] getFilesToProcess( CheckstyleExecutorRequest request )
+    private List<File> getFilesToProcess( CheckstyleExecutorRequest request )
         throws IOException
     {
         StringBuilder excludesStr = new StringBuilder();
@@ -580,7 +579,7 @@ public class DefaultCheckstyleExecutor
             excludesStr.append( defaultExclude );
         }
 
-        List<File> files = new ArrayList<File>();
+        Set<File> files = new LinkedHashSet<File>();
         if ( request.isAggregate() )
         {
             for ( MavenProject project : request.getReactorProjects() )
@@ -615,11 +614,11 @@ public class DefaultCheckstyleExecutor
 
         getLogger().debug( "Added " + files.size() + " files to process." );
 
-        return files.toArray( new File[files.size()] );
+        return new ArrayList<File>( files );
     }
 
     private void addFilesToProcess( CheckstyleExecutorRequest request, Collection<File> sourceDirectories, List<Resource> resources,
-                                    List<Resource> testResources, List<File> files, Collection<File> testSourceDirectories )
+                                    List<Resource> testResources, Collection<File> files, Collection<File> testSourceDirectories )
         throws IOException
     {
         if ( sourceDirectories != null )
@@ -673,7 +672,7 @@ public class DefaultCheckstyleExecutor
     }
 
     private void addResourceFilesToProcess( CheckstyleExecutorRequest request, List<Resource> resources,
-                                            List<File> files )
+                                            Collection<File> files )
         throws IOException
     {
         for ( Resource resource : resources )
@@ -681,11 +680,37 @@ public class DefaultCheckstyleExecutor
             if ( resource.getDirectory() != null )
             {
                 File resourcesDirectory = new File( resource.getDirectory() );
-                if ( resourcesDirectory.exists() && resourcesDirectory.isDirectory() )
+                if ( resourcesDirectory.isDirectory() )
                 {
+                    String includes = request.getResourceIncludes();
+                    String excludes = request.getResourceExcludes();
+
+                    // MCHECKSTYLE-214: Only with project-root respect in/excludes, otherwise you'll get every file
+                    if ( resourcesDirectory.equals( request.getProject().getBasedir() ) )
+                    {
+                        String resourceIncludes = StringUtils.join( resource.getIncludes().iterator(), "," );
+                        if ( StringUtils.isEmpty( includes ) )
+                        {
+                            includes = resourceIncludes;
+                        }
+                        else
+                        {
+                            includes += "," + resourceIncludes;
+                        }
+                        
+                        String resourceExcludes = StringUtils.join( resource.getExcludes().iterator(), "," );
+                        if( StringUtils.isEmpty( excludes ) )
+                        {
+                            excludes = resourceExcludes;
+                        }
+                        else
+                        {
+                            excludes += "," + resourceExcludes;
+                        }
+                    }
+                    
                     List<File> resourceFiles =
-                        FileUtils.getFiles( resourcesDirectory, request.getResourceIncludes(),
-                                            request.getResourceExcludes() );
+                        FileUtils.getFiles( resourcesDirectory, includes, excludes );
                     files.addAll( resourceFiles );
                     getLogger().debug( "Added " + resourceFiles.size() + " resource files found in '"
                             + resourcesDirectory.getAbsolutePath() + "'." );