<dependencies>
<!-- TO OTHER DEVELOPERS:
This module should depend on NO OTHER ARCHIVA MODULES.
- If you feel tempted to add one, discuss it first in the
+ If you feel tempted to add one, discuss it first in the
archiva-dev@maven.apache.org mailing-list.
joakime@apache.org
-->
<artifactId>spring-beans</artifactId>
<version>2.5.1</version>
</dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
</dependencies>
<build>
<plugins>
--- /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.InputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+
+import org.springframework.beans.factory.xml.BeanDefinitionDocumentReader;
+import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;
+import org.springframework.beans.factory.xml.XmlReaderContext;
+import org.w3c.dom.Document;
+
+/**
+ * A Spring {@link BeanDefinitionDocumentReader} that converts on the fly the
+ * Plexus components descriptor to a spring XML context.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @since 1.1
+ */
+public class PlexusBeanDefinitionDocumentReader
+ extends DefaultBeanDefinitionDocumentReader
+{
+
+ public void registerBeanDefinitions( Document doc, XmlReaderContext readerContext )
+ {
+ convertPlexusDescriptorToSpringBeans( doc );
+ super.registerBeanDefinitions( doc, readerContext );
+ }
+
+ protected Document convertPlexusDescriptorToSpringBeans( Document doc )
+ {
+ try
+ {
+ Source xmlSource = new DOMSource( doc );
+ InputStream is = getClass().getResourceAsStream( "plexus2spring.xsl" );
+ Source xsltSource = new StreamSource( is );
+
+ DOMResult transResult = new DOMResult();
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer( xsltSource );
+ t.transform( xmlSource, transResult );
+
+ return (Document) transResult.getNode();
+ }
+ catch ( Exception e )
+ {
+ // FIXME log the error;
+ return doc;
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+ version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:output method="xml" indent="yes" />
+
+<xsl:template match="/component-set">
+<beans>
+ <xsl:for-each select="components/component">
+ <bean>
+ <xsl:choose>
+ <xsl:when test="role-hint">
+ <xsl:attribute name="id">
+ <xsl:value-of select="role" />
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name="id">
+ <xsl:value-of select="concat( role, '#', role-hint )" />
+ </xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:attribute name="class">
+ <xsl:value-of select="implementation" />
+ </xsl:attribute>
+ <xsl:for-each select="requirements/requirement">
+ <property>
+ <xsl:attribute name="name">
+ <xsl:value-of select="field-name" />
+ </xsl:attribute>
+ <xsl:choose>
+ <xsl:when test="role-hint">
+ <xsl:attribute name="ref">
+ <xsl:value-of select="concat( role, '#', role-hint )" />
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name="ref">
+ <xsl:value-of select="role" />
+ </xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </property>
+ </xsl:for-each>
+ <xsl:for-each select="configuration/*">
+ <property>
+ <xsl:attribute name="name">
+ <xsl:value-of select="name(.)" />
+ </xsl:attribute>
+ <xsl:attribute name="value">
+ <xsl:value-of select="." />
+ </xsl:attribute>
+ </property>
+ </xsl:for-each>
+ </bean>
+ </xsl:for-each>
+</beans>
+</xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /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.InputStream;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.dom4j.io.DOMReader;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
+import org.w3c.dom.Document;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class PlexusBeanDefinitionDocumentReaderTest
+ extends TestCase
+{
+ PlexusBeanDefinitionDocumentReader reader = new PlexusBeanDefinitionDocumentReader();
+
+ public void testConvertPlexusToSpring()
+ throws Exception
+ {
+ URL plexus = getClass().getResource( "components.xml" );
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse( plexus.openStream() );
+
+ doc = reader.convertPlexusDescriptorToSpringBeans( doc );
+
+ new XMLWriter( System.out, OutputFormat.createPrettyPrint() ).write( new DOMReader().read( doc ) );
+ }
+}
--- /dev/null
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
+ <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>
+ <configuration>
+ <user-config-filename>${user.home}/.m2/archiva.xml</user-config-filename>
+ <alt-config-filename>${appserver.base}/conf/archiva.xml</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>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <field-name>archivaConfiguration</field-name>
+ </requirement>
+ </requirements>
+ </component>
+ </components>
+</component-set>