myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jak...@apache.org
Subject svn commit: r1004830 - in /myfaces/extensions/cdi/trunk: ./ dist/jsf12/ dist/jsf20/ maven-utils/ maven-utils/src/ maven-utils/src/main/ maven-utils/src/main/java/ maven-utils/src/main/java/org/ maven-utils/src/main/java/org/apache/ maven-utils/src/main...
Date Tue, 05 Oct 2010 22:07:09 GMT
Author: jakobk
Date: Tue Oct  5 22:07:09 2010
New Revision: 1004830

URL: http://svn.apache.org/viewvc?rev=1004830&view=rev
Log:
add maven-utils module and an BeansXmlTransformer for correctly merging beans.xml files in
the shade-plugin

Added:
    myfaces/extensions/cdi/trunk/maven-utils/   (with props)
    myfaces/extensions/cdi/trunk/maven-utils/pom.xml
    myfaces/extensions/cdi/trunk/maven-utils/src/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/maven/
    myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/maven/BeansXmlTransformer.java
    myfaces/extensions/cdi/trunk/maven-utils/src/main/resources/
Modified:
    myfaces/extensions/cdi/trunk/dist/jsf12/pom.xml
    myfaces/extensions/cdi/trunk/dist/jsf20/pom.xml
    myfaces/extensions/cdi/trunk/pom.xml

Modified: myfaces/extensions/cdi/trunk/dist/jsf12/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/dist/jsf12/pom.xml?rev=1004830&r1=1004829&r2=1004830&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/dist/jsf12/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/dist/jsf12/pom.xml Tue Oct  5 22:07:09 2010
@@ -129,11 +129,19 @@
                     <createSourcesJar>true</createSourcesJar>
                     <transformers>
                         <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
-                        <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
+                        <transformer implementation="org.apache.myfaces.extensions.cdi.maven.BeansXmlTransformer">
                             <resource>META-INF/beans.xml</resource>
                         </transformer>
                     </transformers>
                 </configuration>
+
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.myfaces.extensions.cdi</groupId>
+                        <artifactId>myfaces-extcdi-maven-utils</artifactId>
+                        <version>${project.version}</version>
+                    </dependency>
+                </dependencies>
             </plugin>
         </plugins>
     </build>

Modified: myfaces/extensions/cdi/trunk/dist/jsf20/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/dist/jsf20/pom.xml?rev=1004830&r1=1004829&r2=1004830&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/dist/jsf20/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/dist/jsf20/pom.xml Tue Oct  5 22:07:09 2010
@@ -129,11 +129,19 @@
                     <createSourcesJar>true</createSourcesJar>
                     <transformers>
                         <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
-                        <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
+                        <transformer implementation="org.apache.myfaces.extensions.cdi.maven.BeansXmlTransformer">
                             <resource>META-INF/beans.xml</resource>
                         </transformer>
                     </transformers>
                 </configuration>
+
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.myfaces.extensions.cdi</groupId>
+                        <artifactId>myfaces-extcdi-maven-utils</artifactId>
+                        <version>${project.version}</version>
+                    </dependency>
+                </dependencies>
             </plugin>
         </plugins>
     </build>

Propchange: myfaces/extensions/cdi/trunk/maven-utils/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct  5 22:07:09 2010
@@ -0,0 +1,10 @@
+target
+.metadata
+.classpath
+.project
+.settings
+*.iml
+*.ipr
+*.iws
+.git
+.gitignore

Added: myfaces/extensions/cdi/trunk/maven-utils/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/maven-utils/pom.xml?rev=1004830&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/maven-utils/pom.xml (added)
+++ myfaces/extensions/cdi/trunk/maven-utils/pom.xml Tue Oct  5 22:07:09 2010
@@ -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>
+
+    <packaging>jar</packaging>
+
+    <groupId>org.apache.myfaces.extensions.cdi</groupId>
+    <artifactId>myfaces-extcdi-maven-utils</artifactId>
+
+    <name>MyFaces Extensions-CDI Maven Utils</name>
+    <version>1.0.0-SNAPSHOT</version>
+
+    <parent>
+        <groupId>org.apache.myfaces.extensions.cdi</groupId>
+        <artifactId>myfaces-extcdi-parent</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-shade-plugin</artifactId>
+            <version>1.3.3</version>
+        </dependency>
+    </dependencies>
+
+</project>

Added: myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/maven/BeansXmlTransformer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/maven/BeansXmlTransformer.java?rev=1004830&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/maven/BeansXmlTransformer.java
(added)
+++ myfaces/extensions/cdi/trunk/maven-utils/src/main/java/org/apache/myfaces/extensions/cdi/maven/BeansXmlTransformer.java
Tue Oct  5 22:07:09 2010
@@ -0,0 +1,160 @@
+/*
+ * 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.myfaces.extensions.cdi.maven;
+
+import org.apache.maven.plugins.shade.resource.ResourceTransformer;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+/**
+ * A resource transformer for the maven shade-plugin which
+ * processes beans.xml files correctly.
+ *
+ * Most of the code is taken from the XmlAppendingTransformer from the shade-plugin.
+ */
+public class BeansXmlTransformer implements ResourceTransformer
+{
+    public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
+
+    boolean ignoreDtd = true;
+
+    String resource;
+
+    Document doc;
+
+    public boolean canTransformResource(String r)
+    {
+        if (resource != null && resource.equalsIgnoreCase(r))
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    public void processResource(String resource, InputStream is, List relocators)
+            throws IOException
+    {
+        Document r;
+        try
+        {
+            SAXBuilder builder = new SAXBuilder(false);
+            builder.setExpandEntities(false);
+            if (ignoreDtd)
+            {
+                builder.setEntityResolver(new EntityResolver()
+                {
+                    public InputSource resolveEntity(String publicId, String systemId)
+                            throws SAXException, IOException
+                    {
+                        return new InputSource(new StringReader(""));
+                    }
+                });
+            }
+            r = builder.build(is);
+        }
+        catch (JDOMException e)
+        {
+            throw new RuntimeException(e);
+        }
+
+        if (doc == null)
+        {
+            doc = r;
+        }
+        else
+        {
+            Element root = r.getRootElement();
+
+            for (Iterator itr = root.getAttributes().iterator(); itr.hasNext();)
+            {
+                Attribute a = (Attribute) itr.next();
+                itr.remove();
+
+                Element mergedEl = doc.getRootElement();
+                Attribute mergedAtt = mergedEl.getAttribute(a.getName(), a.getNamespace());
+                if (mergedAtt == null)
+                {
+                    mergedEl.setAttribute(a);
+                }
+            }
+
+            Element docRoot = doc.getRootElement();
+
+            for (Iterator itr = root.getChildren().iterator(); itr.hasNext();)
+            {
+                Element child = (Element) itr.next();
+                itr.remove();
+
+                // check if the given element already exists as a child of the
+                // root element and if so, only add the grandchildren to the
+                // already existing child and not the whole child again
+                Element docChild = docRoot.getChild(child.getName(), child.getNamespace());
+                if (docChild != null)
+                {
+                    // the docRoot already has this child
+                    // --> add the grandchildren to the existing element
+                    for (Iterator childrenItr = child.getChildren().iterator(); childrenItr.hasNext();)
+                    {
+                        Element grandchild = (Element) childrenItr.next();
+                        childrenItr.remove();
+
+                        docChild.addContent(grandchild);
+                    }
+                }
+                else
+                {
+                    // the docRoot does not have this child yet
+                    docRoot.addContent(child);
+                }
+            }
+        }
+    }
+
+    public boolean hasTransformedResource()
+    {
+        return doc != null;
+    }
+
+    public void modifyOutputStream(JarOutputStream jos)
+            throws IOException
+    {
+        jos.putNextEntry(new JarEntry(resource));
+
+        new XMLOutputter(Format.getPrettyFormat()).output(doc, jos);
+
+        doc = null;
+    }
+}

Modified: myfaces/extensions/cdi/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/pom.xml?rev=1004830&r1=1004829&r2=1004830&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/pom.xml Tue Oct  5 22:07:09 2010
@@ -71,6 +71,7 @@
 
     <modules>
         <module>site</module>
+        <module>maven-utils</module>
         <module>core</module>
         <module>jee-modules</module>
         <module>jse-modules</module>



Mime
View raw message