Author: nicolas Date: Wed Feb 20 07:53:59 2008 New Revision: 629513 URL: http://svn.apache.org/viewvc?rev=629513&view=rev Log: add support for plexus Initializable / Disposable lifecycle interfaces
Added: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java (with props) Modified: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java maven/archiva/branches/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml Modified: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java?rev=629513&r1=629512&r2=629513&view=diff ============================================================================== --- maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java (original) +++ maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java Wed Feb 20 07:53:59 2008 @@ -27,6 +27,10 @@ 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 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(); - } } Added: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java?rev=629513&view=auto ============================================================================== --- maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java (added) +++ maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java Wed Feb 20 07:53:59 2008 @@ -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:[EMAIL PROTECTED]">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; + }} Propchange: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl?rev=629513&r1=629512&r2=629513&view=diff ============================================================================== --- maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl (original) +++ maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl Wed Feb 20 07:53:59 2008 @@ -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 --> @@ -49,9 +49,15 @@ <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"> Modified: maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java?rev=629513&r1=629512&r2=629513&view=diff ============================================================================== --- maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java (original) +++ maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java Wed Feb 20 07:53:59 2008 @@ -65,9 +65,9 @@ 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() ); } } Modified: maven/archiva/branches/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml URL: http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml?rev=629513&r1=629512&r2=629513&view=diff ============================================================================== --- maven/archiva/branches/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml (original) +++ maven/archiva/branches/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml Wed Feb 20 07:53:59 2008 @@ -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><p> -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>