Author: nicolas
Date: Wed Feb 27 07:04:25 2008
New Revision: 631608
URL: http://svn.apache.org/viewvc?rev=631608&view=rev
Log:
Disposable lifecycle event moved in BeanPostProcessor
documentation
cleaner unit testing with dedicated context files for tested features
Added:
maven/archiva/branches/springy/plexus-spring/src/site/
maven/archiva/branches/springy/plexus-spring/src/site/site.xml (with
props)
maven/archiva/branches/springy/plexus-spring/src/site/xdoc/
maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml
(with props)
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
(with props)
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
(with props)
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
(with props)
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml
(contents, props changed)
- copied, changed from r630752,
maven/archiva/branches/springy/plexus-spring/src/test/resources/applicationContext.xml
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml
(contents, props changed)
- copied, changed from r631207,
maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
(with props)
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
(with props)
maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
(with props)
Removed:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/FieldInjectionTest.java
maven/archiva/branches/springy/plexus-spring/src/test/resources/applicationContext.xml
maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml
Modified:
maven/archiva/branches/springy/plexus-spring/pom.xml
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ComplexPlexusBean.java
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBean.java
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBeanImpl.java
Modified: maven/archiva/branches/springy/plexus-spring/pom.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/pom.xml?rev=631608&r1=631607&r2=631608&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/pom.xml (original)
+++ maven/archiva/branches/springy/plexus-spring/pom.xml Wed Feb 27 07:04:25
2008
@@ -21,6 +21,7 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId>
<version>1.0-SNAPSHOT</version>
+ <name>Plexus to Spring Adapter</name>
<description>
Bridge utility to use plexus components in a SpringFramework context.
Modified:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java?rev=631608&r1=631607&r2=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
Wed Feb 27 07:04:25 2008
@@ -29,14 +29,16 @@
/**
* A custom ClassPathXmlApplicationContext to support plexus
- * <tr>components.xml</tt> descriptors in Spring, with no changes required
- * to neither plexus nor spring beans.
+ * <tr>components.xml</tt> descriptors in Spring, with no changes required to
+ * neither plexus nor spring beans.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
*/
public class PlexusClassPathXmlApplicationContext
extends ClassPathXmlApplicationContext
{
+ private PlexusLifecycleBeanPostProcessor lifecycleBeanPostProcessor;
+
public PlexusClassPathXmlApplicationContext( String path, Class clazz )
throws BeansException
{
@@ -101,6 +103,7 @@
/**
* [EMAIL PROTECTED]
+ *
* @see
org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
*/
protected void postProcessBeanFactory( ConfigurableListableBeanFactory
beanFactory )
@@ -109,9 +112,27 @@
plexus.setApplicationContext( this );
beanFactory.registerSingleton( "plexusContainer", plexus );
- PlexusLifecycleBeanPostProcessor lifecycle = new
PlexusLifecycleBeanPostProcessor();
- lifecycle.setBeanFactory( this );
- beanFactory.addBeanPostProcessor( lifecycle );
+ lifecycleBeanPostProcessor = new PlexusLifecycleBeanPostProcessor();
+ lifecycleBeanPostProcessor.setBeanFactory( this );
+ beanFactory.addBeanPostProcessor( lifecycleBeanPostProcessor );
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @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 );
+ }
+ super.doClose();
}
}
Modified:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java?rev=631608&r1=631607&r2=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
Wed Feb 27 07:04:25 2008
@@ -68,7 +68,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
*/
public class PlexusComponentFactoryBean
- implements FactoryBean, BeanFactoryAware, DisposableBean
+ implements FactoryBean, BeanFactoryAware
{
/** Logger available to subclasses */
protected final Log logger = LogFactory.getLog( getClass() );
@@ -93,30 +93,7 @@
/** The plexus component requirements and configurations */
private Map requirements;
- /** The plexus component created by this FactoryBean */
- private List instances = new LinkedList();
-
- /**
- * [EMAIL PROTECTED]
- *
- * @see
org.springframework.beans.factory.config.AbstractFactoryBean#destroy()
- */
- public void destroy()
- throws Exception
- {
- synchronized ( instances )
- {
- for ( Iterator iterator = instances.iterator();
iterator.hasNext(); )
- {
- Object instance = iterator.next();
- if ( instance instanceof Disposable )
- {
- logger.trace( "Dispose plexus bean " + role );
- ( (Disposable) instance ).dispose();
- }
- }
- }
- }
+ private Object singletonInstance;
/**
* [EMAIL PROTECTED]
@@ -128,13 +105,14 @@
{
if ( isSingleton() )
{
- synchronized ( instances )
+ synchronized ( this )
{
- if ( !instances.isEmpty() )
+ if ( singletonInstance != null )
{
- return instances.get( 0 );
+ return singletonInstance;
}
- return createInstance();
+ this.singletonInstance = createInstance();
+ return singletonInstance;
}
}
return createInstance();
@@ -149,10 +127,6 @@
{
logger.debug( "Creating plexus component " + implementation );
final Object component = implementation.newInstance();
- synchronized ( instances )
- {
- instances.add( component );
- }
if ( requirements != null )
{
for ( Iterator iterator = requirements.entrySet().iterator();
iterator.hasNext(); )
Modified:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java?rev=631608&r1=631607&r2=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
Wed Feb 27 07:04:25 2008
@@ -19,6 +19,8 @@
* under the License.
*/
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -30,21 +32,22 @@
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.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
*/
public class PlexusLifecycleBeanPostProcessor
- implements BeanPostProcessor, BeanFactoryAware
+ implements BeanPostProcessor, BeanFactoryAware, DisposableBean
{
/** Logger available to subclasses */
protected final Log logger = LogFactory.getLog( getClass() );
@@ -55,6 +58,9 @@
private LoggerManager loggerManager;
+ /** The plexus Disposable components */
+ private Map disposables = new HashMap();
+
protected Context getContext()
{
if ( context == null )
@@ -91,7 +97,9 @@
/**
* [EMAIL PROTECTED]
- * @see
org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
java.lang.String)
+ *
+ * @see
org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
+ * java.lang.String)
*/
public Object postProcessBeforeInitialization( Object bean, String
beanName )
throws BeansException
@@ -99,10 +107,11 @@
return bean;
}
-
/**
* [EMAIL PROTECTED]
- * @see
org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
java.lang.String)
+ *
+ * @see
org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
+ * java.lang.String)
*/
public Object postProcessAfterInitialization( Object bean, String beanName
)
throws BeansException
@@ -144,7 +153,16 @@
}
catch ( InitializationException e )
{
- throw new BeanInitializationException( "Failed to invoke
plexus lifecycle Initializable.initialize on " + beanName, 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;
@@ -155,5 +173,23 @@
this.beanFactory = beanFactory;
}
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @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();
+ }
+ }
+ }
}
Added: maven/archiva/branches/springy/plexus-spring/src/site/site.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/site/site.xml?rev=631608&view=auto
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/site/site.xml (added)
+++ maven/archiva/branches/springy/plexus-spring/src/site/site.xml Wed Feb 27
07:04:25 2008
@@ -0,0 +1,36 @@
+<?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>
Propchange: maven/archiva/branches/springy/plexus-spring/src/site/site.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/branches/springy/plexus-spring/src/site/site.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: maven/archiva/branches/springy/plexus-spring/src/site/site.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml?rev=631608&view=auto
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml (added)
+++ maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml Wed
Feb 27 07:04:25 2008
@@ -0,0 +1,75 @@
+<?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>
Propchange: maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: maven/archiva/branches/springy/plexus-spring/src/site/xdoc/index.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ComplexPlexusBean.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ComplexPlexusBean.java?rev=631608&r1=631607&r2=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ComplexPlexusBean.java
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ComplexPlexusBean.java
Wed Feb 27 07:04:25 2008
@@ -1,5 +1,6 @@
package org.codehaus.plexus.spring;
+import java.util.List;
import java.util.Map;
/*
@@ -23,7 +24,7 @@
/**
* A typical plexus component implementation
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
*/
public class ComplexPlexusBean
@@ -34,10 +35,25 @@
private Map plexusBeans;
/**
+ * @plexus.requirement role="org.codehaus.plexus.spring.PlexusBean"
+ */
+ private List beansList;
+
+ /**
* @see org.codehaus.plexus.spring.PlexusBean#toString()
*/
public String toString()
{
return plexusBeans.size() + " components for role
org.codehaus.plexus.spring.PlexusBean";
+ }
+
+ public Map getBeans()
+ {
+ return plexusBeans;
+ }
+
+ public List getBeansList()
+ {
+ return beansList;
}
}
Modified:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBean.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBean.java?rev=631608&r1=631607&r2=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBean.java
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBean.java
Wed Feb 27 07:04:25 2008
@@ -1,5 +1,7 @@
package org.codehaus.plexus.spring;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.logging.Logger;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -22,16 +24,22 @@
/**
* A plexus component interface
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
*/
public interface PlexusBean
{
public static final String DISPOSED = "disposed";
+
public static final String INITIALIZED = "initialized";
+
String ROLE = PlexusBean.class.getName();
-
- String toString();
+
+ String describe();
String getState();
+ Context getContext();
+
+ Logger getLogger();
}
Modified:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBeanImpl.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBeanImpl.java?rev=631608&r1=631607&r2=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBeanImpl.java
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBeanImpl.java
Wed Feb 27 07:04:25 2008
@@ -1,6 +1,10 @@
package org.codehaus.plexus.spring;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.logging.Logger;
+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;
@@ -31,7 +35,7 @@
*/
public class PlexusBeanImpl
extends AbstractLogEnabled
- implements PlexusBean, Initializable, Disposable
+ implements PlexusBean, Initializable, Disposable, Contextualizable
{
private String message;
@@ -42,6 +46,8 @@
*/
private SpringBean bean;
+ private Context context;
+
public void initialize()
throws InitializationException
{
@@ -53,10 +59,7 @@
state = DISPOSED;
}
- /**
- * @see org.codehaus.plexus.spring.PlexusBean#toString()
- */
- public String toString()
+ public String describe()
{
getLogger().info( "Logger has been set" );
return message + " " + bean.toString();
@@ -70,4 +73,23 @@
return state;
}
+ /**
+ * [EMAIL PROTECTED]
+ * @see
org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable#contextualize(org.codehaus.plexus.context.Context)
+ */
+ public void contextualize( Context context )
+ throws ContextException
+ {
+ this.context = context;
+ }
+
+ public Context getContext()
+ {
+ return context;
+ }
+
+ public Logger getLogger()
+ {
+ return super.getLogger();
+ }
}
Added:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java?rev=631608&view=auto
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
(added)
+++
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
Wed Feb 27 07:04:25 2008
@@ -0,0 +1,91 @@
+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
+{
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @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() );
+ }
+
+}
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml?rev=631608&view=auto
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
(added)
+++
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
Wed Feb 27 07:04:25 2008
@@ -0,0 +1,11 @@
+<?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
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml?rev=631608&view=auto
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
(added)
+++
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
Wed Feb 27 07:04:25 2008
@@ -0,0 +1,19 @@
+<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>
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Copied:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml
(from r630752,
maven/archiva/branches/springy/plexus-spring/src/test/resources/applicationContext.xml)
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml?p2=maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml&p1=maven/archiva/branches/springy/plexus-spring/src/test/resources/applicationContext.xml&r1=630752&r2=631608&rev=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/resources/applicationContext.xml
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml
Wed Feb 27 07:04:25 2008
@@ -6,6 +6,6 @@
<bean id="loggerManager"
class="org.codehaus.plexus.logging.console.ConsoleLoggerManager"
init-method="initialize"/>
- <bean id="springBean" class="org.codehaus.plexus.spring.SpringBean"/>
+ <bean name="plexusBean#spring"
class="org.codehaus.plexus.spring.PlexusBeanImpl"/>
</beans>
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml
(from r631207,
maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml)
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml?p2=maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml&p1=maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml&r1=631207&r2=631608&rev=631608&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml
Wed Feb 27 07:04:25 2008
@@ -2,30 +2,8 @@
<components>
<component>
<role>org.codehaus.plexus.spring.PlexusBean</role>
- <role-hint>default</role-hint>
+ <role-hint>plexus</role-hint>
<implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>
- <requirements>
- <requirement>
- <role>springBean</role>
- </requirement>
- </requirements>
- <configuration>
- <message>expected</message>
- </configuration>
- </component>
- <component>
- <role>org.codehaus.plexus.spring.PlexusBean</role>
- <role-hint>another</role-hint>
-
<implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>
- <requirements>
- <requirement>
- <field-name>bean</field-name>
- <role>springBean</role>
- </requirement>
- </requirements>
- <configuration>
- <message>another</message>
- </configuration>
</component>
<component>
<role>org.codehaus.plexus.spring.ComplexPlexusBean</role>
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml?rev=631608&view=auto
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
(added)
+++
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
Wed Feb 27 07:04:25 2008
@@ -0,0 +1,11 @@
+<?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
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml?rev=631608&view=auto
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
(added)
+++
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
Wed Feb 27 07:04:25 2008
@@ -0,0 +1,18 @@
+<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>
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml?rev=631608&view=auto
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
(added)
+++
maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
Wed Feb 27 07:04:25 2008
@@ -0,0 +1,9 @@
+<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>
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml