Author: nicolas
Date: Mon Feb 25 01:20:06 2008
New Revision: 630773
URL: http://svn.apache.org/viewvc?rev=630773&view=rev
Log:
fix NullPointer in CommonsConfiguration.initialize (must call enableLogger()
before initialize())
add support for Plexus List<components for role> injection
(RepositoryContentConsumers)
remove spring support classes from archiva-commons
PlexusInSpringTestCase to replace PlexusTestCase with as fiew as possible
changes
apply plexus-spring on archiva-policies
apply plexus-spring on archiva-proxy (some test failure to investigate)
Added:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
(with props)
Removed:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/
Modified:
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/log4j.xml
maven/archiva/branches/springy/archiva-base/archiva-proxy/pom.xml
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.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/ (props changed)
maven/archiva/branches/springy/plexus-spring/pom.xml
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/PlexusToSpringUtils.java
Modified:
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java
(original)
+++
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java
Mon Feb 25 01:20:06 2008
@@ -22,10 +22,11 @@
import java.io.File;
import java.util.Properties;
-import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext;
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
import org.codehaus.plexus.PlexusTestCase;
-import org.springframework.context.ApplicationContext;
+import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.springframework.context.ConfigurableApplicationContext;
/**
* CachedFailuresPolicyTest
@@ -34,14 +35,12 @@
* @version $Id$
*/
public class CachedFailuresPolicyTest
- extends PlexusTestCase
+ extends PlexusInSpringTestCase
{
- private ApplicationContext factory;
-
private DownloadPolicy lookupPolicy()
throws Exception
{
- return (DownloadPolicy) factory.getBean(
"preDownloadPolicy#cache-failures" );
+ return (DownloadPolicy) lookup( PreDownloadPolicy.class,
"cache-failures" );
}
private File getFile()
@@ -89,7 +88,7 @@
String url = "http://a.bad.hostname.maven.org/path/to/resource.txt";
- UrlFailureCache urlFailureCache = (UrlFailureCache) factory.getBean(
"urlFailureCache" );
+ UrlFailureCache urlFailureCache = (UrlFailureCache) lookup(
"urlFailureCache" );
urlFailureCache.cacheFailure( url );
request.setProperty( "url", url );
@@ -103,17 +102,5 @@
{
// expected path.
}
- }
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- factory = new PlexusClassPathXmlApplicationContext(
- new String[] {
- "classpath*:META-INF/plexus/components.xml",
- "classpath*:META-INF/plexus/components-fragment.xml",
-
"/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml" } );
}
}
Modified:
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/log4j.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/log4j.xml?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/log4j.xml
(original)
+++
maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/log4j.xml
Mon Feb 25 01:20:06 2008
@@ -39,10 +39,10 @@
<level value="error"/>
</logger>
- <logger name="org.springframewrok">
+ <logger name="org.springframework">
<level value="DEBUG"/>
</logger>
-
+
<root>
<priority value ="info" />
<appender-ref ref="console" />
Modified: maven/archiva/branches/springy/archiva-base/archiva-proxy/pom.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/pom.xml?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-proxy/pom.xml (original)
+++ maven/archiva/branches/springy/archiva-base/archiva-proxy/pom.xml Mon Feb
25 01:20:06 2008
@@ -29,6 +29,11 @@
<name>Archiva Base :: Proxy</name>
<dependencies>
<dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-spring</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
</dependency>
Modified:
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
(original)
+++
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
Mon Feb 25 01:20:06 2008
@@ -19,9 +19,18 @@
* under the License.
*/
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Locale;
+
import org.apache.commons.io.FileUtils;
-import
org.apache.maven.archiva.common.spring.PlexusClassPathXmlApplicationContext;
-import org.apache.maven.archiva.common.spring.PlexusFactory;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
@@ -32,22 +41,10 @@
import org.apache.maven.archiva.policies.SnapshotsPolicy;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.wagon.Wagon;
-import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.xml.XmlBeanFactory;
-import org.springframework.core.io.ClassPathResource;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Locale;
/**
* AbstractProxyTestCase
@@ -56,7 +53,7 @@
* @version $Id$
*/
public abstract class AbstractProxyTestCase
- extends PlexusTestCase
+ extends PlexusInSpringTestCase
{
protected static final String ID_LEGACY_PROXIED = "legacy-proxied";
@@ -106,8 +103,6 @@
protected MockConfiguration config;
- protected BeanFactory factory;
-
protected void assertChecksums( File expectedFile, String
expectedSha1Contents, String expectedMd5Contents )
throws Exception
{
@@ -376,18 +371,22 @@
return repoLocation;
}
+ /**
+ * [EMAIL PROTECTED]
+ * @see
org.codehaus.plexus.spring.PlexusInSpringTestCase#getConfigLocation()
+ */
+ @Override
+ protected String getSpringConfigLocation()
+ throws Exception
+ {
+ return "org/apache/maven/archiva/proxy/spring-context.xml";
+ }
+
@Override
protected void setUp()
throws Exception
{
super.setUp();
-
- factory = new PlexusClassPathXmlApplicationContext(
- new String[] {
- "classpath*:META-INF/plexus/components.xml",
- "classpath*:META-INF/plexus/components-fragment.xml",
- "classpath*:META-INF/spring/applicationContext.xml",
- "classpath:/org/apache/maven/archiva/proxy/spring-context.xml"
} );
config = (MockConfiguration) lookup(
ArchivaConfiguration.class.getName(), "mock" );
Modified:
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java
(original)
+++
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java
Mon Feb 25 01:20:06 2008
@@ -49,9 +49,9 @@
String path =
"org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
path );
setupTestableManagedRepository( path );
-
+
assertNotExistsInManagedDefaultRepo( expectedFile );
-
+
ArtifactReference artifact =
managedDefaultRepository.toArtifactReference( path );
// Configure Repository (usually done within archiva.xml configuration)
@@ -72,13 +72,13 @@
File downloadedFile = proxyHandler.fetchFromProxies(
managedDefaultRepository, artifact );
wagonMockControl.verify();
-
+
// Second attempt to download same artifact use cache
wagonMockControl.reset();
wagonMockControl.replay();
downloadedFile = proxyHandler.fetchFromProxies(
managedDefaultRepository, artifact );
wagonMockControl.verify();
-
+
assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
}
@@ -91,7 +91,7 @@
setupTestableManagedRepository( path );
assertNotExistsInManagedDefaultRepo( expectedFile );
-
+
ArtifactReference artifact =
managedDefaultRepository.toArtifactReference( path );
// Configure Repository (usually done within archiva.xml configuration)
@@ -118,11 +118,11 @@
wagonMock.get( path, new File( expectedFile.getParentFile(),
expectedFile.getName() + ".tmp" ) );
wagonMockControl.setThrowable( new ResourceDoesNotExistException(
"resource does not exist." ), 2 );
wagonMockControl.replay();
-
+
downloadedFile = proxyHandler.fetchFromProxies(
managedDefaultRepository, artifact );
-
+
wagonMockControl.verify();
-
+
assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
}
@@ -160,7 +160,7 @@
protected UrlFailureCache lookupUrlFailureCache()
throws Exception
{
- UrlFailureCache urlFailureCache = (UrlFailureCache) factory.getBean(
"urlFailureCache" );
+ UrlFailureCache urlFailureCache = (UrlFailureCache) lookup(
"urlFailureCache" );
assertNotNull( "URL Failure Cache cannot be null.", urlFailureCache );
return urlFailureCache;
}
Modified:
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml
(original)
+++
maven/archiva/branches/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml
Mon Feb 25 01:20:06 2008
@@ -73,10 +73,6 @@
<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>
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=630773&r1=630772&r2=630773&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
Mon Feb 25 01:20:06 2008
@@ -4,6 +4,8 @@
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="urlFailureCache"
class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
<constructor-arg ref="cache#url-failures-cache"
type="org.codehaus.plexus.cache.Cache"/>
</bean>
Propchange: maven/archiva/branches/springy/plexus-spring/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Feb 25 01:20:06 2008
@@ -1,2 +1,3 @@
-.* target bin *.log
-
+.* target bin *.log
+.classpath
+.project
Modified: maven/archiva/branches/springy/plexus-spring/pom.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/pom.xml?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/pom.xml (original)
+++ maven/archiva/branches/springy/plexus-spring/pom.xml Mon Feb 25 01:20:06
2008
@@ -14,45 +14,53 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
- http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-spring</artifactId>
+ <version>1.0-SNAPSHOT</version>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-spring</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <description>
+ Bridge utility to use plexus components in a SpringFramework context.
+ </description>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>2.5.1</version>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.2</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-api</artifactId>
- <version>1.0-alpha-33</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>2.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ <version>1.0-alpha-33</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-log4j-logging</artifactId>
+ <version>1.1-alpha-3</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-log4j-logging</artifactId>
- <version>1.1-alpha-3</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-</project>
+ <developers>
+ <developer>
+ <email>[EMAIL PROTECTED]</email>
+ <name>Nicolas De Loof</name>
+ </developer>
+ </developers>
+</project>
\ No newline at end of file
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=630773&r1=630772&r2=630773&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
Mon Feb 25 01:20:06 2008
@@ -20,6 +20,7 @@
*/
import java.lang.reflect.Field;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -31,6 +32,8 @@
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.springframework.beans.BeansException;
+import org.springframework.beans.SimpleTypeConverter;
+import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanInitializationException;
@@ -50,11 +53,11 @@
* </ul>
* If not set, the beanFActory will auto-detect the loggerManager to use by
searching for the adequate bean in the
* spring context.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
*/
public class PlexusComponentFactoryBean
- implements FactoryBean, BeanFactoryAware, InitializingBean, DisposableBean
+ implements FactoryBean, BeanFactoryAware, DisposableBean
{
private Class role;
@@ -68,29 +71,9 @@
private LoggerManager loggerManager;
- private List instances = new LinkedList();
+ private TypeConverter typeConverter = new SimpleTypeConverter();
- public void afterPropertiesSet()
- throws Exception
- {
- if ( loggerManager == null )
- {
- if ( beanFactory.containsBean( "loggerManager" ) )
- {
- loggerManager = (LoggerManager) beanFactory.getBean(
"loggerManager" );
- }
- Map loggers = beanFactory.getBeansOfType( LoggerManager.class );
- if ( loggers.size() == 1 )
- {
- loggerManager = (LoggerManager)
loggers.values().iterator().next();
- }
- else
- {
- throw new BeanInitializationException(
- "You must explicitly
set a LoggerManager or define a unique one in bean context" );
- }
- }
- }
+ private List instances = new LinkedList();
public void destroy()
throws Exception
@@ -148,6 +131,25 @@
}
dependency = map;
}
+ else if ( Collection.class.isAssignableFrom(
field.getType() ) )
+ {
+ List list = new LinkedList();
+ String mask = beanName + '#';
+ String[] beans =
beanFactory.getBeanDefinitionNames();
+ for ( int i = 0; i < beans.length; i++ )
+ {
+ String name = beans[i];
+ if ( name.startsWith( mask ) )
+ {
+ list.add( beanFactory.getBean( name ) );
+ }
+ }
+ if ( beanFactory.containsBean( beanName ) )
+ {
+ list.add( beanFactory.getBean( beanName ) );
+ }
+ dependency = list;
+ }
else
{
dependency = beanFactory.getBean( beanName );
@@ -155,6 +157,7 @@
}
if ( dependency != null )
{
+ dependency = typeConverter.convertIfNecessary(
dependency, field.getType() );
ReflectionUtils.makeAccessible( field );
ReflectionUtils.setField( field, component, dependency
);
}
@@ -162,18 +165,19 @@
}, ReflectionUtils.COPYABLE_FIELDS );
}
- if ( component instanceof Initializable )
+
+ if ( component instanceof LogEnabled )
{
- ( (Initializable) component ).initialize();
+ ( (LogEnabled) component ).enableLogging(
getLoggerManager().getLoggerForComponent( role.getName() ) );
}
- // TODO handle Initializable, Startable, Stopable, Disposable
-
- if ( component instanceof LogEnabled )
+ if ( component instanceof Initializable )
{
- ( (LogEnabled) component ).enableLogging(
loggerManager.getLoggerForComponent( role.getName() ) );
+ ( (Initializable) component ).initialize();
}
+ // TODO add support for Startable, Stopable -> LifeCycle ?
+
return component;
}
@@ -187,6 +191,28 @@
return "per-lookup".equals( instanciationStrategy );
}
+ private LoggerManager getLoggerManager()
+ {
+ if ( loggerManager == null )
+ {
+ if ( beanFactory.containsBean( "loggerManager" ) )
+ {
+ loggerManager = (LoggerManager) beanFactory.getBean(
"loggerManager" );
+ }
+ Map loggers = beanFactory.getBeansOfType( LoggerManager.class );
+ if ( loggers.size() == 1 )
+ {
+ loggerManager = (LoggerManager)
loggers.values().iterator().next();
+ }
+ else
+ {
+ throw new BeanInitializationException(
+ "You must explicitly
set a LoggerManager or define a unique one in bean context" );
+ }
+ }
+ return loggerManager;
+ }
+
public void setBeanFactory( BeanFactory beanFactory )
throws BeansException
{
@@ -231,6 +257,11 @@
public void setRequirements( Map requirements )
{
this.requirements = requirements;
+ }
+
+ protected void setTypeConverter( TypeConverter typeConverter )
+ {
+ this.typeConverter = typeConverter;
}
}
Added:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java?rev=630773&view=auto
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
(added)
+++
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
Mon Feb 25 01:20:06 2008
@@ -0,0 +1,157 @@
+package org.codehaus.plexus.spring;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.springframework.context.ConfigurableApplicationContext;
+
+;
+
+/**
+ * Mimic org.codehaus.plexus.PlexusTestCase as simple replacement for test
+ * cases.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
+ */
+public class PlexusInSpringTestCase
+ extends TestCase
+{
+ private static String basedir;
+
+ private ConfigurableApplicationContext applicationContext;
+
+ protected void setUp()
+ throws Exception
+ {
+ basedir = getBasedir();
+ applicationContext =
+ new PlexusClassPathXmlApplicationContext( new String[] {
"classpath*:META-INF/plexus/components.xml",
+ "classpath*:META-INF/plexus/components-fragment.xml",
+ "classpath*:" + getPlexusConfigLocation(),
+ "classpath*:" + getSpringConfigLocation()} );
+ }
+
+ protected String getSpringConfigLocation()
+ throws Exception
+ {
+ return getClass().getName().replace( '.', '/' ) + "-context.xml";
+ }
+
+ protected String getPlexusConfigLocation()
+ throws Exception
+ {
+ return getClass().getName().replace( '.', '/' ) + ".xml";
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown()
+ throws Exception
+ {
+ if ( applicationContext != null )
+ {
+ applicationContext.close();
+ }
+ }
+
+ public static String getBasedir()
+ {
+ if ( basedir != null )
+ {
+ return basedir;
+ }
+
+ basedir = System.getProperty( "basedir" );
+ if ( basedir == null )
+ {
+ basedir = new File( "" ).getAbsolutePath();
+ }
+
+ return basedir;
+ }
+
+ public String getTestConfiguration()
+ {
+ return getTestConfiguration( getClass() );
+ }
+
+ public static String getTestConfiguration( Class clazz )
+ {
+ String s = clazz.getName().replace( '.', '/' );
+
+ return s.substring( 0, s.indexOf( "$" ) ) + ".xml";
+ }
+
+ public Object lookup( Class role )
+ {
+ return lookup( role, null );
+ }
+
+ public Object lookup( Class role, String roleHint )
+ {
+ return lookup( role.getName(), roleHint );
+
+ }
+
+ public Object lookup( String role )
+ {
+ return lookup( role, null );
+ }
+
+ public Object lookup( String role, String roleHint )
+ {
+ return applicationContext.getBean( PlexusToSpringUtils.buildSpringId(
role, roleHint ) );
+ }
+
+ public static File getTestFile( String path )
+ {
+ return new File( getBasedir(), path );
+ }
+
+ public static File getTestFile( String basedir,
+ String path )
+ {
+ File basedirFile = new File( basedir );
+
+ if ( !basedirFile.isAbsolute() )
+ {
+ basedirFile = getTestFile( basedir );
+ }
+
+ return new File( basedirFile, path );
+ }
+
+ public static String getTestPath( String path )
+ {
+ return getTestFile( path ).getAbsolutePath();
+ }
+
+ public static String getTestPath( String basedir,
+ String path )
+ {
+ return getTestFile( basedir, path ).getAbsolutePath();
+ }
+}
Propchange:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusToSpringUtils.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusToSpringUtils.java?rev=630773&r1=630772&r2=630773&view=diff
==============================================================================
---
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusToSpringUtils.java
(original)
+++
maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusToSpringUtils.java
Mon Feb 25 01:20:06 2008
@@ -27,7 +27,7 @@
/**
* Utility method to convert plexus descriptors to spring bean context.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
* @since 1.1
*/
@@ -103,6 +103,11 @@
i = 0;
}
String id = Character.toLowerCase( role.charAt( i ) ) +
role.substring( i + 1 );
- return ( roleHint.length() == 0 || "default".equals( roleHint ) ) ? id
: id + '#' + roleHint;
+ return isDefaultHint( roleHint ) ? id : id + '#' + roleHint;
+ }
+
+ private static boolean isDefaultHint( String roleHint )
+ {
+ return roleHint == null || roleHint.length() == 0 || "default".equals(
roleHint );
}
}