+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<!--\r
- ~ Copyright 2006-2007 Nicolas De Loof.\r
- ~\r
- ~ Licensed under the Apache License, Version 2.0 (the "License");\r
- ~ you may not use this file except in compliance with the License.\r
- ~ You may obtain a copy of the License at\r
- ~\r
- ~ http://www.apache.org/licenses/LICENSE-2.0\r
- ~\r
- ~ Unless required by applicable law or agreed to in writing, software\r
- ~ distributed under the License is distributed on an "AS IS" BASIS,\r
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- ~ See the License for the specific language governing permissions and\r
- ~ limitations under the License.\r
--->\r
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0\r
- http://maven.apache.org/maven-v4_0_0.xsd">\r
- <modelVersion>4.0.0</modelVersion>\r
- <groupId>org.codehaus.plexus</groupId>\r
- <artifactId>plexus-spring</artifactId>\r
- <version>1.0-SNAPSHOT</version>\r
- <name>Plexus to Spring Adapter</name>\r
-\r
- <description>\r
- Bridge utility to use plexus components in a SpringFramework context.\r
- </description>\r
-\r
- <dependencies>\r
- <dependency>\r
- <groupId>org.springframework</groupId>\r
- <artifactId>spring-context</artifactId>\r
- <version>2.5.1</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.springframework</groupId>\r
- <artifactId>spring-web</artifactId>\r
- <version>2.5.1</version>\r
- <optional>true</optional>\r
- </dependency>\r
- <dependency>\r
- <groupId>commons-lang</groupId>\r
- <artifactId>commons-lang</artifactId>\r
- <version>2.2</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.codehaus.plexus</groupId>\r
- <artifactId>plexus-component-api</artifactId>\r
- <version>1.0-alpha-22</version>\r
- </dependency>\r
- <dependency>\r
- <!-- only required for ConsoleLogger -->\r
- <groupId>org.codehaus.plexus</groupId>\r
- <artifactId>plexus-container-default</artifactId>\r
- <version>1.0-alpha-22</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>dom4j</groupId>\r
- <artifactId>dom4j</artifactId>\r
- <version>1.6.1</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>com.opensymphony</groupId>\r
- <artifactId>webwork</artifactId>\r
- <version>2.2.6</version>\r
- <optional>true</optional>\r
- </dependency>\r
- <dependency>\r
- <groupId>javax.servlet</groupId>\r
- <artifactId>servlet-api</artifactId>\r
- <version>2.3</version>\r
- <optional>true</optional>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>junit</groupId>\r
- <artifactId>junit</artifactId>\r
- <version>3.8.2</version>\r
- <scope>compile</scope>\r
- <optional>true</optional>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.codehaus.plexus</groupId>\r
- <artifactId>plexus-log4j-logging</artifactId>\r
- <version>1.1-alpha-3</version>\r
- <scope>test</scope>\r
- </dependency>\r
- </dependencies>\r
-\r
- <developers>\r
- <developer>\r
- <email>nicolas@apache.org</email>\r
- <name>Nicolas De Loof</name>\r
- </developer>\r
- </developers>\r
-</project>
\ No newline at end of file
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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 org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
-
-/**
- * Utility method to convert plexus descriptors to spring bean context.
- *
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class PlexusApplicationContextDelegate
-{
- /** Logger used by this class. */
- protected final Log logger = LogFactory.getLog(getClass());
-
- private PlexusLifecycleBeanPostProcessor lifecycleBeanPostProcessor;
-
- /**
- * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
- */
- protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
- throws BeansException, IOException
- {
- logger.info( "Registering plexus to spring XML translation" );
- reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
- reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );
- }
-
- /**
- * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
- */
- protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory, ApplicationContext context )
- {
- // Register a PlexusContainerAdapter bean to allow context lookups using plexus API
- PlexusContainerAdapter plexus = new PlexusContainerAdapter();
- plexus.setApplicationContext( context );
- beanFactory.registerSingleton( "plexusContainer", plexus );
-
- // Register a beanPostProcessor to handle plexus interface-based lifecycle management
- lifecycleBeanPostProcessor = new PlexusLifecycleBeanPostProcessor();
- lifecycleBeanPostProcessor.setBeanFactory( context );
- beanFactory.addBeanPostProcessor( lifecycleBeanPostProcessor );
-
- // Register a PorpertyEditor to support plexus XML <configuration> set as CDATA in
- // a spring context XML file.
- beanFactory.addPropertyEditorRegistrar( new PlexusConfigurationPropertyEditor() );
- beanFactory.addPropertyEditorRegistrar( new PropertiesPropertyEditor() );
- }
-
- /**
- * @see org.springframework.context.support.AbstractApplicationContext#doClose()
- */
- protected void doClose()
- {
- try
- {
- lifecycleBeanPostProcessor.destroy();
- }
- catch ( Throwable ex )
- {
- logger.error( "Exception thrown from PlexusLifecycleBeanPostProcessor handling ContextClosedEvent", ex );
- }
- }
-}
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-import java.io.InputStream;\r
-\r
-import javax.xml.transform.Source;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.TransformerFactoryConfigurationError;\r
-import javax.xml.transform.dom.DOMResult;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamSource;\r
-\r
-import org.dom4j.io.DOMReader;\r
-import org.dom4j.io.OutputFormat;\r
-import org.dom4j.io.XMLWriter;\r
-import org.springframework.beans.factory.BeanDefinitionStoreException;\r
-import org.springframework.beans.factory.xml.BeanDefinitionDocumentReader;\r
-import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;\r
-import org.springframework.beans.factory.xml.XmlReaderContext;\r
-import org.w3c.dom.Document;\r
-\r
-/**\r
- * A Spring {@link BeanDefinitionDocumentReader} that converts on the fly the\r
- * Plexus components descriptor to a spring XML context.\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public class PlexusBeanDefinitionDocumentReader\r
- extends DefaultBeanDefinitionDocumentReader\r
-{\r
- public void registerBeanDefinitions( Document doc, XmlReaderContext readerContext )\r
- {\r
- doc = convertPlexusDescriptorToSpringBeans( doc );\r
- if ( Boolean.getBoolean( "plexus-spring.debug" ) )\r
- {\r
- try\r
- {\r
- XMLWriter writer = new XMLWriter( System.out, OutputFormat.createPrettyPrint() );\r
- writer.write( new DOMReader().read( doc ) );\r
- }\r
- catch ( Exception e )\r
- {\r
- // ignored\r
- }\r
- }\r
-\r
- super.registerBeanDefinitions( doc, readerContext );\r
- }\r
-\r
- protected Document convertPlexusDescriptorToSpringBeans( Document doc )\r
- {\r
- if ( "component-set".equals( doc.getDocumentElement().getNodeName() ) )\r
- {\r
- return translatePlexusDescriptor( doc );\r
- }\r
- if ( "plexus".equals( doc.getDocumentElement().getNodeName() ) )\r
- {\r
- return translatePlexusDescriptor( doc );\r
- }\r
-\r
- return doc;\r
- }\r
-\r
- private Document translatePlexusDescriptor( Document doc )\r
- throws TransformerFactoryConfigurationError\r
- {\r
- try\r
- {\r
- Source xmlSource = new DOMSource( doc );\r
- InputStream is = getClass().getResourceAsStream( "PlexusBeanDefinitionDocumentReader.xsl" );\r
- Source xsltSource = new StreamSource( is );\r
-\r
- DOMResult transResult = new DOMResult();\r
-\r
- TransformerFactory tf = TransformerFactory.newInstance();\r
- Transformer t = tf.newTransformer( xsltSource );\r
- t.transform( xmlSource, transResult );\r
-\r
- logger.debug( doc.getDocumentURI() + " successfully translated to spring");\r
- return (Document) transResult.getNode();\r
- }\r
- catch ( Exception e )\r
- {\r
- throw new BeanDefinitionStoreException(\r
- "Failed to translate plexus component descriptor to Spring XML context", e );\r
- }\r
- }\r
-}\r
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-import java.io.IOException;\r
-\r
-import org.springframework.beans.BeansException;\r
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;\r
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;\r
-import org.springframework.context.ApplicationContext;\r
-import org.springframework.context.support.ClassPathXmlApplicationContext;\r
-\r
-/**\r
- * A custom ClassPathXmlApplicationContext to support plexus\r
- * <tr>components.xml</tt> descriptors in Spring, with no changes required to\r
- * neither plexus nor spring beans.\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public class PlexusClassPathXmlApplicationContext\r
- extends ClassPathXmlApplicationContext\r
-{\r
- private static PlexusApplicationContextDelegate delegate = new PlexusApplicationContextDelegate();\r
-\r
- public PlexusClassPathXmlApplicationContext( String path, Class clazz )\r
- throws BeansException\r
- {\r
- super( path, clazz );\r
- }\r
-\r
- public PlexusClassPathXmlApplicationContext( String configLocation )\r
- throws BeansException\r
- {\r
- super( configLocation );\r
- }\r
-\r
- public PlexusClassPathXmlApplicationContext( String[] configLocations, ApplicationContext parent )\r
- throws BeansException\r
- {\r
- super( configLocations, parent );\r
- }\r
-\r
- public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh, ApplicationContext parent )\r
- throws BeansException\r
- {\r
- super( configLocations, refresh, parent );\r
- }\r
-\r
- public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh )\r
- throws BeansException\r
- {\r
- super( configLocations, refresh );\r
- }\r
-\r
- public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz, ApplicationContext parent )\r
- throws BeansException\r
- {\r
- super( paths, clazz, parent );\r
- }\r
-\r
- public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz )\r
- throws BeansException\r
- {\r
- super( paths, clazz );\r
- }\r
-\r
- public PlexusClassPathXmlApplicationContext( String[] configLocations )\r
- throws BeansException\r
- {\r
- super( configLocations );\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- *\r
- * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)\r
- */\r
- protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )\r
- throws BeansException, IOException\r
- {\r
- delegate.loadBeanDefinitions( reader );\r
- super.loadBeanDefinitions( reader );\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- *\r
- * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)\r
- */\r
- protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )\r
- {\r
- delegate.postProcessBeanFactory( beanFactory, this );\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- *\r
- * @see org.springframework.context.support.AbstractApplicationContext#doClose()\r
- */\r
- protected void doClose()\r
- {\r
- delegate.doClose();\r
- super.doClose();\r
- }\r
-\r
-}\r
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-import java.lang.reflect.Field;\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.springframework.beans.SimpleTypeConverter;\r
-import org.springframework.beans.TypeConverter;\r
-import org.springframework.beans.factory.BeanCreationException;\r
-import org.springframework.beans.factory.BeanFactory;\r
-import org.springframework.beans.factory.BeanFactoryAware;\r
-import org.springframework.beans.factory.BeanInitializationException;\r
-import org.springframework.beans.factory.FactoryBean;\r
-import org.springframework.beans.factory.ListableBeanFactory;\r
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;\r
-import org.springframework.beans.factory.config.RuntimeBeanReference;\r
-import org.springframework.util.ReflectionUtils;\r
-\r
-/**\r
- * A FactoryBean dedicated to building plexus components. This includes :\r
- * <ul>\r
- * <li>Support for direct field injection or "requirements"</li>\r
- * <li>Support for LogEnabled, Initializable and Disposable plexus interfaces</li>\r
- * <li>Support for plexus.requirement to get a Map<role-hint, component> for a\r
- * role\r
- * </ul>\r
- * If not set, the beanFActory will auto-detect the loggerManager to use by\r
- * searching for the adequate bean in the spring context.\r
- * <p>\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public class PlexusComponentFactoryBean\r
- implements FactoryBean, BeanFactoryAware\r
-{\r
- /** Logger available to subclasses */\r
- protected final Log logger = LogFactory.getLog( getClass() );\r
-\r
- /** The beanFactory */\r
- private BeanFactory beanFactory;\r
-\r
- /**\r
- * @todo isn't there a constant for this in plexus ?\r
- */\r
- private static final String SINGLETON = "singleton";\r
-\r
- /** The plexus component role */\r
- private Class role;\r
-\r
- /** The plexus component implementation class */\r
- private Class implementation;\r
-\r
- /** The plexus component instantiation strategy */\r
- private String instantiationStrategy;\r
-\r
- /** The plexus component requirements and configurations */\r
- private Map requirements;\r
-\r
- private Object singletonInstance;\r
-\r
- /**\r
- * {@inheritDoc}\r
- *\r
- * @see org.springframework.beans.factory.FactoryBean#getObject()\r
- */\r
- public Object getObject()\r
- throws Exception\r
- {\r
- if ( isSingleton() )\r
- {\r
- synchronized ( this )\r
- {\r
- if ( singletonInstance != null )\r
- {\r
- return singletonInstance;\r
- }\r
- this.singletonInstance = createInstance();\r
- return singletonInstance;\r
- }\r
- }\r
- return createInstance();\r
- }\r
-\r
- /**\r
- * Create the plexus component instance. Inject dependencies declared as\r
- * requirements using direct field injection\r
- */\r
- public Object createInstance()\r
- throws Exception\r
- {\r
- logger.debug( "Creating plexus component " + implementation );\r
- final Object component = implementation.newInstance();\r
- if ( requirements != null )\r
- {\r
- for ( Iterator iterator = requirements.entrySet().iterator(); iterator.hasNext(); )\r
- {\r
- Map.Entry requirement = (Map.Entry) iterator.next();\r
- String fieldName = (String) requirement.getKey();\r
-\r
- if ( fieldName.startsWith( "#" ) )\r
- {\r
- // implicit field injection : the field name was no\r
- // specified in the plexus descriptor as only one filed\r
- // matches Dependency type\r
-\r
- RuntimeBeanReference ref = (RuntimeBeanReference) requirement.getValue();\r
- Object dependency = beanFactory.getBean( ref.getBeanName() );\r
-\r
- Field[] fields = implementation.getDeclaredFields();\r
- for ( int i = 0; i < fields.length; i++ )\r
- {\r
- Field field = fields[i];\r
- if ( ReflectionUtils.COPYABLE_FIELDS.matches( field )\r
- && field.getType().isAssignableFrom( dependency.getClass() ) )\r
- {\r
- if ( logger.isTraceEnabled() )\r
- {\r
- logger.trace( "Injecting dependency " + dependency + " into field " + field.getName() );\r
- }\r
- ReflectionUtils.makeAccessible( field );\r
- ReflectionUtils.setField( field, component, dependency );\r
- }\r
- }\r
- }\r
- else\r
- {\r
- // explicit field injection\r
- fieldName = PlexusToSpringUtils.toCamelCase( fieldName );\r
- Field field = findField( fieldName );\r
- Object dependency = resolveRequirement( field, requirement.getValue() );\r
- if ( logger.isTraceEnabled() )\r
- {\r
- logger.trace( "Injecting dependency " + dependency + " into field " + field.getName() );\r
- }\r
- ReflectionUtils.makeAccessible( field );\r
- ReflectionUtils.setField( field, component, dependency );\r
- }\r
- }\r
- }\r
- return component;\r
- }\r
-\r
- private Field findField( String fieldName )\r
- {\r
- Class clazz = implementation;\r
- while ( clazz != Object.class )\r
- {\r
- try\r
- {\r
- return clazz.getDeclaredField( fieldName );\r
- }\r
- catch ( NoSuchFieldException e )\r
- {\r
- clazz = clazz.getSuperclass();\r
- }\r
- }\r
- String error = "No field " + fieldName + " on implementation class " + implementation;\r
- logger.error( error );\r
- throw new BeanInitializationException( error );\r
- }\r
-\r
- /**\r
- * Resolve the requirement that this field exposes in the component\r
- *\r
- * @param field\r
- * @return\r
- */\r
- protected Object resolveRequirement( Field field, Object requirement )\r
- {\r
- if ( requirement instanceof RuntimeBeanReference )\r
- {\r
- String beanName = ( (RuntimeBeanReference) requirement ).getBeanName();\r
- if ( Map.class.isAssignableFrom( field.getType() ) )\r
- {\r
- // component ask plexus for a Map of all available\r
- // components for the role\r
- requirement = PlexusToSpringUtils.lookupMap( beanName, getListableBeanFactory() );\r
- }\r
- else if ( Collection.class.isAssignableFrom( field.getType() ) )\r
- {\r
- requirement = PlexusToSpringUtils.LookupList( beanName, getListableBeanFactory() );\r
- }\r
- else\r
- {\r
- requirement = beanFactory.getBean( beanName );\r
- }\r
- }\r
- if ( requirement != null )\r
- {\r
- requirement = getBeanTypeConverter().convertIfNecessary( requirement, field.getType() );\r
- }\r
- return requirement;\r
-\r
- }\r
-\r
- public Class getObjectType()\r
- {\r
- return role;\r
- }\r
-\r
- public boolean isSingleton()\r
- {\r
- return SINGLETON.equals( instantiationStrategy );\r
- }\r
-\r
- protected TypeConverter getBeanTypeConverter()\r
- {\r
- if ( beanFactory instanceof ConfigurableBeanFactory )\r
- {\r
- return ( (ConfigurableBeanFactory) beanFactory ).getTypeConverter();\r
- }\r
- else\r
- {\r
- return new SimpleTypeConverter();\r
- }\r
- }\r
-\r
- private ListableBeanFactory getListableBeanFactory()\r
- {\r
- if ( beanFactory instanceof ListableBeanFactory )\r
- {\r
- return (ListableBeanFactory) beanFactory;\r
- }\r
- throw new BeanInitializationException( "A ListableBeanFactory is required by the PlexusComponentFactoryBean" );\r
- }\r
-\r
- /**\r
- * @param role the role to set\r
- */\r
- public void setRole( Class role )\r
- {\r
- this.role = role;\r
- }\r
-\r
- /**\r
- * @param implementation the implementation to set\r
- */\r
- public void setImplementation( Class implementation )\r
- {\r
- this.implementation = implementation;\r
- }\r
-\r
- /**\r
- * @param instantiationStrategy the instantiationStrategy to set\r
- */\r
- public void setInstantiationStrategy( String instantiationStrategy )\r
- {\r
- if ( instantiationStrategy.length() == 0 )\r
- {\r
- instantiationStrategy = SINGLETON;\r
- }\r
- if ( "poolable".equals( instantiationStrategy ) )\r
- {\r
- throw new BeanCreationException( "Plexus poolable instantiation-strategy is not supported" );\r
- }\r
- this.instantiationStrategy = instantiationStrategy;\r
- }\r
-\r
- /**\r
- * @param requirements the requirements to set\r
- */\r
- public void setRequirements( Map requirements )\r
- {\r
- this.requirements = requirements;\r
- }\r
-\r
- public void setBeanFactory( BeanFactory beanFactory )\r
- {\r
- this.beanFactory = beanFactory;\r
- }\r
-\r
-}\r
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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.beans.PropertyEditorSupport;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.commons.lang.StringUtils;
-import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import org.springframework.beans.PropertyEditorRegistrar;
-import org.springframework.beans.PropertyEditorRegistry;
-
-/**
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class PlexusConfigurationPropertyEditor
- extends PropertyEditorSupport
- implements PropertyEditorRegistrar
-{
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.beans.PropertyEditorRegistrar#registerCustomEditors(org.springframework.beans.PropertyEditorRegistry)
- */
- public void registerCustomEditors( PropertyEditorRegistry registry )
- {
- registry.registerCustomEditor( PlexusConfiguration.class, this );
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
- */
- public void setAsText( String text )
- throws IllegalArgumentException
- {
- if (StringUtils.isBlank( text ))
- {
- setValue( null );
- return;
- }
- try
- {
- Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( text ) );
- XmlPlexusConfiguration configuration = new XmlPlexusConfiguration( dom );
- setValue( configuration );
- }
- catch ( Exception e )
- {
- throw new IllegalArgumentException( "Failed to convert to Plexus XML configuration", e );
- }
- }
-
-}
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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.File;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.PlexusContainerException;
-import org.codehaus.plexus.classworlds.realm.ClassRealm;
-import org.codehaus.plexus.component.composition.CompositionException;
-import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
-import org.codehaus.plexus.component.repository.ComponentDescriptor;
-import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.logging.LoggerManager;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-/**
- * An adapter to access Spring ApplicationContext from a plexus component
- *
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class PlexusContainerAdapter
- implements PlexusContainer, ApplicationContextAware
-{
- private Context context = new SimpleContext();
-
- private ApplicationContext applicationContext;
-
-
- public PlexusContainerAdapter()
- {
- super();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#addComponentDescriptor(org.codehaus.plexus.component.repository.ComponentDescriptor)
- */
- public void addComponentDescriptor( ComponentDescriptor componentDescriptor )
- throws ComponentRepositoryException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#addContextValue(java.lang.Object, java.lang.Object)
- */
- public void addContextValue( Object key, Object value )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#addJarRepository(java.io.File)
- */
- public void addJarRepository( File repository )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#addJarResource(java.io.File)
- */
- public void addJarResource( File resource )
- throws PlexusContainerException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#autowire(java.lang.Object)
- */
- public Object autowire( Object component )
- throws CompositionException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#createAndAutowire(java.lang.String)
- */
- public Object createAndAutowire( String clazz )
- throws CompositionException, ClassNotFoundException, InstantiationException, IllegalAccessException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map)
- */
- public PlexusContainer createChildContainer( String name, List classpathJars, Map context )
- throws PlexusContainerException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map, java.util.List)
- */
- public PlexusContainer createChildContainer( String name, List classpathJars, Map context, List discoveryListeners )
- throws PlexusContainerException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#createComponentRealm(java.lang.String, java.util.List)
- */
- public ClassRealm createComponentRealm( String id, List jars )
- throws PlexusContainerException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#dispose()
- */
- public void dispose()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getChildContainer(java.lang.String)
- */
- public PlexusContainer getChildContainer( String name )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String)
- */
- public ComponentDescriptor getComponentDescriptor( String role )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String, java.lang.String)
- */
- public ComponentDescriptor getComponentDescriptor( String role, String roleHint )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public ComponentDescriptor getComponentDescriptor( String role, ClassRealm realm )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String, java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public ComponentDescriptor getComponentDescriptor( String role, String roleHint, ClassRealm realm )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorList(java.lang.String)
- */
- public List getComponentDescriptorList( String role )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorList(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public List getComponentDescriptorList( String role, ClassRealm componentRealm )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorMap(java.lang.String)
- */
- public Map getComponentDescriptorMap( String role )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorMap(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public Map getComponentDescriptorMap( String role, ClassRealm componentRealm )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getComponentRealm(java.lang.String)
- */
- public ClassRealm getComponentRealm( String realmId )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getContainerRealm()
- */
- public ClassRealm getContainerRealm()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getContext()
- */
- public Context getContext()
- {
- return context;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getCreationDate()
- */
- public Date getCreationDate()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getLogger()
- */
- public Logger getLogger()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getLoggerManager()
- */
- public LoggerManager getLoggerManager()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getLookupRealm()
- */
- public ClassRealm getLookupRealm()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getLookupRealm(java.lang.Object)
- */
- public ClassRealm getLookupRealm( Object component )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#getName()
- */
- public String getName()
- {
- return "plexus spring adapter";
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#hasChildContainer(java.lang.String)
- */
- public boolean hasChildContainer( String name )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String)
- */
- public boolean hasComponent( String role )
- {
- return false;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String, java.lang.String)
- */
- public boolean hasComponent( String role, String roleHint )
- {
- return applicationContext.containsBean( PlexusToSpringUtils.buildSpringId( role, roleHint ) );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#isReloadingEnabled()
- */
- public boolean isReloadingEnabled()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String)
- */
- public Object lookup( String componentKey )
- throws ComponentLookupException
- {
- return lookup( componentKey, (String) null );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class)
- */
- public Object lookup( Class componentClass )
- throws ComponentLookupException
- {
- return lookup( componentClass.getName(), (String) null );
-
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public Object lookup( String componentKey, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, java.lang.String)
- */
- public Object lookup( String role, String roleHint )
- throws ComponentLookupException
- {
- return applicationContext.getBean( PlexusToSpringUtils.buildSpringId( role, roleHint ) );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public Object lookup( Class componentClass, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class, java.lang.String)
- */
- public Object lookup( Class role, String roleHint )
- throws ComponentLookupException
- {
- return lookup( role.getName(), roleHint );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public Object lookup( String role, String roleHint, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class, java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public Object lookup( Class role, String roleHint, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.String)
- */
- public List lookupList( String role )
- throws ComponentLookupException
- {
- return PlexusToSpringUtils.LookupList( role, applicationContext );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.Class)
- */
- public List lookupList( Class role )
- throws ComponentLookupException
- {
- return lookupList( role.getName() );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public List lookupList( String role, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.Class, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public List lookupList( Class role, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.String)
- */
- public Map lookupMap( String role )
- throws ComponentLookupException
- {
- return PlexusToSpringUtils.lookupMap( role, applicationContext );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.Class)
- */
- public Map lookupMap( Class role )
- throws ComponentLookupException
- {
- return lookupMap( role.getName() );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public Map lookupMap( String role, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.Class, org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public Map lookupMap( Class role, ClassRealm realm )
- throws ComponentLookupException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#registerComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener)
- */
- public void registerComponentDiscoveryListener( ComponentDiscoveryListener listener )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#release(java.lang.Object)
- */
- public void release( Object component )
- throws ComponentLifecycleException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.Map)
- */
- public void releaseAll( Map components )
- throws ComponentLifecycleException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.List)
- */
- public void releaseAll( List components )
- throws ComponentLifecycleException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#removeChildContainer(java.lang.String)
- */
- public void removeChildContainer( String name )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#removeComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener)
- */
- public void removeComponentDiscoveryListener( ComponentDiscoveryListener listener )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#resume(java.lang.Object)
- */
- public void resume( Object component )
- throws ComponentLifecycleException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#setLoggerManager(org.codehaus.plexus.logging.LoggerManager)
- */
- public void setLoggerManager( LoggerManager loggerManager )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#setLookupRealm(org.codehaus.plexus.classworlds.realm.ClassRealm)
- */
- public ClassRealm setLookupRealm( ClassRealm realm )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#setName(java.lang.String)
- */
- public void setName( String name )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#setParentPlexusContainer(org.codehaus.plexus.PlexusContainer)
- */
- public void setParentPlexusContainer( PlexusContainer container )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#setReloadingEnabled(boolean)
- */
- public void setReloadingEnabled( boolean reloadingEnabled )
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.PlexusContainer#suspend(java.lang.Object)
- */
- public void suspend( Object component )
- throws ComponentLifecycleException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
- */
- public void setApplicationContext( ApplicationContext applicationContext )
- throws BeansException
- {
- this.applicationContext = applicationContext;
- }
-
- private class SimpleContext implements Context
- {
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.context.Context#contains(java.lang.Object)
- */
- public boolean contains( Object key )
- {
- return PlexusConstants.PLEXUS_KEY.equals( key );
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.context.Context#get(java.lang.Object)
- */
- public Object get( Object key )
- throws ContextException
- {
- return PlexusConstants.PLEXUS_KEY.equals( key ) ? PlexusContainerAdapter.this : null;
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.context.Context#getContextData()
- */
- public Map getContextData()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.context.Context#hide(java.lang.Object)
- */
- public void hide( Object key )
- throws IllegalStateException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.context.Context#makeReadOnly()
- */
- public void makeReadOnly()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- * @see org.codehaus.plexus.context.Context#put(java.lang.Object, java.lang.Object)
- */
- public void put( Object key, Object value )
- throws IllegalStateException
- {
- throw new UnsupportedOperationException();
- }
-
- }
-}
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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.File;
-
-import junit.framework.TestCase;
-
-import org.springframework.context.ConfigurableApplicationContext;
-
-/**
- * Mimic org.codehaus.plexus.PlexusTestCase as simple replacement for test
- * cases.
- *
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class PlexusInSpringTestCase
- extends TestCase
-{
- private ConfigurableApplicationContext applicationContext;
-
- protected void setUp()
- throws Exception
- {
- applicationContext =
- new PlexusClassPathXmlApplicationContext( new String[] {
- "classpath*:META-INF/plexus/components.xml",
- "classpath*:" + getPlexusConfigLocation(),
- "classpath*:" + getSpringConfigLocation()} );
- }
-
- protected String getSpringConfigLocation()
- throws Exception
- {
- return getClass().getName().replace( '.', '/' ) + "-context.xml";
- }
-
- protected String getPlexusConfigLocation()
- throws Exception
- {
- return getClass().getName().replace( '.', '/' ) + ".xml";
- }
-
- /**
- * {@inheritDoc}
- *
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown()
- throws Exception
- {
- if ( applicationContext != null )
- {
- applicationContext.close();
- }
- }
-
- public static String getBasedir()
- {
- return PlexusToSpringUtils.getBasedir();
- }
-
- public String getTestConfiguration()
- {
- return getTestConfiguration( getClass() );
- }
-
- public static String getTestConfiguration( Class clazz )
- {
- String s = clazz.getName().replace( '.', '/' );
-
- return s.substring( 0, s.indexOf( "$" ) ) + ".xml";
- }
-
- public Object lookup( Class role )
- {
- return lookup( role, null );
- }
-
- public Object lookup( Class role, String roleHint )
- {
- return lookup( role.getName(), roleHint );
-
- }
-
- public Object lookup( String role )
- {
- return lookup( role, null );
- }
-
- public Object lookup( String role, String roleHint )
- {
- return applicationContext.getBean( PlexusToSpringUtils.buildSpringId( role, roleHint ) );
- }
-
- public static File getTestFile( String path )
- {
- return new File( PlexusToSpringUtils.getBasedir(), path );
- }
-
- public static File getTestFile( String basedir,
- String path )
- {
- File basedirFile = new File( basedir );
-
- if ( !basedirFile.isAbsolute() )
- {
- basedirFile = getTestFile( basedir );
- }
-
- return new File( basedirFile, path );
- }
-
- public static String getTestPath( String path )
- {
- return getTestFile( path ).getAbsolutePath();
- }
-
- public static String getTestPath( String basedir,
- String path )
- {
- return getTestFile( basedir, path ).getAbsolutePath();
- }
-
- protected ConfigurableApplicationContext getApplicationContext()
- {
- return applicationContext;
- }
-}
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.logging.LogEnabled;
-import org.codehaus.plexus.logging.LoggerManager;
-import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.BeanInitializationException;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-
-/**
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class PlexusLifecycleBeanPostProcessor
- implements BeanPostProcessor, BeanFactoryAware, DisposableBean
-{
- /** Logger available to subclasses */
- protected final Log logger = LogFactory.getLog( getClass() );
-
- private BeanFactory beanFactory;
-
- private Context context;
-
- private LoggerManager loggerManager;
-
- /** The plexus Disposable components */
- private Map disposables = new HashMap();
-
- protected Context getContext()
- {
- if ( context == null )
- {
- PlexusContainer container = (PlexusContainer) beanFactory.getBean( "plexusContainer" );
- context = container.getContext();
- }
- return context;
- }
-
- /**
- * Retrieve the loggerManager instance to be used for LogEnabled components
- *
- * @return
- */
- protected LoggerManager getLoggerManager()
- {
- if ( loggerManager == null )
- {
- if ( beanFactory.containsBean( "loggerManager" ) )
- {
- loggerManager = (LoggerManager) beanFactory.getBean( "loggerManager" );
- }
- else
- {
- logger.warn( "No loggerManager set in context. Falling back to ConsoleLoggerManager" );
- ConsoleLoggerManager defaultLoggerManager = new ConsoleLoggerManager();
- defaultLoggerManager.initialize();
- loggerManager = defaultLoggerManager;
- }
- }
- return loggerManager;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
- * java.lang.String)
- */
- public Object postProcessBeforeInitialization( Object bean, String beanName )
- throws BeansException
- {
- return bean;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
- * java.lang.String)
- */
- public Object postProcessAfterInitialization( Object bean, String beanName )
- throws BeansException
- {
- if ( bean instanceof FactoryBean )
- {
- // only apply to beans
- return bean;
- }
-
- if ( bean instanceof LogEnabled )
- {
- logger.trace( "Enable Logging on plexus bean " + beanName );
- ( (LogEnabled) bean ).enableLogging( getLoggerManager().getLoggerForComponent( beanName ) );
- }
-
- if ( bean instanceof Contextualizable )
- {
- try
- {
- logger.trace( "Contextualize plexus bean " + beanName );
- ( (Contextualizable) bean ).contextualize( getContext() );
- }
- catch ( ContextException e )
- {
- throw new BeanInitializationException(
- "Failed to invoke plexus lifecycle Contextualizable.contextualize on " + beanName, e );
- }
- }
-
- // TODO add support for Startable, Stopable -> LifeCycle ?
-
- if ( bean instanceof Initializable )
- {
- try
- {
- logger.trace( "Initialize plexus bean " + beanName );
- ( (Initializable) bean ).initialize();
- }
- catch ( InitializationException e )
- {
- throw new BeanInitializationException( "Failed to invoke plexus lifecycle Initializable.initialize on "
- + beanName, e );
- }
- }
-
- if ( bean instanceof Disposable )
- {
- synchronized ( disposables )
- {
- disposables.put( beanName, bean );
- }
- }
- return bean;
- }
-
- public void setBeanFactory( BeanFactory beanFactory )
- {
- this.beanFactory = beanFactory;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.beans.factory.config.AbstractFactoryBean#destroy()
- */
- public void destroy()
- throws Exception
- {
- synchronized ( disposables )
- {
- for ( Iterator iterator = disposables.entrySet().iterator(); iterator.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) iterator.next();
- logger.debug( "Dispose plexus component " + entry.getKey() );
- ( (Disposable) entry.getValue() ).dispose();
- }
- }
- }
-
-}
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-import java.io.PrintWriter;\r
-import java.io.StringWriter;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.apache.commons.lang.StringUtils;\r
-import org.springframework.beans.factory.BeanDefinitionStoreException;\r
-import org.springframework.beans.factory.config.RuntimeBeanReference;\r
-import org.springframework.beans.factory.support.AbstractBeanDefinition;\r
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;\r
-import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;\r
-import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;\r
-import org.springframework.beans.factory.xml.NamespaceHandlerSupport;\r
-import org.springframework.beans.factory.xml.ParserContext;\r
-import org.springframework.util.xml.DomUtils;\r
-import org.w3c.dom.Element;\r
-import org.w3c.dom.NamedNodeMap;\r
-import org.w3c.dom.Node;\r
-import org.w3c.dom.NodeList;\r
-\r
-/**\r
- * A spring namespace handler to support plexus components creation and direct\r
- * field-injection in a spring XmlApplicationContext.\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- * @since 1.1\r
- */\r
-public class PlexusNamespaceHandler\r
- extends NamespaceHandlerSupport\r
-{\r
- public void init()\r
- {\r
- registerBeanDefinitionParser( "component", new PlexusComponentBeanDefinitionParser() );\r
- registerBeanDefinitionParser( "requirement", new NopBeanDefinitionParser() );\r
- registerBeanDefinitionParser( "configuration", new NopBeanDefinitionParser() );\r
- }\r
-\r
- private class NopBeanDefinitionParser\r
- extends AbstractBeanDefinitionParser\r
- {\r
- protected AbstractBeanDefinition parseInternal( Element element, ParserContext parserContext )\r
- {\r
- return null;\r
- }\r
-\r
- }\r
-\r
- /**\r
- * BeanDefinitionParser for <plexus:component>. Register a bean\r
- * definition for a PlexusComponentFactoryBean with all nested requirement /\r
- * configuration injected using direct field injection.\r
- * <p>\r
- * Also register an alias for the Plexus component using spring conventions\r
- * (interface class simple name + "#" role-hint)\r
- */\r
- private class PlexusComponentBeanDefinitionParser\r
- extends AbstractSingleBeanDefinitionParser\r
- {\r
- private int count;\r
-\r
- protected void doParse( Element element, BeanDefinitionBuilder builder )\r
- {\r
- builder.addPropertyValue( "role", element.getAttribute( "role" ) );\r
- String implementation = element.getAttribute( "implementation" );\r
- builder.addPropertyValue( "implementation", implementation );\r
- builder.addPropertyValue( "instantiationStrategy", element.getAttribute( "instantiation-strategy" ) );\r
-\r
- Map dependencies = new HashMap();\r
-\r
- List requirements = DomUtils.getChildElementsByTagName( element, "requirement" );\r
- for ( Iterator iterator = requirements.iterator(); iterator.hasNext(); )\r
- {\r
- Element child = (Element) iterator.next();\r
- String name = child.getAttribute( "field-name" );\r
- if ( name.length() == 0 )\r
- {\r
- // Plexus doesn't require to specify the field-name if only\r
- // one field matches the injected type\r
- name = "#" + count++;\r
- }\r
- String role = child.getAttribute( "role" );\r
- String roleHint = child.getAttribute( "role-hint" );\r
- String ref = PlexusToSpringUtils.buildSpringId( role, roleHint );\r
- dependencies.put( name, new RuntimeBeanReference( ref ) );\r
-\r
- }\r
-\r
- List configurations = DomUtils.getChildElementsByTagName( element, "configuration" );\r
- for ( Iterator iterator = configurations.iterator(); iterator.hasNext(); )\r
- {\r
- Element child = (Element) iterator.next();\r
- String name = child.getAttribute( "name" );\r
- String value;\r
- if ( child.getChildNodes().getLength() == 1 )\r
- {\r
- value = child.getTextContent();\r
- }\r
- else\r
- {\r
- StringWriter xml = new StringWriter();\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
- }\r
-\r
- protected String resolveId( Element element, AbstractBeanDefinition definition, ParserContext parserContext )\r
- throws BeanDefinitionStoreException\r
- {\r
- String role = element.getAttribute( "role" );\r
- String roleHint = element.getAttribute( "role-hint" );\r
- return PlexusToSpringUtils.buildSpringId( role, roleHint );\r
- }\r
-\r
- protected Class getBeanClass( Element element )\r
- {\r
- return PlexusComponentFactoryBean.class;\r
- }\r
-\r
- }\r
- /**\r
- * @param childNodes\r
- * @return\r
- */\r
- private void flatten( NodeList childNodes, PrintWriter out )\r
- {\r
- for ( int i = 0; i < childNodes.getLength(); i++ )\r
- {\r
- Node node = childNodes.item( i );\r
- if (node.getNodeType() == Node.TEXT_NODE )\r
- {\r
- out.print( node.getTextContent() );\r
- }\r
- else if (node.getNodeType() == Node.ELEMENT_NODE )\r
- {\r
- flatten( (Element) node, out );\r
- }\r
- }\r
- }\r
- /**\r
- * @param item\r
- * @param out\r
- */\r
- private void flatten( Element el, PrintWriter out )\r
- {\r
- out.print( '<' );\r
- out.print( el.getTagName() );\r
- NamedNodeMap attributes = el.getAttributes();\r
- for ( int i = 0; i < attributes.getLength(); i++ )\r
- {\r
- Node attribute = attributes.item( i );\r
- out.print( " ");\r
- out.print( attribute.getLocalName() );\r
- out.print( "=\"" );\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
- out.print( el.getTagName() );\r
- out.print( '>' );\r
- }\r
-}\r
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\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
-import java.util.Map;\r
-import java.util.StringTokenizer;\r
-\r
-import org.apache.commons.lang.ClassUtils;\r
-import org.codehaus.plexus.PlexusConstants;\r
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;\r
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;\r
-import org.springframework.beans.factory.ListableBeanFactory;\r
-\r
-/**\r
- * Utility method to convert plexus descriptors to spring bean context.\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public class PlexusToSpringUtils\r
-{\r
-\r
- public static String toSpringId( String string )\r
- {\r
- int i = string.lastIndexOf( '.' );\r
- if ( i >= 0 )\r
- {\r
- return Character.toLowerCase( string.charAt( i + 1 ) ) + string.substring( i + 2 );\r
- }\r
- return string;\r
- }\r
-\r
- public static String toCamelCase( String string )\r
- {\r
- StringBuilder camelCase = new StringBuilder();\r
- boolean first = true;\r
-\r
- StringTokenizer tokenizer = new StringTokenizer( string, "-" );\r
- while ( tokenizer.hasMoreTokens() )\r
- {\r
- String token = tokenizer.nextToken();\r
- if ( first )\r
- {\r
- camelCase.append( token.charAt( 0 ) );\r
- first = false;\r
- }\r
- else\r
- {\r
- camelCase.append( Character.toUpperCase( token.charAt( 0 ) ) );\r
- }\r
- camelCase.append( token.substring( 1, token.length() ) );\r
- }\r
- return camelCase.toString();\r
- }\r
-\r
- public static boolean isInitializable( String className )\r
- {\r
- boolean initializable = false;\r
- try\r
- {\r
- initializable = Initializable.class.isAssignableFrom( ClassUtils.getClass( className ) );\r
- }\r
- catch ( ClassNotFoundException e )\r
- {\r
- // ignored\r
- }\r
- return initializable;\r
- }\r
-\r
- public static boolean isDisposable( String className )\r
- {\r
- boolean disposable = false;\r
- try\r
- {\r
- disposable = Disposable.class.isAssignableFrom( ClassUtils.getClass( className ) );\r
- }\r
- catch ( ClassNotFoundException e )\r
- {\r
- // ignored\r
- }\r
- return disposable;\r
- }\r
-\r
- public static String buildSpringId( Class role, String roleHint )\r
- {\r
- return buildSpringId( role.getName(), roleHint );\r
- }\r
-\r
- public static String buildSpringId( String role, String roleHint )\r
- {\r
- int i = role.lastIndexOf( '.' ) + 1;\r
- if ( i <= 0 )\r
- {\r
- i = 0;\r
- }\r
- String id = Character.toLowerCase( role.charAt( i ) ) + role.substring( i + 1 );\r
- return isDefaultHint( roleHint ) ? id : id + '#' + roleHint;\r
- }\r
-\r
- private static boolean isDefaultHint( String roleHint )\r
- {\r
- return roleHint == null || roleHint.length() == 0 || "default".equals( roleHint );\r
- }\r
-\r
- public static Map lookupMap( String role, ListableBeanFactory beanFactory )\r
- {\r
- Map map = new HashMap();\r
- String mask = role + '#';\r
- String[] beans = beanFactory.getBeanDefinitionNames();\r
- for ( int i = 0; i < beans.length; i++ )\r
- {\r
- String name = beans[i];\r
- if ( name.startsWith( mask ) )\r
- {\r
- map.put( name.substring( mask.length() ), beanFactory.getBean( name ) );\r
- }\r
- }\r
- if ( beanFactory.containsBean( role ) )\r
- {\r
- map.put( PlexusConstants.PLEXUS_DEFAULT_HINT, beanFactory.getBean( role ) );\r
- }\r
- return map;\r
- }\r
-\r
- public static List LookupList( String role, ListableBeanFactory beanFactory )\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;
-
-/*
- * 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 org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.web.context.support.XmlWebApplicationContext;
-
-/**
- * A custom XmlWebApplicationContext to support plexus
- * <tr>components.xml</tt> descriptors in Spring, with no changes required to
- * neither plexus nor spring beans.
- *
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class PlexusWebApplicationContext
- extends XmlWebApplicationContext
-{
- private static PlexusApplicationContextDelegate delegate = new PlexusApplicationContextDelegate();
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
- */
- protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
- throws BeansException, IOException
- {
- delegate.loadBeanDefinitions( reader );
- super.loadBeanDefinitions( reader );
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
- */
- protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
- {
- delegate.postProcessBeanFactory( beanFactory, this );
- getServletContext().setAttribute( "webwork.plexus.container", beanFactory.getBean( "plexusContainer" ) );
- super.postProcessBeanFactory( beanFactory );
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.context.support.AbstractApplicationContext#doClose()
- */
- protected void doClose()
- {
- delegate.doClose();
- super.doClose();
- }
-
-}
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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.beans.PropertyEditorSupport;
-import java.io.StringReader;
-import java.util.Iterator;
-import java.util.Properties;
-
-import org.apache.commons.lang.StringUtils;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
-import org.springframework.beans.PropertyEditorRegistrar;
-import org.springframework.beans.PropertyEditorRegistry;
-
-/**
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class PropertiesPropertyEditor
- extends PropertyEditorSupport
- implements PropertyEditorRegistrar
-{
-
- /**
- * {@inheritDoc}
- *
- * @see org.springframework.beans.PropertyEditorRegistrar#registerCustomEditors(org.springframework.beans.PropertyEditorRegistry)
- */
- public void registerCustomEditors( PropertyEditorRegistry registry )
- {
- registry.registerCustomEditor( Properties.class, this );
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * Support for plexus properties injection
- * <pre>
- * <fieldName>
- * <property>
- * <name>key</name>
- * <value>true</value>
- * </property>
- * ...
- * </pre>
- *
- * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
- */
- public void setAsText( String text )
- throws IllegalArgumentException
- {
- if ( StringUtils.isBlank( text ) )
- {
- setValue( null );
- return;
- }
- Properties properties = new Properties();
- try
- {
- SAXReader reader = new SAXReader();
- Document doc = reader.read( new StringReader( text ) );
- Element root = doc.getRootElement();
- for ( Iterator i = root.elementIterator(); i.hasNext(); )
- {
- Element element = (Element) i.next();
- properties.setProperty( element.element( "name" ).getText(), element.element( "value" ).getText() );
- }
- }
- catch ( Exception e )
- {
- throw new IllegalArgumentException( "Failed to convert to Properties", e );
- }
- setValue( properties );
- }
-
-}
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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.util.Map;
-
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.core.NestedRuntimeException;
-
-import com.opensymphony.webwork.spring.WebWorkSpringObjectFactory;
-import com.opensymphony.xwork.Action;
-import com.opensymphony.xwork.Result;
-import com.opensymphony.xwork.interceptor.Interceptor;
-
-/**
- * Replacement for WebWorkSpringObjectFactory ("webwork.objectFactory = spring")
- * to support plexus components lookup as expected by plexus-xwork integration.
- *
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
- */
-public class WebWorkPlexusInSpringObjectFactory
- extends WebWorkSpringObjectFactory
-{
-
- /**
- * {@inheritDoc}
- *
- * @see com.opensymphony.xwork.spring.SpringObjectFactory#buildBean(java.lang.String,
- * java.util.Map)
- */
- public Object buildBean( String name, Map map )
- throws Exception
- {
- String id = PlexusToSpringUtils.buildSpringId( Action.class, name );
- if ( appContext.containsBean( id ) )
- {
- return super.buildBean( id, map );
- }
-
- id = PlexusToSpringUtils.buildSpringId( Result.class, name );
- if ( appContext.containsBean( id ) )
- {
- return super.buildBean( id, map );
- }
-
- id = PlexusToSpringUtils.buildSpringId( Interceptor.class, name );
- if ( appContext.containsBean( id ) )
- {
- return super.buildBean( id, map );
- }
- return super.buildBean( name, map );
- }
-
- public Class getClassInstance( String className )
- throws ClassNotFoundException
- {
- String id = PlexusToSpringUtils.buildSpringId( Action.class, className );
- if ( appContext.containsBean( id ) )
- {
- return appContext.getType( id );
- }
-
- id = PlexusToSpringUtils.buildSpringId( Result.class, className );
- if ( appContext.containsBean( id ) )
- {
- return appContext.getType( id );
- }
-
- id = PlexusToSpringUtils.buildSpringId( Interceptor.class, className );
- if ( appContext.containsBean( id ) )
- {
- return appContext.getType( id );
- }
- return super.getClassInstance( className );
- }
-}
+++ /dev/null
-# register a NamespaceHandler for the custom <plexus: namespace\r
-http\://plexus.codehaus.org/spring = org.codehaus.plexus.spring.PlexusNamespaceHandler\r
-
\ No newline at end of file
+++ /dev/null
-# register a local copy of the plexus namespace XML schema\r
-http\://plexus.codehaus.org/schemas/spring-1.0.xsd = plexus.xsd\r
-
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<!--\r
- ~ Licensed to the Apache Software Foundation (ASF) under one\r
- ~ or more contributor license agreements. See the NOTICE file\r
- ~ distributed with this work for additional information\r
- ~ regarding copyright ownership. The ASF licenses this file\r
- ~ to you under the Apache License, Version 2.0 (the\r
- ~ "License"); you may not use this file except in compliance\r
- ~ with the License. You may obtain a copy of the License at\r
- ~\r
- ~ http://www.apache.org/licenses/LICENSE-2.0\r
- ~\r
- ~ Unless required by applicable law or agreed to in writing,\r
- ~ software distributed under the License is distributed on an\r
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- ~ KIND, either express or implied. See the License for the\r
- ~ specific language governing permissions and limitations\r
- ~ under the License.\r
- -->\r
-\r
-<xsl:stylesheet\r
- version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
- xmlns:plexus="http://plexus.codehaus.org/spring">\r
-\r
-<xsl:output method="xml" cdata-section-elements="configuration"/>\r
-\r
-<!--\r
- Convert a plexus descriptor to a spring XML context with help of the custom <plexus: namespace\r
- to handle IoC containers incompatibilities.\r
- -->\r
-\r
-<xsl:template match="/" >\r
-<spring:beans xmlns:spring="http://www.springframework.org/schema/beans"\r
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xmlns="http://plexus.codehaus.org/spring"\r
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
- http://plexus.codehaus.org/spring http://plexus.codehaus.org/schemas/spring-1.0.xsd"\r
- default-lazy-init="true">\r
- <xsl:for-each select="//component">\r
-\r
- <component>\r
- <xsl:attribute name="role">\r
- <xsl:value-of select="role" />\r
- </xsl:attribute>\r
- <xsl:if test="role-hint">\r
- <xsl:attribute name="role-hint">\r
- <xsl:value-of select="role-hint" />\r
- </xsl:attribute>\r
- </xsl:if>\r
- <xsl:attribute name="implementation">\r
- <xsl:value-of select="implementation" />\r
- </xsl:attribute>\r
- <xsl:if test="instantiation-strategy">\r
- <xsl:attribute name="instantiation-strategy">\r
- <xsl:value-of select="instantiation-strategy" />\r
- </xsl:attribute>\r
- </xsl:if>\r
- <xsl:for-each select="requirements/requirement">\r
- <requirement>\r
- <xsl:attribute name="field-name">\r
- <xsl:value-of select="field-name" />\r
- </xsl:attribute>\r
- <xsl:attribute name="role">\r
- <xsl:value-of select="role" />\r
- </xsl:attribute>\r
- <xsl:if test="role-hint">\r
- <xsl:attribute name="role-hint">\r
- <xsl:value-of select="role-hint" />\r
- </xsl:attribute>\r
- </xsl:if>\r
- </requirement>\r
- </xsl:for-each>\r
- <xsl:for-each select="configuration/*">\r
- <configuration>\r
- <xsl:attribute name="name">\r
- <xsl:value-of select="name(.)" />\r
- </xsl:attribute>\r
- <xsl:copy-of select="child::node()" />\r
- </configuration>\r
- </xsl:for-each>\r
- </component>\r
-\r
- </xsl:for-each>\r
-</spring:beans>\r
-</xsl:template>\r
-\r
-</xsl:stylesheet>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<xsd:schema xmlns="http://plexus.codehaus.org/spring" xmlns:xsd="http://www.w3.org/2001/XMLSchema"\r
-targetNamespace="http://plexus.codehaus.org/spring"\r
-elementFormDefault="qualified" attributeFormDefault="unqualified">\r
-\r
- <xsd:element name="component">\r
- <xsd:complexType>\r
- <xsd:sequence>\r
- <xsd:element name="requirement" minOccurs="0">\r
- <xsd:complexType>\r
- <xsd:attribute name="field-name" type="xsd:string" use="optional"/>\r
- <xsd:attribute name="role" type="xsd:string" use="required"/>\r
- <xsd:attribute name="role-hint" type="xsd:string" use="optional"/>\r
- </xsd:complexType>\r
- </xsd:element>\r
- <xsd:element name="configuration" minOccurs="0">\r
- <xsd:complexType>\r
- <xsd:attribute name="name" type="xsd:string" use="required"/>\r
- <xsd:attribute name="value" type="xsd:string" use="required"/>\r
- </xsd:complexType>\r
- </xsd:element>\r
- </xsd:sequence>\r
- <xsd:attribute name="role" type="xsd:string" use="required"/>\r
- <xsd:attribute name="role-hint" type="xsd:string" use="optional"/>\r
- <xsd:attribute name="implementation" type="xsd:string" use="required"/>\r
- </xsd:complexType>\r
- </xsd:element>\r
-</xsd:schema>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- 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 name="Monitoring">
-
- <bannerRight>
- <name>Plexus Spring integration support</name>
- <href>/index.html</href>
- </bannerRight>
-
- <body>
- <menu name="Plexus Spring integration support">
- <item name="Overview" href="/index.html"/>
- </menu>
- <menu name="Links">
- <item name="Spring framework" href="http://www.springframework.org"/>
- <item name="Plexus" href="http://plexus.codehaus.org/"/>
- </menu>
-
- </body>
-
-</project>
+++ /dev/null
-<?xml version="1.0"?>
-<!--
- 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.
--->
-
-<document>
-
- <properties>
- <title>Plexus to Spring Adapter</title>
- </properties>
-
- <body>
-
- <section name="Plexus to Spring Adapter">
- <subsection name="overview">
- <p>
- This library is an adapter to use plexus components in a springframework application context.
- It translates plexus components descriptors and interfaces to spring to get dependency
- injection and interface based lifecycle management, with some limitations.
- </p>
- </subsection>
- <subsection name="features">
- <p>
- Pexus-spring provides to plexus components :
- <ul>
- <li>Lifecycle management (creation, initialization, Logger injection and destruction</li>
- <li>Limited Contextualization using a PlexusContainerAdapter and ContextAdapter</li>
- <li>Injection of dependencies (using plexus direct field-injection) based on plexus descriptor</li>
- <li>Injection of configuration, limited to String and simple types</li>
- </ul>
- </p>
- </subsection>
- <subsection name="how ?">
- <p>
- Pexus-spring defines some custom Spring components :
- <ul>
- <li>a <tt>PlexusBeanDefinitionDocumentReader</tt> to translate the plexus component descriptors
- to spring context XML document (using XSLT)</li>
- <li>a spring namespace dedicated to plexus, that mimics the plexus component descriptor format</li>
- <li>a FactoryBean to create and inject dependencies in plexus components</li>
- <li>a BeanPostProcessor to support plexus lifecycle interfaces in spring context
- (LogEnabled, Contextualizable, Initializable, Disposable).</li>
- <li>a <tt>PlexusContainerAdapter</tt> to support plexus-like lookups in spring context</li>
- </ul>
- To make life simplier, plexus-spring also provides a <tt>PlexusClassPathXmlApplicationContext</tt>
- that registers all necessary components and accepts either spring or plexus XML files as context locations.
- </p>
- </subsection>
- <subsection name="who is using it ?">
- <p>This adapter library has been created as part of the migration effort from plexus to spring
- in apache Archiva. It allows a smooth migration from plexus to spring as the initial components
- can be used as is in spring until they are migrated to be more spring compliant or replaced.
- </p>
- <p>It can also be used to support some plexus components packaged as jars that provide helpfull
- features to a spring-based application.
- </p>
- </subsection>
- </section>
-
- </body>
-
-</document>
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-/**\r
- * A typical plexus component implementation\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public class ComplexPlexusBean\r
-{\r
- /**\r
- * @plexus.requirement role="org.codehaus.plexus.spring.PlexusBean"\r
- */\r
- private Map plexusBeans;\r
-\r
- /**\r
- * @plexus.requirement role="org.codehaus.plexus.spring.PlexusBean"\r
- */\r
- private List beansList;\r
-\r
- /**\r
- * @see org.codehaus.plexus.spring.PlexusBean#toString()\r
- */\r
- public String toString()\r
- {\r
- return plexusBeans.size() + " components for role org.codehaus.plexus.spring.PlexusBean";\r
- }\r
-\r
- public Map getBeans()\r
- {\r
- return plexusBeans;\r
- }\r
-\r
- public List getBeansList()\r
- {\r
- return beansList;\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;
- }
-
-
-
-}
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-import org.codehaus.plexus.context.Context;\r
-import org.codehaus.plexus.logging.Logger;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-/**\r
- * A plexus component interface\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public interface PlexusBean\r
-{\r
- public static final String DISPOSED = "disposed";\r
-\r
- public static final String INITIALIZED = "initialized";\r
-\r
- String ROLE = PlexusBean.class.getName();\r
-\r
- String describe();\r
-\r
- String getState();\r
-\r
- Context getContext();\r
-\r
- Logger getLogger();\r
-}
\ No newline at end of file
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-import org.codehaus.plexus.context.Context;\r
-import org.codehaus.plexus.context.ContextException;\r
-import org.codehaus.plexus.logging.AbstractLogEnabled;\r
-import org.codehaus.plexus.logging.Logger;\r
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;\r
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;\r
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;\r
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-/**\r
- * A typical plexus component implementation\r
- *\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public class PlexusBeanImpl\r
- extends AbstractLogEnabled\r
- implements PlexusBean, Initializable, Disposable, Contextualizable\r
-{\r
- private String message;\r
-\r
- private String state = "undefined";\r
-\r
- /**\r
- * @plexus.requirement\r
- */\r
- private SpringBean bean;\r
-\r
- private Context context;\r
-\r
- public void initialize()\r
- throws InitializationException\r
- {\r
- state = INITIALIZED;\r
- }\r
-\r
- public void dispose()\r
- {\r
- state = DISPOSED;\r
- }\r
-\r
- public String describe()\r
- {\r
- getLogger().info( "Logger has been set" );\r
- return message + " " + bean.toString();\r
- }\r
-\r
- /**\r
- * @return the state\r
- */\r
- public String getState()\r
- {\r
- return state;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable#contextualize(org.codehaus.plexus.context.Context)\r
- */\r
- public void contextualize( Context context )\r
- throws ContextException\r
- {\r
- this.context = context;\r
- }\r
-\r
- public Context getContext()\r
- {\r
- return context;\r
- }\r
-\r
- public Logger getLogger()\r
- {\r
- return super.getLogger();\r
- }\r
-}\r
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-/*
- * 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 junit.framework.TestCase;
-
-import org.springframework.context.ConfigurableApplicationContext;
-
-public class PlexusClassPathXmlApplicationContextTest
- extends TestCase
-{
- /**
- * {@inheritDoc}
- *
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp()
- throws Exception
- {
- System.setProperty( "plexus-spring.debug", "true" );
- }
-
- public void testInjectSpringBeansInPlexusComponent()
- throws Exception
- {
- ConfigurableApplicationContext applicationContext =
- new PlexusClassPathXmlApplicationContext( new String[] {
- "testInjectSpringBeansInPlexusComponent.xml",
- "testInjectSpringBeansInPlexusComponent-context.xml" } );
- PlexusBean plexusBean = (PlexusBean) applicationContext.getBean( "plexusBean" );
- assertEquals( "field injection failed", "expected SpringBean", plexusBean.describe() );
- applicationContext.close();
- }
-
- public void testPlexusLifecycleSupport()
- throws Exception
- {
- ConfigurableApplicationContext applicationContext =
- new PlexusClassPathXmlApplicationContext( new String[] {
- "testPlexusLifecycleSupport.xml" } );
- PlexusBean plexusBean = (PlexusBean) applicationContext.getBean( "plexusBean" );
- assertEquals( PlexusBean.INITIALIZED, plexusBean.getState() );
- assertNotNull( plexusBean.getContext() );
- assertNotNull( plexusBean.getLogger() );
- applicationContext.close();
- assertEquals( PlexusBean.DISPOSED, plexusBean.getState() );
-
- }
-
- public void testInjectMapForRole()
- throws Exception
- {
- ConfigurableApplicationContext applicationContext =
- new PlexusClassPathXmlApplicationContext( new String[] {
- "testInjectMapForRole.xml",
- "testInjectMapForRole-context.xml" } );
- ComplexPlexusBean plexusBean = (ComplexPlexusBean) applicationContext.getBean( "complexPlexusBean" );
- assertTrue( plexusBean.getBeans().containsKey( "spring" ) );
- assertTrue( plexusBean.getBeans().containsKey( "plexus" ) );
- assertEquals( "2 components for role org.codehaus.plexus.spring.PlexusBean", plexusBean.toString() );
- }
-
- public void testInjectListForRole()
- throws Exception
- {
- ConfigurableApplicationContext applicationContext =
- new PlexusClassPathXmlApplicationContext( new String[] {
- "testInjectListForRole.xml",
- "testInjectListForRole-context.xml" } );
- ComplexPlexusBean plexusBean = (ComplexPlexusBean) applicationContext.getBean( "complexPlexusBean" );
- 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" ) );
- }
-
- public void testInjectProperties()
- throws Exception
- {
- ConfigurableApplicationContext applicationContext =
- new PlexusClassPathXmlApplicationContext( new String[] {
- "testInjectProperties.xml" } );
- PropertiesPlexusBean plexusBean = (PropertiesPlexusBean) applicationContext.getBean( "plexusBean" );
- assertEquals( "expected", plexusBean.getProperties().getProperty( "test" ) );
- }
-
-}
+++ /dev/null
-package org.codehaus.plexus.spring;
-
-import java.util.Properties;
-
-/*
- * 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 PropertiesPlexusBean
-{
- private Properties properties;
-
- public Properties getProperties()
- {
- return properties;
- }
-
-
-
-}
+++ /dev/null
-package org.codehaus.plexus.spring;\r
-\r
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-/**\r
- * A bean expected to live in the spring context\r
- * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- */\r
-public class SpringBean\r
-{\r
- public String toString()\r
- {\r
- return "SpringBean";\r
- }\r
-}\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>\r
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">\r
-<!-- ===================================================================== -->\r
-<!-- Log4j Configuration -->\r
-<!-- ===================================================================== -->\r
-\r
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"\r
- debug="false">\r
-\r
- <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">\r
- <param name="Target" value="System.out"/>\r
- <layout class="org.apache.log4j.PatternLayout">\r
- <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}.%M](%L) %m%n"/>\r
- </layout>\r
- </appender>\r
-\r
- <category name="org.springframework">\r
- <priority value="DEBUG"/>\r
- </category>\r
-\r
- <category name="org.codehaus">\r
- <priority value="DEBUG"/>\r
- </category>\r
-\r
- <root>\r
- <priority value="WARN"/>\r
- <appender-ref ref="CONSOLE"/>\r
- </root>\r
-\r
-</log4j:configuration>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
-
- <bean id="loggerManager" class="org.codehaus.plexus.logging.console.ConsoleLoggerManager"
- init-method="initialize"/>
-
- <bean name="plexusBean#spring" class="org.codehaus.plexus.spring.PlexusBeanImpl"/>
-
-</beans>
\ No newline at end of file
+++ /dev/null
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.spring.PlexusBean</role>
- <role-hint>plexus</role-hint>
- <implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>
- </component>
- <component>
- <role>org.codehaus.plexus.spring.ComplexPlexusBean</role>
- <implementation>org.codehaus.plexus.spring.ComplexPlexusBean</implementation>
- <requirements>
- <requirement>
- <field-name>beansList</field-name>
- <role>org.codehaus.plexus.spring.PlexusBean</role>
- </requirement>
- </requirements>
- </component>
- </components>
-</component-set>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<beans xmlns="http://www.springframework.org/schema/beans"\r
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
-\r
- <bean id="loggerManager" class="org.codehaus.plexus.logging.console.ConsoleLoggerManager"\r
- init-method="initialize"/>\r
-\r
- <bean name="plexusBean#spring" class="org.codehaus.plexus.spring.PlexusBeanImpl"/>\r
-\r
-</beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-\r
-<plexus>\r
-\r
- <components>\r
- <component>\r
- <role>org.codehaus.plexus.spring.PlexusBean</role>\r
- <role-hint>plexus</role-hint>\r
- <implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>\r
- </component>\r
- <component>\r
- <role>org.codehaus.plexus.spring.ComplexPlexusBean</role>\r
- <implementation>org.codehaus.plexus.spring.ComplexPlexusBean</implementation>\r
- <requirements>\r
- <requirement>\r
- <field-name>plexusBeans</field-name>\r
- <role>org.codehaus.plexus.spring.PlexusBean</role>\r
- </requirement>\r
- </requirements>\r
- </component>\r
- </components>\r
-\r
-</plexus>\r
+++ /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>
+++ /dev/null
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.spring.PlexusBean</role>
- <implementation>org.codehaus.plexus.spring.PropertiesPlexusBean</implementation>
- <configuration>
- <properties>
- <property>
- <name>test</name>
- <value>expected</value>
- </property>
- <property>
- <name>other</name>
- <value>value</value>
- </property>
- </properties>
- </configuration>
- </component>
- </components>
-</component-set>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
-
- <bean id="loggerManager" class="org.codehaus.plexus.logging.console.ConsoleLoggerManager"
- init-method="initialize"/>
-
- <bean id="springBean" class="org.codehaus.plexus.spring.SpringBean"/>
-
-</beans>
\ No newline at end of file
+++ /dev/null
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.spring.PlexusBean</role>
- <role-hint>default</role-hint>
- <implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>
- <requirements>
- <requirement>
- <!-- implicit field-injection : no field-name set -->
- <role>springBean</role>
- </requirement>
- </requirements>
- <configuration>
- <message>expected</message>
- </configuration>
- </component>
- </components>
-</component-set>
+++ /dev/null
-<component-set>
- <components>
- <component>
- <role>org.codehaus.plexus.spring.PlexusBean</role>
- <role-hint>default</role-hint>
- <implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>
- </component>
- </components>
-</component-set>