From 773b4eb7dace4e6fb3e402eb0db111d165593c9f Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 25 Feb 2008 16:36:58 +0000 Subject: [PATCH] fix instantiation-strategy git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@630922 13f79535-47bb-0310-9956-ffa450edef68 --- springy/plexus-spring/pom.xml | 7 ++++- .../PlexusBeanDefinitionDocumentReader.java | 2 +- .../spring/PlexusComponentFactoryBean.java | 29 +++++++++---------- .../plexus/spring/FieldInjectionTest.java | 10 +++++++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/springy/plexus-spring/pom.xml b/springy/plexus-spring/pom.xml index a5983c141..0a26b3492 100644 --- a/springy/plexus-spring/pom.xml +++ b/springy/plexus-spring/pom.xml @@ -40,7 +40,12 @@ org.codehaus.plexus plexus-component-api - 1.0-alpha-33 + 1.0-alpha-22 + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-22 dom4j diff --git a/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java b/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java index 3866db78d..086538516 100644 --- a/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java +++ b/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java @@ -49,7 +49,7 @@ public class PlexusBeanDefinitionDocumentReader public void registerBeanDefinitions( Document doc, XmlReaderContext readerContext ) { doc = convertPlexusDescriptorToSpringBeans( doc ); - if ( Boolean.getBoolean( "spring-plexus.debug" ) ) + if ( Boolean.getBoolean( "plexus-spring.debug" ) ) { try { diff --git a/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java b/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java index a9a5cb409..6e6494fc0 100644 --- a/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java +++ b/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java @@ -20,15 +20,12 @@ package org.codehaus.plexus.spring; */ import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.logging.LogEnabled; @@ -65,13 +62,16 @@ import org.springframework.util.ReflectionUtils; public class PlexusComponentFactoryBean implements FactoryBean, BeanFactoryAware, DisposableBean { - private static final char HINT = '#'; + /** + * @todo isn't there a constant for this in plexus ? + */ + private static final String SINGLETON = "singleton"; private Class role; private Class implementation; - private String instanciationStrategy; + private String instanciationStrategy = SINGLETON; private Map requirements; @@ -105,15 +105,9 @@ public class PlexusComponentFactoryBean public Object getObject() throws Exception { - if ( "poolable".equals( instanciationStrategy ) ) - { - throw new BeanCreationException( "Plexus poolable instanciation-strategy is not supported" ); - } - // Spring MAY cache the object built by this factory if getSingleton() - // returns true, - // but can also requires us to ensure unicity. - if ( "singleton".equals( instanciationStrategy ) && !instances.isEmpty() ) + // returns true, but can also requires us to ensure unicity. + if ( SINGLETON.equals( instanciationStrategy ) && !instances.isEmpty() ) { return instances.get( 0 ); } @@ -147,6 +141,7 @@ public class PlexusComponentFactoryBean if (component instanceof Contextualizable ) { + // VERRY limiter support for Contextualizable ((Contextualizable) component).contextualize( getContext() ); } @@ -167,7 +162,7 @@ public class PlexusComponentFactoryBean public boolean isSingleton() { - return "per-lookup".equals( instanciationStrategy ); + return SINGLETON.equals( instanciationStrategy ); } /** @@ -246,7 +241,11 @@ public class PlexusComponentFactoryBean { if ( instanciationStrategy.length() == 0 ) { - instanciationStrategy = "singleton"; + instanciationStrategy = SINGLETON; + } + if ( "poolable".equals( instanciationStrategy ) ) + { + throw new BeanCreationException( "Plexus poolable instanciation-strategy is not supported" ); } this.instanciationStrategy = instanciationStrategy; } 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 index 1f288bd43..57980cb05 100644 --- 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 @@ -26,6 +26,16 @@ import org.springframework.context.ConfigurableApplicationContext; public class FieldInjectionTest extends TestCase { + /** + * {@inheritDoc} + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() + throws Exception + { + System.setProperty( "plexus-spring.debug", "true" ); + } + public void testFieldInjectionInSpringContext() throws Exception { -- 2.39.5