<!-- 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>
protected Document convertPlexusDescriptorToSpringBeans( Document doc )
{
+ if ( ! "component-set".equals( doc.getDocumentElement().getNodeName() ) )
+ {
+ return doc;
+ }
+
try
{
Source xmlSource = new DOMSource( doc );
--- /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.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 );
+ }
+
+}
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();
+++ /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 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;
- }
- }
-}
<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>