]> source.dussan.org Git - archiva.git/commitdiff
add support for plexus Initializable / Disposable lifecycle interfaces
authorNicolas De Loof <nicolas@apache.org>
Wed, 20 Feb 2008 15:53:59 +0000 (15:53 +0000)
committerNicolas De Loof <nicolas@apache.org>
Wed, 20 Feb 2008 15:53:59 +0000 (15:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@629513 13f79535-47bb-0310-9956-ffa450edef68

springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java [new file with mode: 0644]
springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl
springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java
springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml

index 858e8736d934dfd2fcfc5f263edf97af7176a1df..faadfd7fad2bc54c96ea3d00750ec9932afa4619 100644 (file)
@@ -27,6 +27,10 @@ import javax.xml.xpath.XPathFunction;
 import javax.xml.xpath.XPathFunctionException;
 import javax.xml.xpath.XPathFunctionResolver;
 
+import org.apache.commons.lang.ClassUtils;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+
 /**
  * XPathFunction to convert plexus property-name to Spring propertyName.
  *
@@ -62,29 +66,8 @@ public class CamelCaseXpathFunction
     public Object evaluate( List args )
         throws XPathFunctionException
     {
-        return toCamelCase( (String) args.get( 0 ) );
+        return PlexusToSpringUtils.toCamelCase( (String) args.get( 0 ) );
     }
 
-    public static String toCamelCase( String string )
-    {
-        StringBuilder camelCase = new StringBuilder();
-        boolean first = true;
 
-        StringTokenizer tokenizer = new StringTokenizer( string.toLowerCase(), "-" );
-        while ( tokenizer.hasMoreTokens() )
-        {
-            String token = tokenizer.nextToken();
-            if ( first )
-            {
-                camelCase.append( token.charAt( 0 ) );
-                first = false;
-            }
-            else
-            {
-                camelCase.append( Character.toUpperCase( token.charAt( 0 ) ) );
-            }
-            camelCase.append( token.substring( 1, token.length() ) );
-        }
-        return camelCase.toString();
-    }
 }
diff --git a/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java
new file mode 100644 (file)
index 0000000..8f26520
--- /dev/null
@@ -0,0 +1,86 @@
+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.util.StringTokenizer;
+
+import org.apache.commons.lang.ClassUtils;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+
+/**
+ * Utility method to convert plexus descriptors to spring bean context.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @since 1.1
+ */
+public class PlexusToSpringUtils
+{
+
+    public static String toCamelCase( String string )
+    {
+        StringBuilder camelCase = new StringBuilder();
+        boolean first = true;
+
+        StringTokenizer tokenizer = new StringTokenizer( string.toLowerCase(), "-" );
+        while ( tokenizer.hasMoreTokens() )
+        {
+            String token = tokenizer.nextToken();
+            if ( first )
+            {
+                camelCase.append( token.charAt( 0 ) );
+                first = false;
+            }
+            else
+            {
+                camelCase.append( Character.toUpperCase( token.charAt( 0 ) ) );
+            }
+            camelCase.append( token.substring( 1, token.length() ) );
+        }
+        return camelCase.toString();
+    }
+
+    public static boolean isInitializable( String className )
+    {
+        boolean initializable = false;
+        try
+        {
+            initializable = Initializable.class.isAssignableFrom( ClassUtils.getClass( className ) );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            // ignored
+        }
+        return initializable;
+    }
+
+    public static boolean isDisposable( String className )
+    {
+        boolean disposable = false;
+        try
+        {
+            disposable = Disposable.class.isAssignableFrom( ClassUtils.getClass( className ) );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            // ignored
+        }
+        return disposable;
+    }}
index eb22435fb31104226652fe69f2d068694265d3c3..866c516304868ed59b1d28468e2a4537c644dd0a 100644 (file)
@@ -20,9 +20,9 @@
 
 <xsl:stylesheet
     version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    xmlns:plexus="org.apache.maven.archiva.common.spring.CamelCaseXpathFunction">
+    xmlns:plexus="org.apache.maven.archiva.common.spring.PlexusToSpringUtils">
 <!--
-    use xalan extension mecanism to call static methods
+    FIXME replace xalan extension mecanism to call static methods with XPathFunctions
     @see http://www.ibm.com/developerworks/library/x-xalanextensions.html
  -->
 
       <xsl:attribute name="class">
         <xsl:value-of select="implementation" />
       </xsl:attribute>
-        <xsl:if test="instanciation-strategy/text() = 'per-lookup'">
-          <xsl:attribute name="scope">prototype</xsl:attribute>
-        </xsl:if>
+      <xsl:if test="instanciation-strategy/text() = 'per-lookup'">
+        <xsl:attribute name="scope">prototype</xsl:attribute>
+      </xsl:if>
+      <xsl:if test="plexus:isInitializable( implementation/text() )">
+        <xsl:attribute name="init-method">initialize</xsl:attribute>
+      </xsl:if>
+      <xsl:if test="plexus:isDisposable( implementation/text() )">
+        <xsl:attribute name="init-method">dispose</xsl:attribute>
+      </xsl:if>
       <xsl:for-each select="requirements/requirement">
         <property>
           <xsl:attribute name="name">
index cc561227224c2e2765c15686a24ce135d769114e..470df6c7eec3b2c0d8e8dfa56267d9f06afafa27 100644 (file)
@@ -65,9 +65,9 @@ public class PlexusBeanDefinitionDocumentReaderTest
         PlexusBeanFactory factory = new PlexusBeanFactory( new UrlResource( plexus ) );
         assertEquals( 2, factory.getBeanDefinitionCount() );
 
-        BeanDefinition bd = factory.getBeanDefinition( "org.apache.maven.archiva.configuration.ArchivaConfiguration" );
-        assertEquals( "org.apache.maven.archiva.configuration.DefaultArchivaConfiguration", bd.getBeanClassName() );
+        BeanDefinition bd = factory.getBeanDefinition( "java.lang.Object#default" );
+        assertEquals( "java.lang.String", bd.getBeanClassName() );
         assertEquals( "prototype", bd.getScope() );
-        assertEquals( 5, bd.getPropertyValues().size() );
+        assertEquals( 2, bd.getPropertyValues().size() );
     }
 }
index 764e9d8bb55ca27783756c18475a69d960374c7d..ab6b8172a51774dc136c819aecfe46569b98a22e 100644 (file)
@@ -1,39 +1,33 @@
 <component-set>
   <components>
     <component>
-      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
-      <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
+      <role>java.lang.Object</role>
+      <role-hint>default</role-hint>
+      <implementation>java.lang.String</implementation>
       <instanciation-strategy>per-lookup</instanciation-strategy>
-      <description>&lt;p&gt;
-Implementation of configuration holder that retrieves it from the registry.</description>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.registry.Registry</role>
-          <role-hint>commons-configuration</role-hint>
-          <field-name>registry</field-name>
-        </requirement>
-        <requirement>
-          <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role>
-          <field-name>prePolicies</field-name>
-        </requirement>
-        <requirement>
-          <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
-          <field-name>postPolicies</field-name>
-        </requirement>
-      </requirements>
+      <description></description>
       <configuration>
-        <user-config-filename>${user.home}/.m2/archiva.xml</user-config-filename>
-        <alt-config-filename>${appserver.base}/conf/archiva.xml</alt-config-filename>
+        <user-config-filename>${user.home}</user-config-filename>
+        <alt-config-filename>${java.home}</alt-config-filename>
       </configuration>
     </component>
     <component>
-      <role>org.apache.maven.archiva.configuration.FileTypes</role>
-      <implementation>org.apache.maven.archiva.configuration.FileTypes</implementation>
-      <description>FileTypes</description>
+      <role>org.codehaus.plexus.logging.LoggerManager</role>
+      <implementation>org.codehaus.plexus.logging.console.ConsoleLoggerManager</implementation>
       <requirements>
         <requirement>
-          <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
-          <field-name>archivaConfiguration</field-name>
+          <role>org.codehaus.plexus.digest.Digester</role>
+          <role-hint>sha1</role-hint>
+          <field-name>digestSha1</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.digest.Digester</role>
+          <role-hint>md5</role-hint>
+          <field-name>digestMd5</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.digest.ChecksumFile</role>
+          <field-name>checksumFile</field-name>
         </requirement>
       </requirements>
     </component>