archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r631290 - in /maven/archiva/branches/springy: archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ plexus-spring/ plexus-spring/src...
Date Tue, 26 Feb 2008 16:52:52 GMT
Author: nicolas
Date: Tue Feb 26 08:52:49 2008
New Revision: 631290

URL: http://svn.apache.org/viewvc?rev=631290&view=rev
Log:
plexus lifecycle handling moved to a BeanPostProcessor
BeanPostProcessor and PlexusContainerAdapter automatically registered in the ApplicationContext
fall back to ConsoleLoggerManager when no LoggerManager bean found
===========================================================
!!! archiva-proxy tests now pass as PlexusInSpringTests !!!
===========================================================

Added:
    maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
  (with props)
Removed:
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
Modified:
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml
    maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml
    maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml
    maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml
    maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml
    maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml
    maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml
    maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml
    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/PlexusContainerAdapter.java

Modified: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml
Tue Feb 26 08:52:49 2008
@@ -4,11 +4,6 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
-  <bean id="plexusContainer" class="org.codehaus.plexus.spring.PlexusContainerAdapter"/>
-
-  <bean id="loggerManager" class="org.codehaus.plexus.logging.console.ConsoleLoggerManager"
-     	init-method="initialize"/>
-
   <bean id="urlFailureCache" class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
     <!-- collaborators and configuration for this bean go here -->
     <constructor-arg ref="cache#url-failures-cache" type="org.codehaus.plexus.cache.Cache"/>

Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml
Tue Feb 26 08:52:49 2008
@@ -73,16 +73,16 @@
           <field-name>postDownloadPolicies</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.archiva.common.spring.SpringFactory</role>
-          <role-hint>default</role-hint>
-        </requirement>
-        <requirement>
           <role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
           <field-name>consumers</field-name>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
+          <field-name>urlFailureCache</field-name>
+        </requirement>
       </requirements>
     </component>
-    
+
     <component>
       <role>org.codehaus.plexus.cache.Cache</role>
       <role-hint>url-failures-cache</role-hint>
@@ -103,7 +103,7 @@
         <time-to-live-seconds>1800</time-to-live-seconds>
       </configuration>
     </component>
-        
+
     <component>
       <role>org.codehaus.plexus.logging.LoggerManager</role>
       <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>

Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml
Tue Feb 26 08:52:49 2008
@@ -73,16 +73,16 @@
           <field-name>postDownloadPolicies</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.archiva.common.spring.SpringFactory</role>
-          <role-hint>default</role-hint>
-        </requirement>
-        <requirement>
           <role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
           <field-name>consumers</field-name>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
+          <field-name>urlFailureCache</field-name>
+        </requirement>
       </requirements>
     </component>
-    
+
     <component>
       <role>org.codehaus.plexus.cache.Cache</role>
       <role-hint>url-failures-cache</role-hint>
@@ -103,7 +103,7 @@
         <time-to-live-seconds>1800</time-to-live-seconds>
       </configuration>
     </component>
-        
+
     <component>
       <role>org.codehaus.plexus.logging.LoggerManager</role>
       <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>

Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml
Tue Feb 26 08:52:49 2008
@@ -73,16 +73,16 @@
           <field-name>postDownloadPolicies</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.archiva.common.spring.SpringFactory</role>
-          <role-hint>default</role-hint>
-        </requirement>
-        <requirement>
           <role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
           <field-name>consumers</field-name>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
+          <field-name>urlFailureCache</field-name>
+        </requirement>
       </requirements>
     </component>
-    
+
     <component>
       <role>org.codehaus.plexus.cache.Cache</role>
       <role-hint>url-failures-cache</role-hint>
@@ -103,7 +103,7 @@
         <time-to-live-seconds>1800</time-to-live-seconds>
       </configuration>
     </component>
-        
+
     <component>
       <role>org.codehaus.plexus.logging.LoggerManager</role>
       <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>

Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml
Tue Feb 26 08:52:49 2008
@@ -42,8 +42,8 @@
         </requirement>
       </requirements>
     </component>
-    
-    
+
+
     <component>
       <role>org.apache.maven.archiva.repository.metadata.MetadataTools</role>
       <implementation>org.apache.maven.archiva.repository.metadata.MetadataTools</implementation>
@@ -64,7 +64,7 @@
         </requirement>
       </requirements>
     </component>
-    
+
     <component>
       <role>org.apache.maven.archiva.proxy.RepositoryProxyConnectors</role>
       <role-hint>default</role-hint>
@@ -96,16 +96,16 @@
           <field-name>postDownloadPolicies</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.archiva.common.spring.SpringFactory</role>
-          <role-hint>default</role-hint>
-        </requirement>
-        <requirement>
           <role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
           <field-name>consumers</field-name>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
+          <field-name>urlFailureCache</field-name>
+        </requirement>
       </requirements>
     </component>
-    
+
     <component>
       <role>org.codehaus.plexus.cache.Cache</role>
       <role-hint>url-failures-cache</role-hint>
@@ -126,7 +126,7 @@
         <time-to-live-seconds>1800</time-to-live-seconds>
       </configuration>
     </component>
-        
+
     <component>
       <role>org.codehaus.plexus.logging.LoggerManager</role>
       <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>

Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml
Tue Feb 26 08:52:49 2008
@@ -73,16 +73,16 @@
           <field-name>postDownloadPolicies</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.archiva.common.spring.SpringFactory</role>
-          <role-hint>default</role-hint>
-        </requirement>
-        <requirement>
           <role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
           <field-name>consumers</field-name>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
+          <field-name>urlFailureCache</field-name>
+        </requirement>
       </requirements>
     </component>
-    
+
     <component>
       <role>org.codehaus.plexus.cache.Cache</role>
       <role-hint>url-failures-cache</role-hint>
@@ -103,7 +103,7 @@
         <time-to-live-seconds>1800</time-to-live-seconds>
       </configuration>
     </component>
-        
+
     <component>
       <role>org.codehaus.plexus.logging.LoggerManager</role>
       <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>

Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml
Tue Feb 26 08:52:49 2008
@@ -73,16 +73,16 @@
           <field-name>postDownloadPolicies</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.archiva.common.spring.SpringFactory</role>
-          <role-hint>default</role-hint>
-        </requirement>
-        <requirement>
           <role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
           <field-name>consumers</field-name>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
+          <field-name>urlFailureCache</field-name>
+        </requirement>
       </requirements>
     </component>
-    
+
     <component>
       <role>org.codehaus.plexus.cache.Cache</role>
       <role-hint>url-failures-cache</role-hint>
@@ -103,7 +103,7 @@
         <time-to-live-seconds>1800</time-to-live-seconds>
       </configuration>
     </component>
-        
+
     <component>
       <role>org.codehaus.plexus.logging.LoggerManager</role>
       <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>

Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml
Tue Feb 26 08:52:49 2008
@@ -4,10 +4,6 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
-  <bean id="plexusContainer" class="org.codehaus.plexus.spring.PlexusContainerAdapter"/>
-
-  <bean id="loggerManager" class="org.codehaus.plexus.logging.console.ConsoleLoggerManager"
init-method="initialize"/>
-
   <bean id="urlFailureCache" class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
     <constructor-arg ref="cache#url-failures-cache" type="org.codehaus.plexus.cache.Cache"/>
   </bean>

Modified: maven/archiva/branches/springy/plexus-spring/pom.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/pom.xml?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/pom.xml (original)
+++ maven/archiva/branches/springy/plexus-spring/pom.xml Tue Feb 26 08:52:49 2008
@@ -43,6 +43,12 @@
       <version>1.0-alpha-22</version>
     </dependency>
     <dependency>
+      <!-- only required for ConsoleLogger -->
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-22</version>
+    </dependency>
+    <dependency>
       <!-- only required to debug XSLT result -->
       <groupId>dom4j</groupId>
       <artifactId>dom4j</artifactId>

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=631290&r1=631289&r2=631290&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
Tue Feb 26 08:52:49 2008
@@ -22,6 +22,7 @@
 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.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -96,6 +97,21 @@
         reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
         reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );
         super.loadBeanDefinitions( reader );
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
+     */
+    protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
+    {
+        PlexusContainerAdapter plexus = new PlexusContainerAdapter();
+        plexus.setApplicationContext( this );
+        beanFactory.registerSingleton( "plexusContainer", plexus );
+
+        PlexusLifecycleBeanPostProcessor lifecycle = new PlexusLifecycleBeanPostProcessor();
+        lifecycle.setBeanFactory( this );
+        beanFactory.addBeanPostProcessor( lifecycle );
     }
 
 }

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=631290&r1=631289&r2=631290&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
Tue Feb 26 08:52:49 2008
@@ -88,7 +88,7 @@
     private Class implementation;
 
     /** The plexus component instantiation strategy */
-    private String instantiationStrategy = SINGLETON;
+    private String instantiationStrategy;
 
     /** The plexus component requirements and configurations */
     private Map requirements;
@@ -96,12 +96,6 @@
     /** The plexus component created by this FactoryBean */
     private List instances = new LinkedList();
 
-    /** Optional plexus loggerManager */
-    private static LoggerManager loggerManager;
-
-    /** Optional plexus context */
-    private static Context context;
-
     /**
      * {@inheritDoc}
      *
@@ -114,10 +108,11 @@
         {
             for ( Iterator iterator = instances.iterator(); iterator.hasNext(); )
             {
-                Object isntance = iterator.next();
-                if ( isntance instanceof Disposable )
+                Object instance = iterator.next();
+                if ( instance instanceof Disposable )
                 {
-                    ( (Disposable) isntance ).dispose();
+                    logger.trace( "Dispose plexus bean " + role );
+                    ( (Disposable) instance ).dispose();
                 }
             }
         }
@@ -125,14 +120,22 @@
 
     /**
      * {@inheritDoc}
+     *
      * @see org.springframework.beans.factory.FactoryBean#getObject()
      */
     public Object getObject()
         throws Exception
     {
-        if ( isSingleton() && !instances.isEmpty())
+        if ( isSingleton() )
         {
-            return instances.get( 0 );
+            synchronized ( instances )
+            {
+                if ( !instances.isEmpty() )
+                {
+                    return instances.get( 0 );
+                }
+                return createInstance();
+            }
         }
         return createInstance();
     }
@@ -197,22 +200,19 @@
                 }
             }
         }
-
-        handlePlexusLifecycle( component );
-
         return component;
     }
 
     private Field findField( String fieldName )
     {
         Class clazz = implementation;
-        while (clazz != Object.class)
+        while ( clazz != Object.class )
         {
             try
             {
                 return clazz.getDeclaredField( fieldName );
             }
-            catch (NoSuchFieldException e)
+            catch ( NoSuchFieldException e )
             {
                 clazz = clazz.getSuperclass();
             }
@@ -222,28 +222,6 @@
         throw new BeanInitializationException( error );
     }
 
-    private void handlePlexusLifecycle( final Object component )
-        throws ContextException, InitializationException
-    {
-        if ( component instanceof LogEnabled )
-        {
-            ( (LogEnabled) component ).enableLogging( getLoggerManager().getLoggerForComponent(
role.getName() ) );
-        }
-
-        if ( component instanceof Contextualizable )
-        {
-            // VERRY limited support for Contextualizable
-            ( (Contextualizable) component ).contextualize( getContext() );
-        }
-
-        // TODO add support for Startable, Stopable -> LifeCycle ?
-
-        if ( component instanceof Initializable )
-        {
-            ( (Initializable) component ).initialize();
-        }
-    }
-
     /**
      * Resolve the requirement that this field exposes in the component
      *
@@ -288,19 +266,6 @@
         return SINGLETON.equals( instantiationStrategy );
     }
 
-    /**
-     * @return
-     */
-    protected Context getContext()
-    {
-        if ( context == null )
-        {
-            PlexusContainer container = (PlexusContainer) beanFactory.getBean( "plexusContainer"
);
-            context = container.getContext();
-        }
-        return context;
-    }
-
     protected TypeConverter getBeanTypeConverter()
     {
         if ( beanFactory instanceof ConfigurableBeanFactory )
@@ -313,35 +278,6 @@
         }
     }
 
-    /**
-     * 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
-            {
-                Map loggers = getListableBeanFactory().getBeansOfType( LoggerManager.class
);
-                if ( loggers.size() == 1 )
-                {
-                    loggerManager = (LoggerManager) loggers.values().iterator().next();
-                }
-            }
-        }
-        if ( loggerManager == null )
-        {
-            throw new BeanCreationException( "A LoggerManager instance must be set in the
applicationContext" );
-        }
-        return loggerManager;
-    }
-
     private ListableBeanFactory getListableBeanFactory()
     {
         if ( beanFactory instanceof ListableBeanFactory )
@@ -352,14 +288,6 @@
     }
 
     /**
-     * @param loggerManager the loggerManager to set
-     */
-    public void setLoggerManager( LoggerManager loggerManager )
-    {
-        PlexusComponentFactoryBean.loggerManager = loggerManager;
-    }
-
-    /**
      * @param role the role to set
      */
     public void setRole( Class role )
@@ -397,11 +325,6 @@
     public void setRequirements( Map requirements )
     {
         this.requirements = requirements;
-    }
-
-    public void setContext( Context context )
-    {
-        PlexusComponentFactoryBean.context = context;
     }
 
     public void setBeanFactory( BeanFactory beanFactory )

Modified: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java?rev=631290&r1=631289&r2=631290&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java
(original)
+++ maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java
Tue Feb 26 08:52:49 2008
@@ -55,6 +55,11 @@
     private ApplicationContext applicationContext;
 
 
+    public PlexusContainerAdapter()
+    {
+        super();
+    }
+
     /**
      * {@inheritDoc}
      * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()

Added: 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=631290&view=auto
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
(added)
+++ maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
Tue Feb 26 08:52:49 2008
@@ -0,0 +1,159 @@
+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.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.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.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
+{
+    /** Logger available to subclasses */
+    protected final Log logger = LogFactory.getLog( getClass() );
+
+    private BeanFactory beanFactory;
+
+    private Context context;
+
+    private LoggerManager loggerManager;
+
+    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 );
+            }
+        }
+        return bean;
+    }
+
+    public void setBeanFactory( BeanFactory beanFactory )
+    {
+        this.beanFactory = beanFactory;
+    }
+
+
+}

Propchange: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusLifecycleBeanPostProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message