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/03/01 11:49:23 UTC

svn commit: r1573147 - in /maven/plugins/trunk/maven-checkstyle-plugin/src: it/MCHECKSTYLE-219-no-license_failure/ it/MCHECKSTYLE-219-no-license_success/ main/java/org/apache/maven/plugin/checkstyle/ main/java/org/apache/maven/plugin/checkstyle/resource/

Author: rfscholte
Date: Sat Mar  1 10:49:22 2014
New Revision: 1573147

URL: http://svn.apache.org/r1573147
Log:
[MCHECKSTYLE-219] When no license is specified, ALv2 from maven-checkstyle-plugin is used

Added:
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/invoker.properties
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/pom.xml
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/verify.groovy
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/invoker.properties
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/pom.xml
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/verify.groovy
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/resource/
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/resource/LicenseResourceManager.java
Modified:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/invoker.properties?rev=1573147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/invoker.properties (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/invoker.properties Sat Mar  1 10:49:22 2014
@@ -0,0 +1,21 @@
+# 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 = verify
+invoker.debug = true
+
+invoker.buildResult = failure
\ No newline at end of file

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/pom.xml?rev=1573147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/pom.xml (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/pom.xml Sat Mar  1 10:49:22 2014
@@ -0,0 +1,54 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.checkstyle</groupId>
+  <artifactId>mcheckstyle-219</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>@pom.version@</version>
+        <executions>
+          <execution>
+            <id>check</id>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <configLocation>config/turbine_checks.xml</configLocation>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/verify.groovy?rev=1573147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/verify.groovy (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_failure/verify.groovy Sat Mar  1 10:49:22 2014
@@ -0,0 +1,28 @@
+
+/*
+ * 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' )
+
+assert !buildLog.text.contains( "The resource 'LICENSE.txt' was found" )
+
+assert buildLog.text.contains( "Unable to process header location: LICENSE.txt" )
+assert buildLog.text.contains( 'Checkstyle will throw exception if ${checkstyle.header.file} is used' )
+
+assert buildLog.text.contains( "Failed during checkstyle configuration" )
+assert buildLog.text.contains( 'Property ${checkstyle.header.file} has not been set' )

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/invoker.properties?rev=1573147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/invoker.properties (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/invoker.properties Sat Mar  1 10:49:22 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 = verify
+invoker.debug = true
\ No newline at end of file

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/pom.xml?rev=1573147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/pom.xml (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/pom.xml Sat Mar  1 10:49:22 2014
@@ -0,0 +1,55 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.checkstyle</groupId>
+  <artifactId>mcheckstyle-219_success</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <description>
+    The default configLocation (i.e. config/sun_checks.xml ) doesn't check for headers, so it doesn't matter if the LICENSE.txt couldn't be found.
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>@pom.version@</version>
+        <executions>
+          <execution>
+            <id>check</id>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/verify.groovy?rev=1573147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/verify.groovy (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-219-no-license_success/verify.groovy Sat Mar  1 10:49:22 2014
@@ -0,0 +1,25 @@
+
+/*
+ * 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' )
+
+assert !buildLog.text.contains( "The resource 'LICENSE.txt' was found" )
+
+assert buildLog.text.contains( "Unable to process header location: LICENSE.txt" )
+assert buildLog.text.contains( 'Checkstyle will throw exception if ${checkstyle.header.file} is used' )

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=1573147&r1=1573146&r2=1573147&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 Sat Mar  1 10:49:22 2014
@@ -66,8 +66,11 @@ public class DefaultCheckstyleExecutor
     extends AbstractLogEnabled
     implements CheckstyleExecutor
 {
-    @Requirement
+    @Requirement( hint = "default" )
     private ResourceManager locator;
+    
+    @Requirement( hint = "license" )
+    private ResourceManager licenseLocator;
 
     private static final File[] EMPTY_FILE_ARRAY = new File[0];
 
@@ -88,7 +91,9 @@ public class DefaultCheckstyleExecutor
 
         MavenProject project = request.getProject();
 
-        configureResourceLocator(request);
+        configureResourceLocator( locator, request);
+        
+        configureResourceLocator( licenseLocator, request );
 
         File[] files;
         try
@@ -278,6 +283,7 @@ public class DefaultCheckstyleExecutor
                 .loadConfiguration( configFile, new PropertiesExpander( overridingProperties ) );
             String effectiveEncoding = StringUtils.isNotEmpty( request.getEncoding() ) ? request.getEncoding() : System
                 .getProperty( "file.encoding", "UTF-8" );
+            
             if ( StringUtils.isEmpty( request.getEncoding() ) )
             {
                 request.getLog().warn(
@@ -433,7 +439,7 @@ public class DefaultCheckstyleExecutor
             {
                 try
                 {
-                    File headerFile = locator.getResourceAsFile( headerLocation, "checkstyle-header.txt" );
+                    File headerFile = licenseLocator.getResourceAsFile( headerLocation, "checkstyle-header.txt" );
 
                     if ( headerFile != null )
                     {
@@ -442,11 +448,13 @@ public class DefaultCheckstyleExecutor
                 }
                 catch ( FileResourceCreationException e )
                 {
-                    throw new CheckstyleExecutorException( "Unable to process header location: " + headerLocation, e );
+                    getLogger().debug( "Unable to process header location: " + headerLocation );
+                    getLogger().debug( "Checkstyle will throw exception if ${checkstyle.header.file} is used" );
                 }
                 catch ( ResourceNotFoundException e )
                 {
-                    throw new CheckstyleExecutorException( "Unable to process header location: " + headerLocation, e );
+                    getLogger().debug( "Unable to process header location: " + headerLocation );
+                    getLogger().debug( "Checkstyle will throw exception if ${checkstyle.header.file} is used" );
                 }
             }
 
@@ -676,10 +684,10 @@ public class DefaultCheckstyleExecutor
      *
      * @param request executor request data.
      */
-    private void configureResourceLocator( final CheckstyleExecutorRequest request )
+    private void configureResourceLocator( final ResourceManager resourceManager, final CheckstyleExecutorRequest request )
     {
         final MavenProject project = request.getProject();
-        locator.setOutputDirectory( new File( project.getBuild().getDirectory() ) );
+        resourceManager.setOutputDirectory( new File( project.getBuild().getDirectory() ) );
 
         // Recurse up the parent hierarchy and add project directories to the search roots
         MavenProject parent = project;
@@ -689,10 +697,10 @@ public class DefaultCheckstyleExecutor
             // (dkulp) Me either.   It really pollutes the location stuff
             // by allowing searches of stuff outside the current module.
             File dir = parent.getFile().getParentFile();
-            locator.addSearchPath( FileResourceLoader.ID, dir.getAbsolutePath() );
+            resourceManager.addSearchPath( FileResourceLoader.ID, dir.getAbsolutePath() );
             parent = parent.getParent();
         }
 
-        locator.addSearchPath( "url", "" );
+        resourceManager.addSearchPath( "url", "" );
     }
 }

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/resource/LicenseResourceManager.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/resource/LicenseResourceManager.java?rev=1573147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/resource/LicenseResourceManager.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/resource/LicenseResourceManager.java Sat Mar  1 10:49:22 2014
@@ -0,0 +1,83 @@
+package org.apache.maven.plugin.checkstyle.resource;
+
+/*
+ * 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.
+ */
+
+import java.util.Map;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.resource.DefaultResourceManager;
+import org.codehaus.plexus.resource.PlexusResource;
+import org.codehaus.plexus.resource.ResourceManager;
+import org.codehaus.plexus.resource.loader.ResourceLoader;
+import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
+import org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader;
+
+@Component( role = ResourceManager.class, hint = "license" )
+public class LicenseResourceManager
+    extends DefaultResourceManager
+{
+
+    @Requirement( role = ResourceLoader.class )
+    private Map<String, ResourceLoader> resourceLoaders;
+
+    @Override
+    public void addSearchPath( String id, String path )
+    {
+        ResourceLoader loader = (ResourceLoader) resourceLoaders.get( id );
+
+        if ( loader == null )
+        {
+            throw new IllegalArgumentException( "unknown resource loader: " + id );
+        }
+
+        loader.addSearchPath( path );
+    }
+
+    @Override
+    public PlexusResource getResource( String name )
+        throws ResourceNotFoundException
+    {
+        for ( ResourceLoader resourceLoader : resourceLoaders.values() )
+        {
+            if ( resourceLoader instanceof ThreadContextClasspathResourceLoader )
+            {
+                // MCHECKSTYLE-219: Don't load the license from the plugin classloader
+                continue;
+            }
+
+            try
+            {
+                PlexusResource resource = resourceLoader.getResource( name );
+
+                getLogger().debug( "The resource " + "'" + name + "'" + " was found as " + resource.getName() + "." );
+
+                return resource;
+            }
+            catch ( ResourceNotFoundException e )
+            {
+                getLogger().debug( "The resource " + "'" + name + "'" + " was not found with resourceLoader "
+                                       + resourceLoader.getClass().getName() + "." );
+            }
+        }
+
+        throw new ResourceNotFoundException( name );
+    }
+}