You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/10/06 00:21:05 UTC

svn commit: r1179463 - in /webservices/commons/trunk/modules/axiom: ./ modules/axiom-buildutils/ modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/ modules/axiom-dom/ modules/axiom-impl/ modules/shade-plugin-patched/ modules/shade-plug...

Author: veithen
Date: Wed Oct  5 22:21:04 2011
New Revision: 1179463

URL: http://svn.apache.org/viewvc?rev=1179463&view=rev
Log:
Implemented a workaround for MSHADE-105. This should partially solve AXIS2-5145.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/pom.xml   (with props)
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/plugins/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/plugins/shade/
    webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
      - copied, changed from r1179434, maven/plugins/tags/maven-shade-plugin-1.4/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/pom.xml
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml
    webservices/commons/trunk/modules/axiom/pom.xml

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/pom.xml?rev=1179463&r1=1179462&r2=1179463&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/pom.xml Wed Oct  5 22:21:04 2011
@@ -43,6 +43,8 @@
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-shade-plugin</artifactId>
             <version>${shade.plugin.version}</version>
+            <!-- This avoids conflicts with our patched version of the plugin -->
+            <scope>provided</scope>
         </dependency>
     </dependencies>
 </project>

Added: webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java?rev=1179463&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java Wed Oct  5 22:21:04 2011
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.buildutils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.maven.plugins.shade.resource.ResourceTransformer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * Quick and dirty hack to adjust the groupId/artifactId/version in a shaded Maven plugin.
+ */
+public class PluginXmlResourceTransformer implements ResourceTransformer {
+    private static final String PLUGIN_XML = "META-INF/maven/plugin.xml";
+    
+    String groupId;
+    String artifactId;
+    String version;
+    
+    private Document pluginXml;
+
+    public boolean canTransformResource(String resource) {
+        return resource.equals(PLUGIN_XML);
+    }
+
+    public boolean hasTransformedResource() {
+        return pluginXml != null;
+    }
+
+    public void processResource(String resource, InputStream is, List relocators) throws IOException {
+        try {
+            pluginXml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
+        } catch (SAXException ex) {
+            throw toIOException(ex);
+        } catch (ParserConfigurationException ex) {
+            throw toIOException(ex);
+        }
+        is.close();
+        Node node = pluginXml.getDocumentElement().getFirstChild();
+        while (node != null) {
+            if (node instanceof Element) {
+                Element element = (Element)node;
+                String name = element.getTagName();
+                if (name.equals("groupId")) {
+                    element.setTextContent(groupId);
+                } else if (name.equals("artifactId")) {
+                    element.setTextContent(artifactId);
+                } else if (name.equals("version")) {
+                    element.setTextContent(version);
+                }
+            }
+            node = node.getNextSibling();
+        }
+    }
+
+    public void modifyOutputStream(JarOutputStream os) throws IOException {
+        os.putNextEntry(new JarEntry(PLUGIN_XML));
+        try {
+            TransformerFactory.newInstance().newTransformer().transform(new DOMSource(pluginXml), new StreamResult(os));
+        } catch (TransformerException ex) {
+            throw toIOException(ex);
+        }
+    }
+    
+    private IOException toIOException(Exception ex) {
+        IOException ioException = new IOException();
+        ioException.initCause(ex);
+        return ioException;
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml?rev=1179463&r1=1179462&r2=1179463&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml Wed Oct  5 22:21:04 2011
@@ -141,7 +141,9 @@
                 <artifactId>maven-scr-plugin</artifactId>
             </plugin>
             <plugin>
-                <artifactId>maven-shade-plugin</artifactId>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>shade-plugin-patched</artifactId>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <phase>package</phase>

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml?rev=1179463&r1=1179462&r2=1179463&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml Wed Oct  5 22:21:04 2011
@@ -135,7 +135,9 @@
                 <artifactId>maven-scr-plugin</artifactId>
             </plugin>
             <plugin>
-                <artifactId>maven-shade-plugin</artifactId>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>shade-plugin-patched</artifactId>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <phase>package</phase>

Added: webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/pom.xml?rev=1179463&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/pom.xml (added)
+++ webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/pom.xml Wed Oct  5 22:21:04 2011
@@ -0,0 +1,99 @@
+<?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>
+    <parent>
+        <groupId>org.apache.ws.commons.axiom</groupId>
+        <artifactId>axiom-parent</artifactId>
+        <version>1.2.13-SNAPSHOT</version>
+        <relativePath>../axiom-parent/pom.xml</relativePath>
+    </parent>
+    <artifactId>shade-plugin-patched</artifactId>
+    <name>Maven Shade Plugin (patched)</name>
+    <description>Patched version of maven-shade-plugin to work around MSHADE-105</description>
+    <packaging>maven-plugin</packaging>
+    <!-- This needs to be set explicitly because the project structure implies that the Maven calculated defaults are wrong -->
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched</developerConnection>
+        <url>http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched</url>
+    </scm>
+    <!-- This also needs to be set explicitly because the Maven calculated URL would point to nowhere -->
+    <url>http://ws.apache.org/axiom/</url>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-shade-plugin</artifactId>
+            <version>${shade.plugin.version}</version>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-plugin-plugin</artifactId>
+                <configuration>
+                    <!-- There are no mojos to extract -->
+                    <skipDescriptor>true</skipDescriptor>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <artifactSet>
+                                <includes>
+                                    <include>org.apache.maven.plugins:maven-shade-plugin</include>
+                                </includes>
+                            </artifactSet>
+                            <filters>
+                                <filter>
+                                    <artifact>org.apache.maven.plugins:maven-shade-plugin</artifact>
+                                    <excludes>
+                                        <exclude>org/apache/maven/plugins/shade/DefaultShader*</exclude>
+                                    </excludes>
+                                </filter>
+                            </filters>
+                            <transformers>
+                                <transformer implementation="org.apache.axiom.buildutils.PluginXmlResourceTransformer">
+                                    <groupId>${project.groupId}</groupId>
+                                    <artifactId>${project.artifactId}</artifactId>
+                                    <version>${project.version}</version>
+                                </transformer>
+                            </transformers>
+                            <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+                <dependencies>
+                    <dependency>
+                        <groupId>${project.groupId}</groupId>
+                        <artifactId>axiom-buildutils</artifactId>
+                        <version>${project.version}</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Propchange: webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java (from r1179434, maven/plugins/tags/maven-shade-plugin-1.4/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java?p2=webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java&p1=maven/plugins/tags/maven-shade-plugin-1.4/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java&r1=1179434&r2=1179463&rev=1179463&view=diff
==============================================================================
--- maven/plugins/tags/maven-shade-plugin-1.4/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/shade-plugin-patched/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java Wed Oct  5 22:21:04 2011
@@ -260,7 +260,12 @@ public class DefaultShader
 
         ClassReader cr = new ClassReader( is );
 
-        ClassWriter cw = new ClassWriter( cr, 0 );
+        // We don't pass the ClassReader here. This forces the ClassWriter to rebuild the constant pool.
+        // Copying the original constant pool should be avoided because it would keep references
+        // to the original class names. This is not a problem at runtime (because these entries in the
+        // constant pool are never used), but confuses some tools such as Felix' maven-bundle-plugin
+        // that use the constant pool to determine the dependencies of a class.
+        ClassWriter cw = new ClassWriter( 0 );
 
         ClassVisitor cv = new TempRemappingClassAdapter( cw, remapper );
 

Modified: webservices/commons/trunk/modules/axiom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/pom.xml?rev=1179463&r1=1179462&r2=1179463&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/pom.xml Wed Oct  5 22:21:04 2011
@@ -546,6 +546,7 @@
     <modules>
         <module>modules/axiom-parent</module>
         <module>modules/axiom-buildutils</module>
+        <module>modules/shade-plugin-patched</module>
         <module>modules/axiom-testutils</module>
         <module>modules/axiom-jaxen-testsuite</module>
         <module>modules/axiom-dom-testsuite</module>