]> source.dussan.org Git - archiva.git/commitdiff
- plexus compilant ClassPathXmlApplicationContext
authorNicolas De Loof <nicolas@apache.org>
Thu, 21 Feb 2008 16:33:22 +0000 (16:33 +0000)
committerNicolas De Loof <nicolas@apache.org>
Thu, 21 Feb 2008 16:33:22 +0000 (16:33 +0000)
- plexus-2-spring xslt now creates simple class name aliases for plexus FQCN roles
- attempt to use plexus to spring bridge in CachedFailuresPolicyTest

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@629854 13f79535-47bb-0310-9956-ffa450edef68

springy/archiva-base/archiva-common/pom.xml
springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReader.java
springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusClassPathXmlApplicationContext.java [new file with mode: 0644]
springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java
springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/SpringFactory.java [deleted file]
springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl

index 1be3c960fd215004412bf45612f916e623533b7f..d7d0d1eaf49e515af682eedf1d375b410af98e30 100644 (file)
@@ -53,7 +53,7 @@
     <!-- TODO: temporary spring dependencies for migration -->
     <dependency>
       <groupId>org.springframework</groupId>
-      <artifactId>spring-beans</artifactId>
+      <artifactId>spring-context</artifactId>
       <version>2.5.1</version>
     </dependency>
     <dependency>
index 6290af08d77954afe2132d7ef90ce6b1a2cdf5d7..fec1170779367022b400a52e81632c075680555c 100644 (file)
@@ -52,6 +52,11 @@ public class PlexusBeanDefinitionDocumentReader
 
     protected Document convertPlexusDescriptorToSpringBeans( Document doc )
     {
+        if ( ! "component-set".equals( doc.getDocumentElement().getNodeName() ) )
+        {
+            return doc;
+        }
+
         try
         {
             Source xmlSource = new DOMSource( doc );
diff --git a/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusClassPathXmlApplicationContext.java b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusClassPathXmlApplicationContext.java
new file mode 100644 (file)
index 0000000..2346253
--- /dev/null
@@ -0,0 +1,102 @@
+package org.apache.maven.archiva.common.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.IOException;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @since 1.1
+ */
+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
+    {
+        super( path, clazz );
+    }
+
+    public PlexusClassPathXmlApplicationContext( String configLocation )
+        throws BeansException
+    {
+        super( configLocation );
+    }
+
+    public PlexusClassPathXmlApplicationContext( String[] configLocations, ApplicationContext parent )
+        throws BeansException
+    {
+        super( configLocations, parent );
+    }
+
+    public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh, ApplicationContext parent )
+        throws BeansException
+    {
+        super( configLocations, refresh, parent );
+    }
+
+    public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh )
+        throws BeansException
+    {
+        super( configLocations, refresh );
+    }
+
+    public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz, ApplicationContext parent )
+        throws BeansException
+    {
+        super( paths, clazz, parent );
+    }
+
+    public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz )
+        throws BeansException
+    {
+        super( paths, clazz );
+    }
+
+    public PlexusClassPathXmlApplicationContext( String[] configLocations )
+        throws BeansException
+    {
+        super( configLocations );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
+     */
+    @Override
+    protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
+        throws BeansException, IOException
+    {
+        reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
+        reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );
+        super.loadBeanDefinitions( reader );
+    }
+
+}
index 8f26520b3234d40e8b4e9a5d07e374b1eb18b763..c0b3a42a56416f8ca3c6bffd6d1803c85e9d9a9f 100644 (file)
@@ -34,6 +34,16 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 public class PlexusToSpringUtils
 {
 
+    public static String toSpringId( String string )
+    {
+        int i = string.lastIndexOf( '.' );
+        if (i >= 0 )
+        {
+            return Character.toLowerCase( string.charAt( i + 1 ) ) + string.substring( i + 2 );
+        }
+        return string;
+    }
+
     public static String toCamelCase( String string )
     {
         StringBuilder camelCase = new StringBuilder();
diff --git a/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/SpringFactory.java b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/SpringFactory.java
deleted file mode 100644 (file)
index 0136a68..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.maven.archiva.common.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 org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
-import org.springframework.beans.factory.BeanFactory;
-
-/**
- * @plexus.component role="org.apache.maven.archiva.common.spring.SpringFactory" role-hint="default"
- */
-public class SpringFactory
-    implements Contextualizable
-{
-    private BeanFactory factory;
-
-    public void contextualize( Context context )
-        throws ContextException
-    {
-        // Grab a Spring component - TODO: should be injected!
-        if ( context.contains( BeanFactory.class ) )
-        {
-            factory = (BeanFactory) context.get( BeanFactory.class );
-        }
-    }
-
-    public Object lookup( String id )
-    {
-        if ( factory != null )
-        {
-            return factory.getBean( id );
-        }
-        else
-        {
-            return null;
-        }
-    }
-}
index 866c516304868ed59b1d28468e2a4537c644dd0a..df472ab4d60b5cf4e6e43b8a9fdd1ae8fe4e477d 100644 (file)
@@ -33,6 +33,7 @@
 <xsl:template match="/component-set">
 <beans>
   <xsl:for-each select="components/component">
+
     <bean>
       <xsl:choose>
         <xsl:when test="role-hint">
           <xsl:choose>
             <xsl:when test="role-hint">
               <xsl:attribute name="ref">
-                <xsl:value-of select="concat( role, '#', role-hint )" />
+                <xsl:value-of select="concat( plexus:toSpringId( role ), '#', role-hint )" />
               </xsl:attribute>
             </xsl:when>
             <xsl:otherwise>
               <xsl:attribute name="ref">
-                <xsl:value-of select="role" />
+                <xsl:value-of select="plexus:toSpringId( role )" />
               </xsl:attribute>
             </xsl:otherwise>
           </xsl:choose>
         </property>
       </xsl:for-each>
     </bean>
+
+    <!--
+      Plexus convention is to use interface FQN as bean ID
+      Spring convention is to use interface simpleName as bean ID
+      To allow smooth migration, we define same bean with both IDs using an alias
+    -->
+
+    <alias>
+      <xsl:attribute name="alias">
+        <xsl:choose>
+          <xsl:when test="role-hint">
+            <xsl:value-of select="concat( plexus:toSpringId( role ), '#', role-hint )" />
+          </xsl:when>
+          <xsl:otherwise>
+              <xsl:value-of select="plexus:toSpringId( role )" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:attribute>
+      <xsl:attribute name="name">
+        <xsl:choose>
+          <xsl:when test="role-hint">
+            <xsl:value-of select="concat( role, '#', role-hint )" />
+          </xsl:when>
+          <xsl:otherwise>
+              <xsl:value-of select="role" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:attribute>
+    </alias>
   </xsl:for-each>
 </beans>
 </xsl:template>