Author: brett
Date: Thu Jul  3 22:01:25 2008
New Revision: 673904

URL: http://svn.apache.org/viewvc?rev=673904&view=rev
Log:
[MSHADE-35] basic component definition merging for adding a configuration 
element if it wasn't already present

Added:
    
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
   (with props)
    maven/plugins/trunk/maven-shade-plugin/src/test/resources/
    maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-1.xml  
 (with props)
    maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-2.xml  
 (with props)
    
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-expected.xml
   (with props)
Modified:
    
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java?rev=673904&r1=673903&r2=673904&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java
 Thu Jul  3 22:01:25 2008
@@ -107,7 +107,20 @@
 
             String roleHint = child != null ? child.getValue() : "";
 
-            components.put( role + roleHint, component );
+            String key = role+roleHint;
+            if ( components.containsKey( key ) )
+            {
+                // TODO: use the tools in Plexus to merge these properly. For 
now, I just need an all-or-nothing
+                // configuration carry over
+                
+                Xpp3Dom dom = (Xpp3Dom) components.get( key );
+                if ( dom.getChild( "configuration" ) != null )
+                {
+                    component.addChild( dom.getChild( "configuration" ) );
+                }
+            }
+            
+            components.put( key, component );
         }
     }
 

Added: 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java?rev=673904&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
 Thu Jul  3 22:01:25 2008
@@ -0,0 +1,53 @@
+package org.apache.maven.plugins.shade.resource;
+
+/*
+ * 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.IOException;
+
+import junit.framework.TestCase;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Test for [EMAIL PROTECTED] ComponentsXmlResourceTransformer}.
+ * 
+ * @author Brett Porter
+ * @version $Id: XmlAppendingTransformerTest.java 644743 2008-04-04 15:52:02Z 
bentmann $
+ */
+public class ComponentsXmlResourceTransformerTest
+    extends TestCase
+{
+    private ComponentsXmlResourceTransformer transformer;
+
+    public void setUp()
+    {
+        this.transformer = new ComponentsXmlResourceTransformer();
+    }
+
+    public void testConfigurationMerging() throws IOException
+    {
+        transformer.processResource( getClass().getResourceAsStream( 
"/components-1.xml" ) );
+        transformer.processResource( getClass().getResourceAsStream( 
"/components-2.xml" ) );
+        
+        assertEquals( IOUtil.toString( getClass().getResourceAsStream( 
"/components-expected.xml" ) ),
+                      FileUtils.fileRead( transformer.getTransformedResource() 
) );
+    }
+}

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-1.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-1.xml?rev=673904&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-1.xml 
(added)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-1.xml 
Thu Jul  3 22:01:25 2008
@@ -0,0 +1,48 @@
+<!--
+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.
+-->
+
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>http</role-hint>
+      
<implementation>org.apache.maven.wagon.providers.http.LightweightHttpWagon</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <description>LightweightHttpWagon</description>
+      <isolated-realm>false</isolated-realm>
+    </component>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>https</role-hint>
+      
<implementation>org.apache.maven.wagon.providers.http.LightweightHttpsWagon</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <description>LIghtweightHttpsWagon</description>
+      <isolated-realm>false</isolated-realm>
+      <configuration>
+        <httpHeaders>
+          <property>
+            <name>User-Agent</name>
+            <value>Apache Maven/${project.version}</value>
+          </property>
+        </httpHeaders>
+      </configuration>
+    </component>
+  </components>
+</component-set>
+    
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-2.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-2.xml?rev=673904&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-2.xml 
(added)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-2.xml 
Thu Jul  3 22:01:25 2008
@@ -0,0 +1,48 @@
+<!--
+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.
+-->
+
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>http</role-hint>
+      
<implementation>org.apache.maven.wagon.providers.http.LightweightHttpWagon</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <description>LightweightHttpWagon</description>
+      <isolated-realm>false</isolated-realm>
+      <configuration>
+        <httpHeaders>
+          <property>
+            <name>User-Agent</name>
+            <value>Apache Maven/${project.version}</value>
+          </property>
+        </httpHeaders>
+      </configuration>
+    </component>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>https</role-hint>
+      
<implementation>org.apache.maven.wagon.providers.http.LightweightHttpsWagon</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <description>LIghtweightHttpsWagon</description>
+      <isolated-realm>false</isolated-realm>
+    </component>
+  </components>
+</component-set>
+    
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-expected.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-expected.xml?rev=673904&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-expected.xml
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-expected.xml
 Thu Jul  3 22:01:25 2008
@@ -0,0 +1,36 @@
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>http</role-hint>
+      
<implementation>org.apache.maven.wagon.providers.http.LightweightHttpWagon</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <description>LightweightHttpWagon</description>
+      <isolated-realm>false</isolated-realm>
+      <configuration>
+        <httpHeaders>
+          <property>
+            <name>User-Agent</name>
+            <value>Apache Maven/${project.version}</value>
+          </property>
+        </httpHeaders>
+      </configuration>
+    </component>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>https</role-hint>
+      
<implementation>org.apache.maven.wagon.providers.http.LightweightHttpsWagon</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <description>LIghtweightHttpsWagon</description>
+      <isolated-realm>false</isolated-realm>
+      <configuration>
+        <httpHeaders>
+          <property>
+            <name>User-Agent</name>
+            <value>Apache Maven/${project.version}</value>
+          </property>
+        </httpHeaders>
+      </configuration>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/test/resources/components-expected.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to