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/09 14:13:36 UTC
svn commit: r1180590 - in /webservices/axiom/branches/osgi-redesign/modules:
axiom-all/ axiom-buildutils/src/main/java/org/apache/axiom/buildutils/
Author: veithen
Date: Sun Oct 9 12:13:35 2011
New Revision: 1180590
URL: http://svn.apache.org/viewvc?rev=1180590&view=rev
Log:
Added a resource transformer for META-INF/axiom.xml to make the uber-JAR work with the new implementation discovery strategy.
Added:
webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/AxiomXmlResourceTransformer.java (with props)
webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/DOMUtils.java (with props)
Modified:
webservices/axiom/branches/osgi-redesign/modules/axiom-all/pom.xml
webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java
Modified: webservices/axiom/branches/osgi-redesign/modules/axiom-all/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/osgi-redesign/modules/axiom-all/pom.xml?rev=1180590&r1=1180589&r2=1180590&view=diff
==============================================================================
--- webservices/axiom/branches/osgi-redesign/modules/axiom-all/pom.xml (original)
+++ webservices/axiom/branches/osgi-redesign/modules/axiom-all/pom.xml Sun Oct 9 12:13:35 2011
@@ -77,9 +77,19 @@
<include>${project.groupId}:*</include>
</includes>
</artifactSet>
+ <transformers>
+ <transformer implementation="org.apache.axiom.buildutils.AxiomXmlResourceTransformer" />
+ </transformers>
</configuration>
</execution>
</executions>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axiom-buildutils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</plugin>
<plugin>
<!-- If we deploy the uber-JAR to the Maven repositories, then we will end up with
Added: webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/AxiomXmlResourceTransformer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/AxiomXmlResourceTransformer.java?rev=1180590&view=auto
==============================================================================
--- webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/AxiomXmlResourceTransformer.java (added)
+++ webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/AxiomXmlResourceTransformer.java Sun Oct 9 12:13:35 2011
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.maven.plugins.shade.resource.ResourceTransformer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Merges <tt>META-INF/axiom.xml</tt> files.
+ */
+public class AxiomXmlResourceTransformer implements ResourceTransformer {
+ private static final String AXIOM_XML = "META-INF/axiom.xml";
+
+ private Document mergedAxiomXml;
+
+ public boolean canTransformResource(String resource) {
+ return resource.equals(AXIOM_XML);
+ }
+
+ public boolean hasTransformedResource() {
+ return mergedAxiomXml != null;
+ }
+
+ public void processResource(String resource, InputStream is, List relocators) throws IOException {
+ Document axiomXml = DOMUtils.parse(is);
+ is.close();
+ if (mergedAxiomXml == null) {
+ mergedAxiomXml = axiomXml;
+ } else {
+ for (Node node = axiomXml.getDocumentElement().getFirstChild(); node != null; node = node.getNextSibling()) {
+ mergedAxiomXml.getDocumentElement().appendChild(mergedAxiomXml.importNode(node, true));
+ }
+ }
+ }
+
+ public void modifyOutputStream(JarOutputStream os) throws IOException {
+ os.putNextEntry(new JarEntry(AXIOM_XML));
+ DOMUtils.serialize(mergedAxiomXml, os);
+ }
+}
Propchange: webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/AxiomXmlResourceTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/DOMUtils.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/DOMUtils.java?rev=1180590&view=auto
==============================================================================
--- webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/DOMUtils.java (added)
+++ webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/DOMUtils.java Sun Oct 9 12:13:35 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.io.OutputStream;
+
+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.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public final class DOMUtils {
+ private DOMUtils() {}
+
+ public static Document parse(InputStream is) throws IOException {
+ try {
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
+ } catch (SAXException ex) {
+ throw toIOException(ex);
+ } catch (ParserConfigurationException ex) {
+ throw toIOException(ex);
+ }
+ }
+
+ public static void serialize(Document document, OutputStream os) throws IOException {
+ try {
+ TransformerFactory.newInstance().newTransformer().transform(new DOMSource(document), new StreamResult(os));
+ } catch (TransformerException ex) {
+ throw toIOException(ex);
+ }
+ }
+
+ private static IOException toIOException(Exception ex) {
+ IOException ioException = new IOException();
+ ioException.initCause(ex);
+ return ioException;
+ }
+}
Propchange: webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/DOMUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java?rev=1180590&r1=1180589&r2=1180590&view=diff
==============================================================================
--- webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java (original)
+++ webservices/axiom/branches/osgi-redesign/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/PluginXmlResourceTransformer.java Sun Oct 9 12:13:35 2011
@@ -24,18 +24,10 @@ 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.
@@ -58,13 +50,7 @@ public class PluginXmlResourceTransforme
}
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);
- }
+ pluginXml = DOMUtils.parse(is);
is.close();
Node node = pluginXml.getDocumentElement().getFirstChild();
while (node != null) {
@@ -85,16 +71,6 @@ public class PluginXmlResourceTransforme
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;
+ DOMUtils.serialize(pluginXml, os);
}
}