From 401c68e0042c87dc6d82a99c75c672611039b2cb Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 20 Feb 2008 15:53:59 +0000 Subject: [PATCH] add support for plexus Initializable / Disposable lifecycle interfaces git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@629513 13f79535-47bb-0310-9956-ffa450edef68 --- .../common/spring/CamelCaseXpathFunction.java | 27 ++---- .../common/spring/PlexusToSpringUtils.java | 86 +++++++++++++++++++ .../archiva/common/spring/plexus2spring.xsl | 16 ++-- ...lexusBeanDefinitionDocumentReaderTest.java | 6 +- .../archiva/common/spring/components.xml | 46 +++++----- 5 files changed, 125 insertions(+), 56 deletions(-) create mode 100644 springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java diff --git a/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java index 858e8736d..faadfd7fa 100644 --- a/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java +++ b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java @@ -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 index 000000000..8f26520b3 --- /dev/null +++ b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusToSpringUtils.java @@ -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 Nicolas De Loof + * @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; + }} diff --git a/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl b/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl index eb22435fb..866c51630 100644 --- a/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl +++ b/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl @@ -20,9 +20,9 @@ + xmlns:plexus="org.apache.maven.archiva.common.spring.PlexusToSpringUtils"> @@ -49,9 +49,15 @@ - - prototype - + + prototype + + + initialize + + + dispose + diff --git a/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java b/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java index cc5612272..470df6c7e 100644 --- a/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java +++ b/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReaderTest.java @@ -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() ); } } diff --git a/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml b/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml index 764e9d8bb..ab6b8172a 100644 --- a/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml +++ b/springy/archiva-base/archiva-common/src/test/resources/org/apache/maven/archiva/common/spring/components.xml @@ -1,39 +1,33 @@ - org.apache.maven.archiva.configuration.ArchivaConfiguration - org.apache.maven.archiva.configuration.DefaultArchivaConfiguration + java.lang.Object + default + java.lang.String per-lookup - <p> -Implementation of configuration holder that retrieves it from the registry. - - - org.codehaus.plexus.registry.Registry - commons-configuration - registry - - - org.apache.maven.archiva.policies.PreDownloadPolicy - prePolicies - - - org.apache.maven.archiva.policies.PostDownloadPolicy - postPolicies - - + - ${user.home}/.m2/archiva.xml - ${appserver.base}/conf/archiva.xml + ${user.home} + ${java.home} - org.apache.maven.archiva.configuration.FileTypes - org.apache.maven.archiva.configuration.FileTypes - FileTypes + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.console.ConsoleLoggerManager - org.apache.maven.archiva.configuration.ArchivaConfiguration - archivaConfiguration + org.codehaus.plexus.digest.Digester + sha1 + digestSha1 + + + org.codehaus.plexus.digest.Digester + md5 + digestMd5 + + + org.codehaus.plexus.digest.ChecksumFile + checksumFile -- 2.39.5