Author: struberg
Date: Tue Sep  8 18:22:25 2009
New Revision: 812606

URL: http://svn.apache.org/viewvc?rev=812606&view=rev
Log:
MSHADE-60 skip dependency of type 'pom' from shading

If one has a dependency which cannot be opened via JarFile we now will at least
throw a verbose Exception with stating the exact file which failed.

I also added an integration test to make sure that the transitive dependencies
pulled in via this pom-dependency gets picked up into the shaded jar.

Added:
    maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/
    maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pom.xml   
(with props)
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/pom.xml
   (with props)
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/pom.xml
   (with props)
    maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/pom.xml
   (with props)
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/
    
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/ShadedClassUsage.java
   (with props)
Modified:
    
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
    
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java

Added: maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pom.xml?rev=812606&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pom.xml 
(added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pom.xml 
Tue Sep  8 18:22:25 2009
@@ -0,0 +1,46 @@
+<?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.its.shade.spom</groupId>
+  <artifactId>shadePomDependency</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+
+  <name>MSHADE-60 :: dependency to a type=pom artifact</name>
+  <description>
+    Test creating an uberwar containing an artifact which may not 
+    be handled by the JarFile like e.g. a depending pom.
+    The artifact with packaging=pom we depend on has several other  
+    artifacts as dependencies. Those artifacts should be contained 
+    in the shade-artifact finally.
+  </description>
+
+  <modules>
+    <module>pomDependency</module>
+    <module>shadingModule</module>
+    <module>testModule</module>
+  </modules>
+  
+</project>

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/pom.xml?rev=812606&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/pom.xml
 Tue Sep  8 18:22:25 2009
@@ -0,0 +1,47 @@
+<?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.its.shade.spom</groupId>
+  <artifactId>pomDependency</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+
+  <name>MSHADE-60 :: dependency to a packaging=pom artifact</name>
+  <description>
+    This is an artifact with packaging=pom.
+    It only declares further dependencies which should be shaded
+    into the final uberwar.
+  </description>
+
+  <dependencies>
+    <!-- NOTE: The test requires a dependency to include during shading, 
doesn't matter what classes though -->
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-compiler-plugin</artifactId>
+      <version>2.0.2</version>
+    </dependency>
+  </dependencies>
+  
+</project>

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/pomDependency/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/pom.xml?rev=812606&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/pom.xml
 Tue Sep  8 18:22:25 2009
@@ -0,0 +1,71 @@
+<?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.its.shade.spom</groupId>
+  <artifactId>shadingModule</artifactId>
+  <version>1.0</version>
+
+
+  <name>MSHADE-60 :: dependency to a type=pom artifact</name>
+  <description>
+    This module creates the uberwar containing an artifact which may not 
+    be handled by the JarFile like e.g. a depending pom.
+    The artifact with packaging=pom we depend on has several other  
+    artifacts as dependencies. Those artifacts should be contained 
+    in the shade-artifact finally.
+  </description>
+
+  <dependencies>
+    <dependency>
+         <groupId>org.apache.maven.its.shade.spom</groupId>
+         <artifactId>pomDependency</artifactId>
+         <version>1.0</version>
+         <type>pom</type>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>create-shaded-artifact</id>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <shadedArtifactAttached>true</shadedArtifactAttached>
+              <shadedClassifierName>shaded</shadedClassifierName>
+              <createDependencyReducedPom>false</createDependencyReducedPom>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/shadingModule/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/pom.xml?rev=812606&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/pom.xml
 Tue Sep  8 18:22:25 2009
@@ -0,0 +1,45 @@
+<?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.its.shade.spom</groupId>
+  <artifactId>testModule</artifactId>
+  <version>1.0</version>
+
+  <name>MSHADE-60 :: dependency to a type=pom artifact</name>
+  <description>
+    This module uses the shaded artifact and tries to import a package from
+    the shaded module
+  </description>
+
+  <dependencies>
+    <dependency>
+         <groupId>org.apache.maven.its.shade.spom</groupId>
+         <artifactId>shadingModule</artifactId>
+         <version>1.0</version>
+         <classifier>shaded</classifier>
+    </dependency>
+  </dependencies>
+  
+  
+</project>

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/ShadedClassUsage.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/ShadedClassUsage.java?rev=812606&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/ShadedClassUsage.java
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/ShadedClassUsage.java
 Tue Sep  8 18:22:25 2009
@@ -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.
+ */
+
+public class ShadedClassUsage
+{
+    public static void main() throws Exception
+    {
+        Class cmClass = Class.forName( "org.apache.maven.plugin.CompilerMojo", 
true, 
+                                       
Thread.currentThread().getContextClassLoader() );
+    }
+}
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/ShadedClassUsage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/shadePomDependency/testModule/src/main/java/ShadedClassUsage.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java?rev=812606&r1=812605&r2=812606&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
 Tue Sep  8 18:22:25 2009
@@ -69,7 +69,18 @@
 
             List jarFilters = getFilters( jar, filters );
 
-            JarFile jarFile = new JarFile( jar );
+            JarFile jarFile;
+            
+            try 
+            {
+                jarFile = new JarFile( jar );
+            }
+            catch (ZipException zex)
+            {
+                // JarFile is not very verbose and doesn't tell the user which 
file it was
+                // so we will create a new Exception instead
+                throw new ZipException( "error in opening zip file" + jar );
+            }
 
             for ( Enumeration j = jarFile.entries(); j.hasMoreElements(); )
             {

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java?rev=812606&r1=812605&r2=812606&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
 Tue Sep  8 18:22:25 2009
@@ -332,6 +332,12 @@
 
                 continue;
             }
+            
+            if ( artifact.getType().equals( "pom" ) )
+            {
+                getLog().info( "Skipping pom dependency " + artifact.getId() + 
" in the shaded jar." );
+                continue;
+            }
 
             getLog().info( "Including " + artifact.getId() + " in the shaded 
jar." );
 


Reply via email to