archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r631207 - in /maven/archiva/branches/springy: archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ plexus-spring/ plexus-spring/sr...
Date Tue, 26 Feb 2008 13:04:39 GMT
Author: nicolas
Date: Tue Feb 26 05:04:26 2008
New Revision: 631207

URL: http://svn.apache.org/viewvc?rev=631207&view=rev
Log:
support for plexus requirements without field-name
debug logging
archiva-policies converted to use PlexusInSpringTestCase for tests

Added:
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
  (with props)
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
  (with props)
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
  (with props)
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/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java
    maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml
    maven/archiva/branches/springy/plexus-spring/pom.xml
    maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java
    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
    maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusNamespaceHandler.java
    maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusToSpringUtils.java
    maven/archiva/branches/springy/plexus-spring/src/main/resources/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.xsl
    maven/archiva/branches/springy/plexus-spring/src/main/resources/plexus.xsd
    maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml

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=631207&r1=631206&r2=631207&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
Tue Feb 26 05:04:26 2008
@@ -23,10 +23,7 @@
 import java.util.Properties;
 
 import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-import org.springframework.context.ConfigurableApplicationContext;
 
 /**
  * CachedFailuresPolicyTest

Modified: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ChecksumPolicyTest.java
Tue Feb 26 05:04:26 2008
@@ -19,22 +19,22 @@
  * under the License.
  */
 
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.util.Properties;
 
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
 /**
- * ChecksumPolicyTest 
+ * ChecksumPolicyTest
  *
  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  * @version $Id$
  */
 public class ChecksumPolicyTest
-    extends PlexusTestCase
+    extends PlexusInSpringTestCase
 {
     private static final String GOOD = "good";
 
@@ -166,7 +166,7 @@
         Properties request = createRequest();
 
         boolean actualResult;
-        
+
         try
         {
             policy.applyPolicy( ChecksumPolicy.FAIL, request, localFile );
@@ -195,7 +195,7 @@
         Properties request = createRequest();
 
         boolean actualResult;
-        
+
         try
         {
             policy.applyPolicy( ChecksumPolicy.FIX, request, localFile );
@@ -205,7 +205,7 @@
         {
             actualResult = false;
         }
-        
+
         assertEquals( createMessage( ChecksumPolicy.FIX, md5State, sha1State ), expectedResult,
actualResult );
 
         // End result should be legitimate SHA1 and MD5 files.

Modified: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/ReleasePolicyTest.java
Tue Feb 26 05:04:26 2008
@@ -20,19 +20,20 @@
  */
 
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
 import java.util.Properties;
 
 /**
- * ReleasePolicyTest 
+ * ReleasePolicyTest
  *
  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  * @version $Id$
  */
 public class ReleasePolicyTest
-    extends PlexusTestCase
+    extends PlexusInSpringTestCase
 {
     private static final String PATH_VERSION_METADATA = "org/apache/archiva/archiva-testable/1.0-SNAPSHOT/maven-metadata.xml";
 

Modified: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/SnapshotsPolicyTest.java
Tue Feb 26 05:04:26 2008
@@ -19,12 +19,12 @@
  * under the License.
  */
 
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-
 import java.io.File;
 import java.util.Properties;
 
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
 /**
  * SnapshotsPolicyTest 
  *
@@ -32,7 +32,7 @@
  * @version $Id$
  */
 public class SnapshotsPolicyTest
-    extends PlexusTestCase
+    extends PlexusInSpringTestCase
 {
     private static final String PATH_VERSION_METADATA = "org/apache/archiva/archiva-testable/1.0-SNAPSHOT/maven-metadata.xml";
 

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=631207&r1=631206&r2=631207&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 05:04:26 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="plexusContainer" class="org.codehaus.plexus.spring.PlexusContainerAdapter"/>
+
   <bean id="loggerManager" class="org.codehaus.plexus.logging.console.ConsoleLoggerManager"
      	init-method="initialize"/>
 
@@ -11,4 +13,5 @@
     <!-- collaborators and configuration for this bean go here -->
     <constructor-arg ref="cache#url-failures-cache" type="org.codehaus.plexus.cache.Cache"/>
   </bean>
+
 </beans>

Added: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml?rev=631207&view=auto
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
(added)
+++ maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
Tue Feb 26 05:04:26 2008
@@ -0,0 +1,16 @@
+<?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

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ChecksumPolicyTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml?rev=631207&view=auto
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
(added)
+++ maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
Tue Feb 26 05:04:26 2008
@@ -0,0 +1,16 @@
+<?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

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/ReleasePolicyTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml?rev=631207&view=auto
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
(added)
+++ maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
Tue Feb 26 05:04:26 2008
@@ -0,0 +1,16 @@
+<?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

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: maven/archiva/branches/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/SnapshotsPolicyTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: maven/archiva/branches/springy/plexus-spring/pom.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/pom.xml?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/pom.xml (original)
+++ maven/archiva/branches/springy/plexus-spring/pom.xml Tue Feb 26 05:04:26 2008
@@ -43,11 +43,7 @@
       <version>1.0-alpha-22</version>
     </dependency>
     <dependency>
-      <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>
       <version>1.6.1</version>

Modified: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java
(original)
+++ maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java
Tue Feb 26 05:04:26 2008
@@ -84,6 +84,7 @@
             Transformer t = tf.newTransformer( xsltSource );
             t.transform( xmlSource, transResult );
 
+            logger.debug( doc.getDocumentURI() + " successfully translated to spring");
             return (Document) transResult.getNode();
         }
         catch ( Exception e )

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=631207&r1=631206&r2=631207&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 05:04:26 2008
@@ -30,16 +30,12 @@
  * A custom ClassPathXmlApplicationContext to support plexus
  * <tr>components.xml</tt> descriptors in Spring, with no changes required
  * to neither plexus nor spring beans.
- * 
+ *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public class PlexusClassPathXmlApplicationContext
     extends ClassPathXmlApplicationContext
 {
-
-    // TODO enable Field injection...
-    // @see http://forum.springframework.org/showthread.php?t=50181
-
     public PlexusClassPathXmlApplicationContext( String path, Class clazz )
         throws BeansException
     {
@@ -90,12 +86,13 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
      */
     protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
         throws BeansException, IOException
     {
+        logger.info( "Registering plexus to spring XML translation" );
         reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
         reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );
         super.loadBeanDefinitions( reader );

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=631207&r1=631206&r2=631207&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 05:04:26 2008
@@ -26,13 +26,17 @@
 import java.util.List;
 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.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.SimpleTypeConverter;
 import org.springframework.beans.TypeConverter;
@@ -42,7 +46,10 @@
 import org.springframework.beans.factory.BeanInitializationException;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.ListableBeanFactory;
+import org.springframework.beans.factory.config.AbstractFactoryBean;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 import org.springframework.beans.factory.config.RuntimeBeanReference;
 import org.springframework.util.ReflectionUtils;
 
@@ -56,35 +63,50 @@
  * </ul>
  * If not set, the beanFActory will auto-detect the loggerManager to use by
  * searching for the adequate bean in the spring context.
+ * <p>
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public class PlexusComponentFactoryBean
     implements FactoryBean, BeanFactoryAware, DisposableBean
 {
+    /** Logger available to subclasses */
+    protected final Log logger = LogFactory.getLog( getClass() );
+
+    /** The beanFactory */
+    private BeanFactory beanFactory;
+
     /**
      * @todo isn't there a constant for this in plexus ?
      */
     private static final String SINGLETON = "singleton";
 
+    /** The plexus component role */
     private Class role;
 
+    /** The plexus component implementation class */
     private Class implementation;
 
-    private String instanciationStrategy = SINGLETON;
+    /** The plexus component instantiation strategy */
+    private String instantiationStrategy = SINGLETON;
 
+    /** The plexus component requirements and configurations */
     private Map requirements;
 
-    private ListableBeanFactory beanFactory;
-
-    private LoggerManager loggerManager;
-
-    private TypeConverter typeConverter = new SimpleTypeConverter();
-
+    /** The plexus component created by this FactoryBean */
     private List instances = new LinkedList();
 
-    private Context context;
+    /** Optional plexus loggerManager */
+    private static LoggerManager loggerManager;
+
+    /** Optional plexus context */
+    private static Context context;
 
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.springframework.beans.factory.config.AbstractFactoryBean#destroy()
+     */
     public void destroy()
         throws Exception
     {
@@ -92,26 +114,37 @@
         {
             for ( Iterator iterator = instances.iterator(); iterator.hasNext(); )
             {
-                Object component = (Object) iterator.next();
-                if ( component instanceof Disposable )
+                Object isntance = iterator.next();
+                if ( isntance instanceof Disposable )
                 {
-                    ( (Disposable) component ).dispose();
-
+                    ( (Disposable) isntance ).dispose();
                 }
             }
         }
     }
 
+    /**
+     * {@inheritDoc}
+     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     */
     public Object getObject()
         throws Exception
     {
-        // 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() )
+        if ( isSingleton() && !instances.isEmpty())
         {
             return instances.get( 0 );
         }
+        return createInstance();
+    }
 
+    /**
+     * Create the plexus component instance. Inject dependencies declared as
+     * requirements using direct field injection
+     */
+    public Object createInstance()
+        throws Exception
+    {
+        logger.debug( "Creating plexus component " + implementation );
         final Object component = implementation.newInstance();
         synchronized ( instances )
         {
@@ -119,40 +152,120 @@
         }
         if ( requirements != null )
         {
-            ReflectionUtils.doWithFields( implementation, new ReflectionUtils.FieldCallback()
+            for ( Iterator iterator = requirements.entrySet().iterator(); iterator.hasNext();
)
             {
-                public void doWith( Field field )
-                    throws IllegalArgumentException, IllegalAccessException
+                Map.Entry requirement = (Map.Entry) iterator.next();
+                String fieldName = (String) requirement.getKey();
+
+                if ( fieldName.startsWith( "#" ) )
                 {
-                    Object dependency = resolveRequirement( field );
-                    if ( dependency != null )
+                    // implicit field injection : the field name was no
+                    // specified in the plexus descriptor as only one filed
+                    // matches Dependency type
+
+                    RuntimeBeanReference ref = (RuntimeBeanReference) requirement.getValue();
+                    Object dependency = beanFactory.getBean( ref.getBeanName() );
+
+                    Field[] fields = implementation.getDeclaredFields();
+                    for ( int i = 0; i < fields.length; i++ )
                     {
-                        ReflectionUtils.makeAccessible( field );
-                        ReflectionUtils.setField( field, component, dependency );
+                        Field field = fields[i];
+                        if ( ReflectionUtils.COPYABLE_FIELDS.matches( field )
+                            && field.getType().isAssignableFrom( dependency.getClass()
) )
+                        {
+                            if ( logger.isTraceEnabled() )
+                            {
+                                logger.trace( "Injecting dependency " + dependency + " into
field " + field.getName() );
+                            }
+                            ReflectionUtils.makeAccessible( field );
+                            ReflectionUtils.setField( field, component, dependency );
+                        }
                     }
                 }
-            }, ReflectionUtils.COPYABLE_FIELDS );
+                else
+                {
+                    // explicit field injection
+                    Field field;
+                    try
+                    {
+                        fieldName = PlexusToSpringUtils.toCamelCase( fieldName );
+                        field = implementation.getDeclaredField( fieldName );
+                    }
+                    catch ( NoSuchFieldException e )
+                    {
+                        logger.warn( "No field " + fieldName + " on implementation class
" + implementation );
+                        continue;
+                    }
+                    Object dependency = resolveRequirement( field, requirement.getValue()
);
+                    if ( logger.isTraceEnabled() )
+                    {
+                        logger.trace( "Injecting dependency " + dependency + " into field
" + field.getName() );
+                    }
+                    ReflectionUtils.makeAccessible( field );
+                    ReflectionUtils.setField( field, component, dependency );
+                }
+            }
         }
 
+        handlePlexusLifecycle( component );
+
+        return component;
+    }
+
+    private void handlePlexusLifecycle( final Object component )
+        throws ContextException, InitializationException
+    {
         if ( component instanceof LogEnabled )
         {
             ( (LogEnabled) component ).enableLogging( getLoggerManager().getLoggerForComponent(
role.getName() ) );
         }
 
-        if (component instanceof Contextualizable )
+        if ( component instanceof Contextualizable )
         {
-            // VERRY limiter support for Contextualizable
-            ((Contextualizable) component).contextualize( getContext() );
+            // VERRY limited support for Contextualizable
+            ( (Contextualizable) component ).contextualize( getContext() );
         }
 
+        // TODO add support for Startable, Stopable -> LifeCycle ?
+
         if ( component instanceof Initializable )
         {
             ( (Initializable) component ).initialize();
         }
+    }
 
-        // TODO add support for Startable, Stopable -> LifeCycle ?
+    /**
+     * Resolve the requirement that this field exposes in the component
+     *
+     * @param field
+     * @return
+     */
+    protected Object resolveRequirement( Field field, Object requirement )
+    {
+        if ( requirement instanceof RuntimeBeanReference )
+        {
+            String beanName = ( (RuntimeBeanReference) requirement ).getBeanName();
+            if ( Map.class.isAssignableFrom( field.getType() ) )
+            {
+                // component ask plexus for a Map of all available
+                // components for the role
+                requirement = PlexusToSpringUtils.lookupMap( beanName, getListableBeanFactory()
);
+            }
+            else if ( Collection.class.isAssignableFrom( field.getType() ) )
+            {
+                requirement = PlexusToSpringUtils.LookupList( beanName, getListableBeanFactory()
);
+            }
+            else
+            {
+                requirement = beanFactory.getBean( beanName );
+            }
+        }
+        if ( requirement != null )
+        {
+            requirement = getBeanTypeConverter().convertIfNecessary( requirement, field.getType()
);
+        }
+        return requirement;
 
-        return component;
     }
 
     public Class getObjectType()
@@ -162,7 +275,7 @@
 
     public boolean isSingleton()
     {
-        return SINGLETON.equals( instanciationStrategy );
+        return SINGLETON.equals( instantiationStrategy );
     }
 
     /**
@@ -170,7 +283,7 @@
      */
     protected Context getContext()
     {
-        if (context == null)
+        if ( context == null )
         {
             PlexusContainer container = (PlexusContainer) beanFactory.getBean( "plexusContainer"
);
             context = container.getContext();
@@ -178,8 +291,21 @@
         return context;
     }
 
+    protected TypeConverter getBeanTypeConverter()
+    {
+        if ( beanFactory instanceof ConfigurableBeanFactory )
+        {
+            return ( (ConfigurableBeanFactory) beanFactory ).getTypeConverter();
+        }
+        else
+        {
+            return new SimpleTypeConverter();
+        }
+    }
+
     /**
      * Retrieve the loggerManager instance to be used for LogEnabled components
+     *
      * @return
      */
     protected LoggerManager getLoggerManager()
@@ -190,24 +316,29 @@
             {
                 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" );
+                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;
     }
 
-    public void setBeanFactory( BeanFactory beanFactory )
-        throws BeansException
+    private ListableBeanFactory getListableBeanFactory()
     {
-        this.beanFactory = (ListableBeanFactory) beanFactory;
+        if ( beanFactory instanceof ListableBeanFactory )
+        {
+            return (ListableBeanFactory) beanFactory;
+        }
+        throw new BeanInitializationException( "A ListableBeanFactory is required by the
PlexusComponentFactoryBean" );
     }
 
     /**
@@ -215,7 +346,7 @@
      */
     public void setLoggerManager( LoggerManager loggerManager )
     {
-        this.loggerManager = loggerManager;
+        PlexusComponentFactoryBean.loggerManager = loggerManager;
     }
 
     /**
@@ -247,7 +378,7 @@
         {
             throw new BeanCreationException( "Plexus poolable instanciation-strategy is not
supported" );
         }
-        this.instanciationStrategy = instanciationStrategy;
+        this.instantiationStrategy = instanciationStrategy;
     }
 
     /**
@@ -258,49 +389,14 @@
         this.requirements = requirements;
     }
 
-    protected void setTypeConverter( TypeConverter typeConverter )
+    public void setContext( Context context )
     {
-        this.typeConverter = typeConverter;
+        PlexusComponentFactoryBean.context = context;
     }
 
-
-    /**
-     * Resolve the requirement that this field exposes in the component
-     * @param field
-     * @return
-     */
-    protected Object resolveRequirement( Field field )
-    {
-        Object dependency =  requirements.get( field.getName() );
-        if ( dependency instanceof RuntimeBeanReference )
-        {
-            String beanName = ( (RuntimeBeanReference) dependency ).getBeanName();
-            if ( Map.class.isAssignableFrom( field.getType() ) )
-            {
-                // component ask plexus for a Map of all available
-                // components for the role
-                dependency = PlexusToSpringUtils.lookupMap( beanName, beanFactory );
-            }
-            else if ( Collection.class.isAssignableFrom( field.getType() ) )
-            {
-                dependency = PlexusToSpringUtils.LookupList( beanName, beanFactory );
-            }
-            else
-            {
-                dependency = beanFactory.getBean( beanName );
-            }
-        }
-        if (dependency != null)
-        {
-            dependency = typeConverter.convertIfNecessary( dependency, field.getType() );
-        }
-        return dependency;
-
-    }
-
-    protected void setContext( Context context )
+    public void setBeanFactory( BeanFactory beanFactory )
     {
-        this.context = context;
+        this.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=631207&r1=631206&r2=631207&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 05:04:26 2008
@@ -34,7 +34,7 @@
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
 import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.DefaultContext;
+import org.codehaus.plexus.context.ContextException;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.logging.LoggerManager;
 import org.springframework.beans.BeansException;
@@ -50,7 +50,7 @@
 public class PlexusContainerAdapter
     implements PlexusContainer, ApplicationContextAware, InitializingBean
 {
-    private Context context = new DefaultContext();
+    private Context context = new SimpleContext();
 
     private ApplicationContext applicationContext;
 
@@ -62,7 +62,7 @@
     public void afterPropertiesSet()
         throws Exception
     {
-        context.put( "plexus", this );
+        context = new SimpleContext();
     }
 
     /**
@@ -653,5 +653,67 @@
         this.applicationContext = applicationContext;
     }
 
+    private class SimpleContext implements Context
+    {
+        /** the plexus container key in the context */
+        private static final String PLEXUS = "plexus";
+
+        /**
+         * {@inheritDoc}
+         * @see org.codehaus.plexus.context.Context#contains(java.lang.Object)
+         */
+        public boolean contains( Object key )
+        {
+            return PLEXUS.equals( key );
+        }
+
+        /**
+         * {@inheritDoc}
+         * @see org.codehaus.plexus.context.Context#get(java.lang.Object)
+         */
+        public Object get( Object key )
+            throws ContextException
+        {
+            return PLEXUS.equals( key ) ? PlexusContainerAdapter.this : null;
+        }
+
+        /**
+         * {@inheritDoc}
+         * @see org.codehaus.plexus.context.Context#getContextData()
+         */
+        public Map getContextData()
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * {@inheritDoc}
+         * @see org.codehaus.plexus.context.Context#hide(java.lang.Object)
+         */
+        public void hide( Object key )
+            throws IllegalStateException
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * {@inheritDoc}
+         * @see org.codehaus.plexus.context.Context#makeReadOnly()
+         */
+        public void makeReadOnly()
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * {@inheritDoc}
+         * @see org.codehaus.plexus.context.Context#put(java.lang.Object, java.lang.Object)
+         */
+        public void put( Object key, Object value )
+            throws IllegalStateException
+        {
+            throw new UnsupportedOperationException();
+        }
 
+    }
 }

Modified: maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusNamespaceHandler.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusNamespaceHandler.java?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusNamespaceHandler.java
(original)
+++ maven/archiva/branches/springy/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusNamespaceHandler.java
Tue Feb 26 05:04:26 2008
@@ -37,8 +37,8 @@
 import org.w3c.dom.Element;
 
 /**
- * A spring namespace handler to support plexus components creation and direct field-injection
in a spring
- * XmlApplicationContext.
+ * A spring namespace handler to support plexus components creation and direct
+ * field-injection in a spring XmlApplicationContext.
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  * @since 1.1
@@ -64,15 +64,17 @@
     }
 
     /**
-     * BeanDefinitionParser for &lt;plexus:component&gt;. Register a bean definition
for a PlexusComponentFactoryBean
-     * with all nested requirement / configuration injected using direct field injection.
+     * BeanDefinitionParser for &lt;plexus:component&gt;. Register a bean
+     * definition for a PlexusComponentFactoryBean with all nested requirement /
+     * configuration injected using direct field injection.
      * <p>
-     * Also register an alias for the Plexus component using spring conventions (interface
class simple name + "#"
-     * role-hint)
+     * Also register an alias for the Plexus component using spring conventions
+     * (interface class simple name + "#" role-hint)
      */
     private class PlexusComponentBeanDefinitionParser
         extends AbstractSingleBeanDefinitionParser
     {
+        private int count;
 
         protected void doParse( Element element, BeanDefinitionBuilder builder )
         {
@@ -87,10 +89,12 @@
             for ( Iterator iterator = requirements.iterator(); iterator.hasNext(); )
             {
                 Element child = (Element) iterator.next();
-                String name = child.getAttribute( "name" );
-                if (name.length() == 0)
+                String name = child.getAttribute( "field-name" );
+                if ( name.length() == 0 )
                 {
-                    throw new ApplicationContextException( "No field name for plexus requirement
on " + implementation );
+                    // Plexus doesn't require to specify the field-name if only
+                    // one field matches the injected type
+                    name = "#" + count++;
                 }
                 String role = child.getAttribute( "role" );
                 String roleHint = child.getAttribute( "role-hint" );

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=631207&r1=631206&r2=631207&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
Tue Feb 26 05:04:26 2008
@@ -55,7 +55,7 @@
         StringBuilder camelCase = new StringBuilder();
         boolean first = true;
 
-        StringTokenizer tokenizer = new StringTokenizer( string.toLowerCase(), "-" );
+        StringTokenizer tokenizer = new StringTokenizer( string, "-" );
         while ( tokenizer.hasMoreTokens() )
         {
             String token = tokenizer.nextToken();

Modified: maven/archiva/branches/springy/plexus-spring/src/main/resources/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.xsl
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/resources/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.xsl?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/resources/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.xsl
(original)
+++ maven/archiva/branches/springy/plexus-spring/src/main/resources/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.xsl
Tue Feb 26 05:04:26 2008
@@ -34,7 +34,8 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:plexus="http://plexus.codehaus.org/spring"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
-                           http://plexus.codehaus.org/spring http://plexus.codehaus.org/schemas/spring-1.0.xsd">
+                           http://plexus.codehaus.org/spring http://plexus.codehaus.org/schemas/spring-1.0.xsd"
+       default-lazy-init="true">
   <xsl:for-each select="components/component">
 
     <plexus:component>
@@ -56,7 +57,7 @@
       </xsl:if>
       <xsl:for-each select="requirements/requirement">
         <plexus:requirement>
-          <xsl:attribute name="name">
+          <xsl:attribute name="field-name">
             <xsl:value-of select="field-name" />
           </xsl:attribute>
           <xsl:attribute name="role">

Modified: maven/archiva/branches/springy/plexus-spring/src/main/resources/plexus.xsd
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/main/resources/plexus.xsd?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/main/resources/plexus.xsd (original)
+++ maven/archiva/branches/springy/plexus-spring/src/main/resources/plexus.xsd Tue Feb 26
05:04:26 2008
@@ -8,7 +8,7 @@
 	   <xsd:sequence>
 	     <xsd:element name="requirement" minOccurs="0">
 	       <xsd:complexType>
-			   <xsd:attribute name="name" type="xsd:string" use="required"/>
+			   <xsd:attribute name="field-name" type="xsd:string" use="optional"/>
 	   	   	   <xsd:attribute name="role" type="xsd:string" use="required"/>
 	   	   	   <xsd:attribute name="role-hint" type="xsd:string" use="optional"/>
 	       </xsd:complexType>

Modified: maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml?rev=631207&r1=631206&r2=631207&view=diff
==============================================================================
--- maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml (original)
+++ maven/archiva/branches/springy/plexus-spring/src/test/resources/components.xml Tue Feb
26 05:04:26 2008
@@ -6,7 +6,6 @@
       <implementation>org.codehaus.plexus.spring.PlexusBeanImpl</implementation>
       <requirements>
       	<requirement>
-      		<field-name>bean</field-name>
       		<role>springBean</role>
       	</requirement>
       </requirements>
@@ -37,6 +36,6 @@
       		<role>org.codehaus.plexus.spring.PlexusBean</role>
       	</requirement>
       </requirements>
-    </component>    
+    </component>
   </components>
 </component-set>



Mime
View raw message