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"/>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
-
- <bean id="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"/>
- </bean>
-</beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
-
- <bean id="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"/>
- </bean>
-</beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
-
- <bean id="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"/>
- </bean>
-</beans>
\ No newline at end of file
<role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
<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>
<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>
<role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
<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>
<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>
<role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
<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>
<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>
</requirement>
</requirements>
</component>
-
-
+
+
<component>
<role>org.apache.maven.archiva.repository.metadata.MetadataTools</role>
<implementation>org.apache.maven.archiva.repository.metadata.MetadataTools</implementation>
</requirement>
</requirements>
</component>
-
+
<component>
<role>org.apache.maven.archiva.proxy.RepositoryProxyConnectors</role>
<role-hint>default</role-hint>
<role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
<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>
<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>
<role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
<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>
<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>
<role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
<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>
<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>
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>
<artifactId>plexus-component-api</artifactId>\r
<version>1.0-alpha-22</version>\r
</dependency>\r
+ <dependency>\r
+ <!-- only required for ConsoleLogger -->\r
+ <groupId>org.codehaus.plexus</groupId>\r
+ <artifactId>plexus-container-default</artifactId>\r
+ <version>1.0-alpha-22</version>\r
+ </dependency>\r
<dependency>\r
<!-- only required to debug XSLT result -->\r
<groupId>dom4j</groupId>\r
import java.io.IOException;\r
\r
import org.springframework.beans.BeansException;\r
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;\r
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;\r
import org.springframework.context.ApplicationContext;\r
import org.springframework.context.support.ClassPathXmlApplicationContext;\r
super.loadBeanDefinitions( reader );\r
}\r
\r
+ /**\r
+ * {@inheritDoc}\r
+ * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)\r
+ */\r
+ protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )\r
+ {\r
+ PlexusContainerAdapter plexus = new PlexusContainerAdapter();\r
+ plexus.setApplicationContext( this );\r
+ beanFactory.registerSingleton( "plexusContainer", plexus );\r
+\r
+ PlexusLifecycleBeanPostProcessor lifecycle = new PlexusLifecycleBeanPostProcessor();\r
+ lifecycle.setBeanFactory( this );\r
+ beanFactory.addBeanPostProcessor( lifecycle );\r
+ }\r
+\r
}\r
private Class implementation;\r
\r
/** The plexus component instantiation strategy */\r
- private String instantiationStrategy = SINGLETON;\r
+ private String instantiationStrategy;\r
\r
/** The plexus component requirements and configurations */\r
private Map requirements;\r
/** The plexus component created by this FactoryBean */\r
private List instances = new LinkedList();\r
\r
- /** Optional plexus loggerManager */\r
- private static LoggerManager loggerManager;\r
-\r
- /** Optional plexus context */\r
- private static Context context;\r
-\r
/**\r
* {@inheritDoc}\r
*\r
{\r
for ( Iterator iterator = instances.iterator(); iterator.hasNext(); )\r
{\r
- Object isntance = iterator.next();\r
- if ( isntance instanceof Disposable )\r
+ Object instance = iterator.next();\r
+ if ( instance instanceof Disposable )\r
{\r
- ( (Disposable) isntance ).dispose();\r
+ logger.trace( "Dispose plexus bean " + role );\r
+ ( (Disposable) instance ).dispose();\r
}\r
}\r
}\r
\r
/**\r
* {@inheritDoc}\r
+ *\r
* @see org.springframework.beans.factory.FactoryBean#getObject()\r
*/\r
public Object getObject()\r
throws Exception\r
{\r
- if ( isSingleton() && !instances.isEmpty())\r
+ if ( isSingleton() )\r
{\r
- return instances.get( 0 );\r
+ synchronized ( instances )\r
+ {\r
+ if ( !instances.isEmpty() )\r
+ {\r
+ return instances.get( 0 );\r
+ }\r
+ return createInstance();\r
+ }\r
}\r
return createInstance();\r
}\r
}\r
}\r
}\r
-\r
- handlePlexusLifecycle( component );\r
-\r
return component;\r
}\r
\r
private Field findField( String fieldName )\r
{\r
Class clazz = implementation;\r
- while (clazz != Object.class)\r
+ while ( clazz != Object.class )\r
{\r
try\r
{\r
return clazz.getDeclaredField( fieldName );\r
}\r
- catch (NoSuchFieldException e)\r
+ catch ( NoSuchFieldException e )\r
{\r
clazz = clazz.getSuperclass();\r
}\r
throw new BeanInitializationException( error );\r
}\r
\r
- private void handlePlexusLifecycle( final Object component )\r
- throws ContextException, InitializationException\r
- {\r
- if ( component instanceof LogEnabled )\r
- {\r
- ( (LogEnabled) component ).enableLogging( getLoggerManager().getLoggerForComponent( role.getName() ) );\r
- }\r
-\r
- if ( component instanceof Contextualizable )\r
- {\r
- // VERRY limited support for Contextualizable\r
- ( (Contextualizable) component ).contextualize( getContext() );\r
- }\r
-\r
- // TODO add support for Startable, Stopable -> LifeCycle ?\r
-\r
- if ( component instanceof Initializable )\r
- {\r
- ( (Initializable) component ).initialize();\r
- }\r
- }\r
-\r
/**\r
* Resolve the requirement that this field exposes in the component\r
*\r
return SINGLETON.equals( instantiationStrategy );\r
}\r
\r
- /**\r
- * @return\r
- */\r
- protected Context getContext()\r
- {\r
- if ( context == null )\r
- {\r
- PlexusContainer container = (PlexusContainer) beanFactory.getBean( "plexusContainer" );\r
- context = container.getContext();\r
- }\r
- return context;\r
- }\r
-\r
protected TypeConverter getBeanTypeConverter()\r
{\r
if ( beanFactory instanceof ConfigurableBeanFactory )\r
}\r
}\r
\r
- /**\r
- * Retrieve the loggerManager instance to be used for LogEnabled components\r
- *\r
- * @return\r
- */\r
- protected LoggerManager getLoggerManager()\r
- {\r
- if ( loggerManager == null )\r
- {\r
- if ( beanFactory.containsBean( "loggerManager" ) )\r
- {\r
- loggerManager = (LoggerManager) beanFactory.getBean( "loggerManager" );\r
- }\r
- else\r
- {\r
- Map loggers = getListableBeanFactory().getBeansOfType( LoggerManager.class );\r
- if ( loggers.size() == 1 )\r
- {\r
- loggerManager = (LoggerManager) loggers.values().iterator().next();\r
- }\r
- }\r
- }\r
- if ( loggerManager == null )\r
- {\r
- throw new BeanCreationException( "A LoggerManager instance must be set in the applicationContext" );\r
- }\r
- return loggerManager;\r
- }\r
-\r
private ListableBeanFactory getListableBeanFactory()\r
{\r
if ( beanFactory instanceof ListableBeanFactory )\r
throw new BeanInitializationException( "A ListableBeanFactory is required by the PlexusComponentFactoryBean" );\r
}\r
\r
- /**\r
- * @param loggerManager the loggerManager to set\r
- */\r
- public void setLoggerManager( LoggerManager loggerManager )\r
- {\r
- PlexusComponentFactoryBean.loggerManager = loggerManager;\r
- }\r
-\r
/**\r
* @param role the role to set\r
*/\r
this.requirements = requirements;\r
}\r
\r
- public void setContext( Context context )\r
- {\r
- PlexusComponentFactoryBean.context = context;\r
- }\r
-\r
public void setBeanFactory( BeanFactory beanFactory )\r
{\r
this.beanFactory = beanFactory;\r
private ApplicationContext applicationContext;
+ public PlexusContainerAdapter()
+ {
+ super();
+ }
+
/**
* {@inheritDoc}
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
--- /dev/null
+package org.codehaus.plexus.spring;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.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;
+ }
+
+
+}