<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
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",
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()
public static File getTestFile( String path )
{
- return new File( getBasedir(), path );
+ return new File( PlexusToSpringUtils.getBasedir(), path );
}
public static File getTestFile( String basedir,
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
{\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
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
* 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
{\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
--- /dev/null
+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;
+ }
+
+
+
+}
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" ) );
+ }
+
}
--- /dev/null
+<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>