]> source.dussan.org Git - archiva.git/commitdiff
fix support for PlexucConfiguration injection
authorNicolas De Loof <nicolas@apache.org>
Thu, 28 Feb 2008 13:14:18 +0000 (13:14 +0000)
committerNicolas De Loof <nicolas@apache.org>
Thu, 28 Feb 2008 13:14:18 +0000 (13:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@631954 13f79535-47bb-0310-9956-ffa450edef68

springy/plexus-spring/pom.xml
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusNamespaceHandler.java
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusToSpringUtils.java
springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ConfigPlexusBean.java [new file with mode: 0644]
springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
springy/plexus-spring/src/test/resources/testInjectPlexusConfiguration.xml [new file with mode: 0644]

index b9fc5dfccd6266fd391933055489650624f4db08..8453dccbfa8131a9104ac925158f8833ece77ab2 100644 (file)
       <version>1.0-alpha-22</version>\r
     </dependency>\r
     <dependency>\r
-      <!-- only required to debug XSLT result -->\r
       <groupId>dom4j</groupId>\r
       <artifactId>dom4j</artifactId>\r
       <version>1.6.1</version>\r
-      <optional>true</optional>\r
     </dependency>\r
     <dependency>\r
       <groupId>junit</groupId>\r
index f2bd24113417f840aac8bde0ece5911d46ef4260..ff0dedd18b705c101ccd77d634175e440701b312 100644 (file)
@@ -36,14 +36,11 @@ import org.springframework.context.ConfigurableApplicationContext;
 public class PlexusInSpringTestCase
     extends TestCase
 {
-    private static String basedir;
-
     private ConfigurableApplicationContext applicationContext;
 
     protected void setUp()
         throws Exception
     {
-        basedir = getBasedir();
         applicationContext =
             new PlexusClassPathXmlApplicationContext( new String[] {
                 "classpath*:META-INF/plexus/components.xml",
@@ -79,18 +76,7 @@ public class PlexusInSpringTestCase
 
     public static String getBasedir()
     {
-        if ( basedir != null )
-        {
-            return basedir;
-        }
-
-        basedir = System.getProperty( "basedir" );
-        if ( basedir == null )
-        {
-            basedir = new File( "" ).getAbsolutePath();
-        }
-
-        return basedir;
+        return PlexusToSpringUtils.getBasedir();
     }
 
     public String getTestConfiguration()
@@ -128,7 +114,7 @@ public class PlexusInSpringTestCase
 
     public static File getTestFile( String path )
     {
-        return new File( getBasedir(), path );
+        return new File( PlexusToSpringUtils.getBasedir(), path );
     }
 
     public static File getTestFile( String basedir,
index 0bc6cf072ba947b06a66ee3256c610551e006727..fa5f1deaa0bc8f907792e8e138b5262d9af3ab1b 100644 (file)
@@ -35,6 +35,7 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
 import javax.xml.transform.dom.DOMSource;\r
 import javax.xml.transform.stream.StreamResult;\r
 \r
+import org.apache.commons.lang.StringUtils;\r
 import org.dom4j.io.DOMReader;\r
 import org.dom4j.io.SAXReader;\r
 import org.springframework.beans.factory.BeanDefinitionStoreException;\r
@@ -126,16 +127,21 @@ public class PlexusNamespaceHandler
             {\r
                 Element child = (Element) iterator.next();\r
                 String name = child.getAttribute( "name" );\r
+                String value;\r
                 if ( child.getChildNodes().getLength() == 1 )\r
                 {\r
-                    dependencies.put( name, child.getTextContent() );\r
+                    value = child.getTextContent();\r
                 }\r
                 else\r
                 {\r
                     StringWriter xml = new StringWriter();\r
-                    flatten( child, new PrintWriter( xml ) );\r
-                    dependencies.put( name, xml.toString() );\r
+                    xml.write( '<' + name + '>' );\r
+                    flatten( child.getChildNodes(), new PrintWriter( xml ) );\r
+                    xml.write( "</" + name + '>' );\r
+                    value = xml.toString();\r
                 }\r
+                value = StringUtils.replace( value, "${basedir}", PlexusToSpringUtils.getBasedir() );\r
+                dependencies.put( name, value );\r
             }\r
 \r
             builder.addPropertyValue( "requirements", dependencies );\r
@@ -188,6 +194,11 @@ public class PlexusNamespaceHandler
             out.print( attribute.getTextContent() );\r
             out.print( "\"" );\r
         }\r
+        if (el.getChildNodes().getLength() == 0)\r
+        {\r
+            out.print( "/>" );\r
+            return;\r
+        }\r
         out.print( '>' );\r
         flatten( el.getChildNodes(), out );\r
         out.print( "</" );\r
index 366ce1ce55661af65902b5c1bb6ae4994788e075..0c021528e7230d84bd1128255e1a5fc9f085aa59 100644 (file)
@@ -19,6 +19,7 @@ package org.codehaus.plexus.spring;
  * under the License.\r
  */\r
 \r
+import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.List;\r
@@ -141,4 +142,22 @@ public class PlexusToSpringUtils
     {\r
         return new ArrayList( PlexusToSpringUtils.lookupMap( role, beanFactory ).values() );\r
     }\r
+\r
+    private static String basedir;\r
+\r
+    public static String getBasedir()\r
+    {\r
+        if ( basedir != null )\r
+        {\r
+            return basedir;\r
+        }\r
+\r
+        basedir = System.getProperty( "basedir" );\r
+        if ( basedir == null )\r
+        {\r
+            basedir = new File( "" ).getAbsolutePath();\r
+        }\r
+\r
+        return basedir;\r
+    }\r
 }\r
diff --git a/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ConfigPlexusBean.java b/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ConfigPlexusBean.java
new file mode 100644 (file)
index 0000000..1ab944b
--- /dev/null
@@ -0,0 +1,43 @@
+package org.codehaus.plexus.spring;
+
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+/*
+ * 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.
+ */
+
+/**
+ * A typical plexus component implementation
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class ConfigPlexusBean
+{
+    private PlexusConfiguration config;
+
+    public PlexusConfiguration getConfig()
+    {
+        return config;
+    }
+
+
+
+}
index 59c71433d8977957841eda7b8b49cc03ac6d7747..7d57730c6e0c13185816fac80ebb715ce3e30e92 100644 (file)
@@ -88,4 +88,14 @@ public class PlexusClassPathXmlApplicationContextTest
         assertEquals( 2, plexusBean.getBeansList().size() );
     }
 
+    public void testInjectPlexusConfiguration()
+        throws Exception
+    {
+        ConfigurableApplicationContext applicationContext =
+            new PlexusClassPathXmlApplicationContext( new String[] {
+                "testInjectPlexusConfiguration.xml" } );
+        ConfigPlexusBean plexusBean = (ConfigPlexusBean) applicationContext.getBean( "plexusBean" );
+        assertEquals( "expected", plexusBean.getConfig().getChild( "xml" ).getAttribute( "test" ) );
+    }
+
 }
diff --git a/springy/plexus-spring/src/test/resources/testInjectPlexusConfiguration.xml b/springy/plexus-spring/src/test/resources/testInjectPlexusConfiguration.xml
new file mode 100644 (file)
index 0000000..6855b34
--- /dev/null
@@ -0,0 +1,13 @@
+<component-set>
+  <components>
+    <component>
+      <role>org.codehaus.plexus.spring.PlexusBean</role>
+      <implementation>org.codehaus.plexus.spring.ConfigPlexusBean</implementation>
+      <configuration>
+        <config>
+            <xml test="expected"/>
+        </config>
+      </configuration>
+    </component>
+  </components>
+</component-set>