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.
*
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();
- }
}
--- /dev/null
+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;
+ }}
<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">
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() );
}
}
<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>