You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2015/05/29 23:08:26 UTC

svn commit: r1682553 - in /maven/plugins/trunk/maven-shade-plugin/src: it/MSHADE-183/ it/MSHADE-183/pom.xml it/MSHADE-183/verify.bsh main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java

Author: khmarbaise
Date: Fri May 29 21:08:26 2015
New Revision: 1682553

URL: http://svn.apache.org/r1682553
Log:
[MSHADE-183] Getting "Error creating shaded jar: java.util.jar.Attributes
Added an appropriate IT and applied the given patch

Added:
    maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/
    maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/pom.xml
    maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/verify.bsh
Modified:
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java

Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/pom.xml?rev=1682553&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/pom.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/pom.xml Fri May 29 21:08:26 2015
@@ -0,0 +1,110 @@
+<?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.mt</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <name>MSHADE-183</name>
+  <description>
+    Test that reproduces the issue described in MSHADE-183.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <!-- dummy dependency to test interaction of multiple manifests -->
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-shade-plugin</artifactId>
+      <version>@project.version@</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.2</version>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>org.apache.maven.Main</mainClass>
+            </manifest>
+            <manifestEntries>
+              <Test-Entry>FAILED</Test-Entry>
+              <Original-Entry>PASSED</Original-Entry>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>attach-shade</id>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <shadedArtifactAttached>false</shadedArtifactAttached>
+              <transformers>
+                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                  <mainClass>org.apache.maven.Shade</mainClass>
+                  <manifestEntries>
+                    <Test-Entry>PASSED</Test-Entry>
+                    <Implementation-Build></Implementation-Build>
+                  </manifestEntries>
+                </transformer>
+              </transformers>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/verify.bsh?rev=1682553&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/verify.bsh (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-183/verify.bsh Fri May 29 21:08:26 2015
@@ -0,0 +1,49 @@
+/*
+ * 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.io.*;
+import java.util.jar.*;
+
+// NOTE: We deliberately use JarInputStream and not JarFile here!
+JarInputStream jarStream = new JarInputStream( new FileInputStream( new File( basedir, "target/test-1.0.jar" ) ) );
+Manifest mf = jarStream.getManifest();
+jarStream.close();
+
+if ( mf == null )
+{
+    throw new IllegalStateException( "META-INF/MANIFEST.MF is missing" );
+}
+
+if ( !"PASSED".equals( mf.getMainAttributes().getValue( "Test-Entry" ) ) )
+{
+    throw new IllegalStateException( "META-INF/MANIFEST.MF is incomplete" );
+}
+
+if ( !"PASSED".equals( mf.getMainAttributes().getValue( "Original-Entry" ) ) )
+{
+    throw new IllegalStateException( "META-INF/MANIFEST.MF is incomplete" );
+}
+
+if ( !"org.apache.maven.Shade".equals( mf.getMainAttributes().getValue( "Main-Class" ) ) )
+{
+    throw new IllegalStateException( "META-INF/MANIFEST.MF is incomplete" );
+}
+if ( !"null".equals( mf.getMainAttributes().getValue( "Implementation-Build" ) ) )
+{
+    throw new IllegalStateException( "META-INF/MANIFEST.MF Implementation-Build content is not null as expected." );
+}

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java?rev=1682553&r1=1682552&r2=1682553&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java (original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java Fri May 29 21:08:26 2015
@@ -47,7 +47,7 @@ public class ManifestResourceTransformer
     // Configuration
     private String mainClass;
 
-    private Map<String, Attributes> manifestEntries;
+    private Map<String, Object> manifestEntries;
 
     // Fields
     private boolean manifestDiscovered;
@@ -101,7 +101,7 @@ public class ManifestResourceTransformer
 
         if ( manifestEntries != null )
         {
-            for ( Map.Entry<String, Attributes> entry : manifestEntries.entrySet() )
+            for ( Map.Entry<String, Object> entry : manifestEntries.entrySet() )
             {
                 attributes.put( new Attributes.Name( entry.getKey() ), entry.getValue() );
             }