]> source.dussan.org Git - archiva.git/commitdiff
Disposable lifecycle event moved in BeanPostProcessor
authorNicolas De Loof <nicolas@apache.org>
Wed, 27 Feb 2008 15:04:25 +0000 (15:04 +0000)
committerNicolas De Loof <nicolas@apache.org>
Wed, 27 Feb 2008 15:04:25 +0000 (15:04 +0000)
documentation
cleaner unit testing with dedicated context files for tested features

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@631608 13f79535-47bb-0310-9956-ffa450edef68

20 files changed:
springy/plexus-spring/pom.xml
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
springy/plexus-spring/src/site/site.xml [new file with mode: 0644]
springy/plexus-spring/src/site/xdoc/index.xml [new file with mode: 0644]
springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/ComplexPlexusBean.java
springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/FieldInjectionTest.java [deleted file]
springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBean.java
springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusBeanImpl.java
springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java [new file with mode: 0644]
springy/plexus-spring/src/test/resources/applicationContext.xml [deleted file]
springy/plexus-spring/src/test/resources/components.xml [deleted file]
springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml [new file with mode: 0644]
springy/plexus-spring/src/test/resources/testInjectListForRole.xml [new file with mode: 0644]
springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml [new file with mode: 0644]
springy/plexus-spring/src/test/resources/testInjectMapForRole.xml [new file with mode: 0644]
springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml [new file with mode: 0644]
springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml [new file with mode: 0644]
springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml [new file with mode: 0644]

index 876d29980d33efa86aa949413cae52cdd2123b87..b9fc5dfccd6266fd391933055489650624f4db08 100644 (file)
@@ -21,6 +21,7 @@
   <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
index 96acdb8e2538e963ba114976fce8253ff04b0cf6..32803473ca0f08631893198e4674265e499316b4 100644 (file)
@@ -29,14 +29,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
 \r
 /**\r
  * A custom ClassPathXmlApplicationContext to support plexus\r
- * <tr>components.xml</tt> descriptors in Spring, with no changes required\r
- * to neither plexus nor spring beans.\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 PlexusLifecycleBeanPostProcessor lifecycleBeanPostProcessor;\r
+\r
     public PlexusClassPathXmlApplicationContext( String path, Class clazz )\r
         throws BeansException\r
     {\r
@@ -101,6 +103,7 @@ public class PlexusClassPathXmlApplicationContext
 \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
@@ -109,9 +112,27 @@ public class PlexusClassPathXmlApplicationContext
         plexus.setApplicationContext( this );\r
         beanFactory.registerSingleton( "plexusContainer", plexus );\r
 \r
-        PlexusLifecycleBeanPostProcessor lifecycle = new PlexusLifecycleBeanPostProcessor();\r
-        lifecycle.setBeanFactory( this );\r
-        beanFactory.addBeanPostProcessor( lifecycle );\r
+        lifecycleBeanPostProcessor = new PlexusLifecycleBeanPostProcessor();\r
+        lifecycleBeanPostProcessor.setBeanFactory( this );\r
+        beanFactory.addBeanPostProcessor( lifecycleBeanPostProcessor );\r
+    }\r
+\r
+    /**\r
+     * {@inheritDoc}\r
+     *\r
+     * @see org.springframework.context.support.AbstractApplicationContext#doClose()\r
+     */\r
+    protected void doClose()\r
+    {\r
+        try\r
+        {\r
+            lifecycleBeanPostProcessor.destroy();\r
+        }\r
+        catch ( Throwable ex )\r
+        {\r
+            logger.error( "Exception thrown from PlexusLifecycleBeanPostProcessor handling ContextClosedEvent", ex );\r
+        }\r
+        super.doClose();\r
     }\r
 \r
 }\r
index 636c78ad198d5f70f227095d72df995bbb2074c9..b41b056a6df313b6eb97a0c341afb7aa4a55c188 100644 (file)
@@ -68,7 +68,7 @@ import org.springframework.util.ReflectionUtils;
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
  */\r
 public class PlexusComponentFactoryBean\r
-    implements FactoryBean, BeanFactoryAware, DisposableBean\r
+    implements FactoryBean, BeanFactoryAware\r
 {\r
     /** Logger available to subclasses */\r
     protected final Log logger = LogFactory.getLog( getClass() );\r
@@ -93,30 +93,7 @@ public class PlexusComponentFactoryBean
     /** The plexus component requirements and configurations */\r
     private Map requirements;\r
 \r
-    /** The plexus component created by this FactoryBean */\r
-    private List instances = new LinkedList();\r
-\r
-    /**\r
-     * {@inheritDoc}\r
-     *\r
-     * @see org.springframework.beans.factory.config.AbstractFactoryBean#destroy()\r
-     */\r
-    public void destroy()\r
-        throws Exception\r
-    {\r
-        synchronized ( instances )\r
-        {\r
-            for ( Iterator iterator = instances.iterator(); iterator.hasNext(); )\r
-            {\r
-                Object instance = iterator.next();\r
-                if ( instance instanceof Disposable )\r
-                {\r
-                    logger.trace( "Dispose plexus bean " + role );\r
-                    ( (Disposable) instance ).dispose();\r
-                }\r
-            }\r
-        }\r
-    }\r
+    private Object singletonInstance;\r
 \r
     /**\r
      * {@inheritDoc}\r
@@ -128,13 +105,14 @@ public class PlexusComponentFactoryBean
     {\r
         if ( isSingleton() )\r
         {\r
-            synchronized ( instances )\r
+            synchronized ( this )\r
             {\r
-                if ( !instances.isEmpty() )\r
+                if ( singletonInstance != null )\r
                 {\r
-                    return instances.get( 0 );\r
+                    return singletonInstance;\r
                 }\r
-                return createInstance();\r
+                this.singletonInstance = createInstance();\r
+                return singletonInstance;\r
             }\r
         }\r
         return createInstance();\r
@@ -149,10 +127,6 @@ public class PlexusComponentFactoryBean
     {\r
         logger.debug( "Creating plexus component " + implementation );\r
         final Object component = implementation.newInstance();\r
-        synchronized ( instances )\r
-        {\r
-            instances.add( component );\r
-        }\r
         if ( requirements != null )\r
         {\r
             for ( Iterator iterator = requirements.entrySet().iterator(); iterator.hasNext(); )\r
index a1c4714460afe587d05ab222b86c36a9acd07eec..2e25fca2707ba8771ab6d5e23b0f48d9fc8a2820 100644 (file)
@@ -19,6 +19,8 @@ package org.codehaus.plexus.spring;
  * 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.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.ListableBeanFactory;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 
 /**
  * @author <a href="mailto:nicolas@apache.org">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 @@ public class PlexusLifecycleBeanPostProcessor
 
     private LoggerManager loggerManager;
 
+    /** The plexus Disposable components */
+    private Map disposables = new HashMap();
+
     protected Context getContext()
     {
         if ( context == null )
@@ -91,7 +97,9 @@ public class PlexusLifecycleBeanPostProcessor
 
     /**
      * {@inheritDoc}
-     * @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 @@ public class PlexusLifecycleBeanPostProcessor
         return bean;
     }
 
-
     /**
      * {@inheritDoc}
-     * @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 @@ public class PlexusLifecycleBeanPostProcessor
             }
             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 @@ public class PlexusLifecycleBeanPostProcessor
         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();
+            }
+        }
+    }
 
 }
diff --git a/springy/plexus-spring/src/site/site.xml b/springy/plexus-spring/src/site/site.xml
new file mode 100644 (file)
index 0000000..de1b954
--- /dev/null
@@ -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>
diff --git a/springy/plexus-spring/src/site/xdoc/index.xml b/springy/plexus-spring/src/site/xdoc/index.xml
new file mode 100644 (file)
index 0000000..a177e1d
--- /dev/null
@@ -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>
index f3e9e72149ad7a46743e57631a5ce61779fe6c8c..fd1a7a9cca81144f6341a67d25caf24c674d9953 100644 (file)
@@ -1,5 +1,6 @@
 package org.codehaus.plexus.spring;\r
 \r
+import java.util.List;\r
 import java.util.Map;\r
 \r
 /*\r
@@ -23,7 +24,7 @@ import java.util.Map;
 \r
 /**\r
  * A typical plexus component implementation\r
- * \r
+ *\r
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
  */\r
 public class ComplexPlexusBean\r
@@ -33,6 +34,11 @@ public class ComplexPlexusBean
      */\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
@@ -40,4 +46,14 @@ public class ComplexPlexusBean
     {\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
diff --git a/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/FieldInjectionTest.java b/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/FieldInjectionTest.java
deleted file mode 100644 (file)
index 57980cb..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-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 junit.framework.TestCase;\r
-\r
-import org.springframework.context.ConfigurableApplicationContext;\r
-\r
-public class FieldInjectionTest\r
-    extends TestCase\r
-{\r
-    /**\r
-     * {@inheritDoc}\r
-     * @see junit.framework.TestCase#setUp()\r
-     */\r
-    protected void setUp()\r
-        throws Exception\r
-    {\r
-        System.setProperty( "plexus-spring.debug", "true" );\r
-    }\r
-\r
-    public void testFieldInjectionInSpringContext()\r
-        throws Exception\r
-    {\r
-        ConfigurableApplicationContext applicationContext = new PlexusClassPathXmlApplicationContext( new String[] { "components.xml", "applicationContext.xml" } );\r
-        PlexusBean plexusBean = (PlexusBean) applicationContext.getBean( "plexusBean" );\r
-        assertEquals( PlexusBean.INITIALIZED, plexusBean.getState() );\r
-        assertEquals( "field injection failed", "expected SpringBean", plexusBean.toString() );\r
-        applicationContext.close();\r
-        assertEquals( PlexusBean.DISPOSED, plexusBean.getState() );\r
-\r
-    }\r
-\r
-    public void testInjectMapForRole()\r
-        throws Exception\r
-    {\r
-        ConfigurableApplicationContext applicationContext = new PlexusClassPathXmlApplicationContext( new String[] { "components.xml", "applicationContext.xml" } );\r
-        ComplexPlexusBean plexusBean = (ComplexPlexusBean) applicationContext.getBean( "complexPlexusBean" );\r
-        assertEquals( "2 components for role org.codehaus.plexus.spring.PlexusBean", plexusBean.toString() );\r
-    }\r
-\r
-}\r
index a40247be92fc79794ac6d0dd58947220055fb842..32a7b4d4c93079705089e16b9367fa55be3ca9a3 100644 (file)
@@ -1,5 +1,7 @@
 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
@@ -22,16 +24,22 @@ package org.codehaus.plexus.spring;
 \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 toString();\r
+\r
+    String describe();\r
 \r
     String getState();\r
 \r
+    Context getContext();\r
+\r
+    Logger getLogger();\r
 }
\ No newline at end of file
index c810542c5ae3c33722b39f056c8aae97506a75a9..a6c8ddd8a73c68727742f8f56823bfbac485c117 100644 (file)
@@ -1,6 +1,10 @@
 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
@@ -31,7 +35,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
  */\r
 public class PlexusBeanImpl\r
     extends AbstractLogEnabled\r
-    implements PlexusBean, Initializable, Disposable\r
+    implements PlexusBean, Initializable, Disposable, Contextualizable\r
 {\r
     private String message;\r
 \r
@@ -42,6 +46,8 @@ public class PlexusBeanImpl
      */\r
     private SpringBean bean;\r
 \r
+    private Context context;\r
+\r
     public void initialize()\r
         throws InitializationException\r
     {\r
@@ -53,10 +59,7 @@ public class PlexusBeanImpl
         state = DISPOSED;\r
     }\r
 \r
-    /**\r
-     * @see org.codehaus.plexus.spring.PlexusBean#toString()\r
-     */\r
-    public String toString()\r
+    public String describe()\r
     {\r
         getLogger().info( "Logger has been set" );\r
         return message + " " + bean.toString();\r
@@ -70,4 +73,23 @@ public class PlexusBeanImpl
         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
diff --git a/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java b/springy/plexus-spring/src/test/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContextTest.java
new file mode 100644 (file)
index 0000000..59c7143
--- /dev/null
@@ -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
+{
+    /**
+     * {@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() );
+    }
+
+}
diff --git a/springy/plexus-spring/src/test/resources/applicationContext.xml b/springy/plexus-spring/src/test/resources/applicationContext.xml
deleted file mode 100644 (file)
index 6292ca5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?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 id="springBean" class="org.codehaus.plexus.spring.SpringBean"/>\r
-\r
-</beans>
\ No newline at end of file
diff --git a/springy/plexus-spring/src/test/resources/components.xml b/springy/plexus-spring/src/test/resources/components.xml
deleted file mode 100644 (file)
index bdc9a36..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<component-set>\r
-  <components>\r
-    <component>\r
-      <role>org.codehaus.plexus.spring.PlexusBean</role>\r
-      <role-hint>default</role-hint>\r
-      <implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>\r
-      <requirements>\r
-       <requirement>\r
-               <role>springBean</role>\r
-       </requirement>\r
-      </requirements>\r
-      <configuration>\r
-        <message>expected</message>\r
-      </configuration>\r
-    </component>\r
-    <component>\r
-      <role>org.codehaus.plexus.spring.PlexusBean</role>\r
-      <role-hint>another</role-hint>\r
-      <implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>\r
-      <requirements>\r
-       <requirement>\r
-               <field-name>bean</field-name>\r
-               <role>springBean</role>\r
-       </requirement>\r
-      </requirements>\r
-      <configuration>\r
-        <message>another</message>\r
-      </configuration>\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
-</component-set>\r
diff --git a/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml b/springy/plexus-spring/src/test/resources/testInjectListForRole-context.xml
new file mode 100644 (file)
index 0000000..49db313
--- /dev/null
@@ -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
diff --git a/springy/plexus-spring/src/test/resources/testInjectListForRole.xml b/springy/plexus-spring/src/test/resources/testInjectListForRole.xml
new file mode 100644 (file)
index 0000000..07e623f
--- /dev/null
@@ -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>
diff --git a/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml b/springy/plexus-spring/src/test/resources/testInjectMapForRole-context.xml
new file mode 100644 (file)
index 0000000..70c1e4f
--- /dev/null
@@ -0,0 +1,11 @@
+<?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
diff --git a/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml b/springy/plexus-spring/src/test/resources/testInjectMapForRole.xml
new file mode 100644 (file)
index 0000000..819b38c
--- /dev/null
@@ -0,0 +1,19 @@
+<component-set>\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
+</component-set>\r
diff --git a/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml b/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent-context.xml
new file mode 100644 (file)
index 0000000..9ab6831
--- /dev/null
@@ -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
diff --git a/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml b/springy/plexus-spring/src/test/resources/testInjectSpringBeansInPlexusComponent.xml
new file mode 100644 (file)
index 0000000..e7e5a00
--- /dev/null
@@ -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>
diff --git a/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml b/springy/plexus-spring/src/test/resources/testPlexusLifecycleSupport.xml
new file mode 100644 (file)
index 0000000..4450961
--- /dev/null
@@ -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>