You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:33:56 UTC
svn commit: r1310262 [3/14] - in /archiva/redback/redback-components/trunk:
./ plexus-command-line/ plexus-command-line/src/
plexus-command-line/src/main/ plexus-command-line/src/main/java/
plexus-command-line/src/main/java/org/ plexus-command-line/src...
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,253 @@
+package org.codehaus.plexus.logging.console;
+
+/*
+ * Copyright 2001-2006 Codehaus Foundation.
+ *
+ * Licensed 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.logging.AbstractLoggerManager;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.LoggerManager;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * This is a simple logger manager that will only write the logging statements to the console.
+ *
+ * Sample configuration:
+ * <pre>
+ * <logging>
+ * <implementation>org.codehaus.plexus.logging.ConsoleLoggerManager</implementation>
+ * <logger>
+ * <threshold>DEBUG</threshold>
+ * </logger>
+ * </logging>
+ * </pre>
+ *
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
+ * @version $Id$
+ */
+public class ConsoleLoggerManager
+ extends AbstractLoggerManager
+ implements LoggerManager, Initializable
+{
+ /**
+ * Message of this level or higher will be logged.
+ *
+ * This field is set by the plexus container thus the name is 'threshold'. The field
+ * currentThreshold contains the current setting of the threshold.
+ */
+ private String threshold = "info";
+
+ private int currentThreshold;
+
+ private Map loggers;
+
+ /** The number of active loggers in use. */
+ private int loggerCount;
+
+ private boolean bootTimeLogger = false;
+
+ /**
+ */
+ public ConsoleLoggerManager()
+ {
+ }
+
+ /**
+ * This special constructor is called directly when the container is bootstrapping itself.
+ */
+ public ConsoleLoggerManager( String threshold )
+ {
+ this.threshold = threshold;
+
+ bootTimeLogger = true;
+
+ initialize();
+ }
+
+ public void initialize()
+ {
+ debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." );
+// if ( !bootTimeLogger )
+// new Throwable().printStackTrace(System.err);
+ currentThreshold = parseThreshold( threshold );
+
+ if ( currentThreshold == -1 )
+ {
+ debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." );
+ currentThreshold = Logger.LEVEL_DEBUG;
+ }
+
+ loggers = new HashMap();
+ }
+
+ public void setThreshold( int currentThreshold )
+ {
+ this.currentThreshold = currentThreshold;
+ }
+
+ public void setThresholds( int currentThreshold )
+ {
+ this.currentThreshold = currentThreshold;
+
+ for ( Iterator logs = loggers.values().iterator(); logs.hasNext(); )
+ {
+ Logger logger = (Logger) logs.next();
+ logger.setThreshold( currentThreshold );
+ }
+ }
+
+ /**
+ * @return Returns the threshold.
+ */
+ public int getThreshold()
+ {
+ return currentThreshold;
+ }
+
+ // new stuff
+
+ public void setThreshold( String role, String roleHint, int threshold ) {
+ ConsoleLogger logger;
+ String name;
+
+ name = toMapKey( role, roleHint );
+ logger = (ConsoleLogger)loggers.get( name );
+
+ if(logger == null) {
+ debug( "Trying to set the threshold of a unknown logger '" + name + "'." );
+ return; // nothing to do
+ }
+
+ logger.setThreshold( threshold );
+ }
+
+ public int getThreshold( String role, String roleHint ) {
+ ConsoleLogger logger;
+ String name;
+
+ name = toMapKey( role, roleHint );
+ logger = (ConsoleLogger)loggers.get( name );
+
+ if(logger == null) {
+ debug( "Trying to get the threshold of a unknown logger '" + name + "'." );
+ return Logger.LEVEL_DEBUG; // does not return null because that could create a NPE
+ }
+
+ return logger.getThreshold();
+ }
+
+ public Logger createLogger(int threshold, String name)
+ {
+ return new ConsoleLogger( threshold, name );
+ }
+
+ public Logger getLoggerForComponent( String role, String roleHint )
+ {
+ Logger logger;
+ String name;
+
+ name = toMapKey( role, roleHint );
+ logger = (Logger)loggers.get( name );
+
+ if ( logger != null )
+ return logger;
+
+ debug( "Creating logger '" + name + "' " + this.hashCode() + "." );
+ logger = createLogger( getThreshold(), name );
+ loggers.put( name, logger );
+
+ return logger;
+ }
+
+ public void returnComponentLogger( String role, String roleHint )
+ {
+ Object obj;
+ String name;
+
+ name = toMapKey( role, roleHint );
+ obj = loggers.remove( name );
+
+ if ( obj == null )
+ {
+ debug( "There was no such logger '" + name + "' " + this.hashCode() + ".");
+ }
+ else
+ {
+ debug( "Removed logger '" + name + "' " + this.hashCode() + ".");
+ }
+ }
+
+ public int getActiveLoggerCount()
+ {
+ return loggers.size();
+ }
+
+ private int parseThreshold( String text )
+ {
+ text = text.trim().toLowerCase();
+
+ if ( text.equals( "debug" ) )
+ {
+ return ConsoleLogger.LEVEL_DEBUG;
+ }
+ else if ( text.equals( "info" ) )
+ {
+ return ConsoleLogger.LEVEL_INFO;
+ }
+ else if ( text.equals( "warn" ) )
+ {
+ return ConsoleLogger.LEVEL_WARN;
+ }
+ else if ( text.equals( "error" ) )
+ {
+ return ConsoleLogger.LEVEL_ERROR;
+ }
+ else if ( text.equals( "fatal" ) )
+ {
+ return ConsoleLogger.LEVEL_FATAL;
+ }
+
+ return -1;
+ }
+
+ private String decodeLogLevel( int logLevel )
+ {
+ switch(logLevel) {
+ case ConsoleLogger.LEVEL_DEBUG: return "debug";
+ case ConsoleLogger.LEVEL_INFO: return "info";
+ case ConsoleLogger.LEVEL_WARN: return "warn";
+ case ConsoleLogger.LEVEL_ERROR: return "error";
+ case ConsoleLogger.LEVEL_FATAL: return "fatal";
+ case ConsoleLogger.LEVEL_DISABLED: return "disabled";
+ default: return "unknown";
+ }
+ }
+
+ /**
+ * Remove this method and all references when this code is verified.
+ *
+ * @param msg
+ */
+ private void debug( String msg )
+ {
+// if ( !bootTimeLogger )
+// System.out.println( "[Console] " + msg );
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/DOM2Utils.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/DOM2Utils.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/DOM2Utils.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/DOM2Utils.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,206 @@
+package org.codehaus.plexus.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 java.io.StringWriter;
+import java.io.Writer;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.codehaus.plexus.util.StringUtils;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * DOM2Utils - provides a bridge for some DOM3 methods to the DOM2 present in JDK 1.5
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class DOM2Utils
+{
+ /**
+ * In DOM3, there is a method called Node.getTextContext() which returns the text nodes
+ * of the node and all child nodes. This is a DOM2 equivalent.
+ *
+ * @param node the node to start from.
+ * @return the string of all node and child node text nodes.
+ */
+ public static String getTextContext( Node node )
+ {
+ StringBuilder txt = new StringBuilder();
+
+ appendTextNodes( node, txt );
+
+ return txt.toString();
+ }
+
+ private static void appendTextNodes( Node node, StringBuilder txt )
+ {
+ if ( node.getNodeType() == Node.TEXT_NODE )
+ {
+ txt.append( node.getNodeValue() );
+ }
+ else if ( node.getNodeType() == Node.ELEMENT_NODE )
+ {
+ Element elem = (Element) node;
+ NodeList nodes = elem.getChildNodes();
+ int len = nodes.getLength();
+ for ( int i = 0; i < len; i++ )
+ {
+ appendTextNodes( nodes.item( i ), txt );
+ }
+ }
+ }
+
+ public static String escapeAttributeValue( String value )
+ {
+ if ( StringUtils.isEmpty( value ) )
+ {
+ return null;
+ }
+ StringWriter writer = new StringWriter( value.length() * 2 );
+ try
+ {
+ escapeJavaStyleString( writer, value, true );
+ return writer.toString();
+ }
+ catch ( IOException e )
+ {
+ // this should never ever happen while writing to a StringWriter
+ throw new RuntimeException( "error during escapeJavaStyleString " + e.getMessage(), e );
+ }
+ }
+
+ public static String escapeText( String text )
+ {
+ return StringEscapeUtils.escapeXml( text );
+ }
+
+ /**
+ * Hack to prevent change in commons-lang see :
+ * http://issues.apache.org/jira/browse/LANG-363
+ * to prevent http://jira.codehaus.org/browse/CONTINUUM-1816
+ * org/apache/maven/continuum/security.properties -> org\/apache\/maven\/continuum\/security.properties
+ * @param out
+ * @param str
+ * @param escapeSingleQuote
+ * @throws IOException
+ */
+ private static void escapeJavaStyleString( Writer out, String str, boolean escapeSingleQuote )
+ throws IOException
+ {
+ if ( out == null )
+ {
+ throw new IllegalArgumentException( "The Writer must not be null" );
+ }
+ if ( str == null )
+ {
+ return;
+ }
+ int sz;
+ sz = str.length();
+ for ( int i = 0; i < sz; i++ )
+ {
+ char ch = str.charAt( i );
+
+ // handle unicode
+ if ( ch > 0xfff )
+ {
+ out.write( "\\u" + hex( ch ) );
+ }
+ else if ( ch > 0xff )
+ {
+ out.write( "\\u0" + hex( ch ) );
+ }
+ else if ( ch > 0x7f )
+ {
+ out.write( "\\u00" + hex( ch ) );
+ }
+ else if ( ch < 32 )
+ {
+ switch ( ch )
+ {
+ case '\b':
+ out.write( '\\' );
+ out.write( 'b' );
+ break;
+ case '\n':
+ out.write( '\\' );
+ out.write( 'n' );
+ break;
+ case '\t':
+ out.write( '\\' );
+ out.write( 't' );
+ break;
+ case '\f':
+ out.write( '\\' );
+ out.write( 'f' );
+ break;
+ case '\r':
+ out.write( '\\' );
+ out.write( 'r' );
+ break;
+ default:
+ if ( ch > 0xf )
+ {
+ out.write( "\\u00" + hex( ch ) );
+ }
+ else
+ {
+ out.write( "\\u000" + hex( ch ) );
+ }
+ break;
+ }
+ }
+ else
+ {
+ switch ( ch )
+ {
+ case '\'':
+ if ( escapeSingleQuote )
+ {
+ out.write( '\\' );
+ }
+ out.write( '\'' );
+ break;
+ case '"':
+ out.write( '\\' );
+ out.write( '"' );
+ break;
+ case '\\':
+ out.write( '\\' );
+ out.write( '\\' );
+ break;
+ default:
+ out.write( ch );
+ break;
+ }
+ }
+ }
+ }
+
+ private static String hex( char ch )
+ {
+ return Integer.toHexString( ch ).toUpperCase();
+ }
+
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/DOM2Utils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/DOM2Utils.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusApplicationContextDelegate.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusApplicationContextDelegate.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusApplicationContextDelegate.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusApplicationContextDelegate.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,101 @@
+package org.codehaus.plexus.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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.codehaus.plexus.spring.editors.CollectionPropertyEditor;
+import org.codehaus.plexus.spring.editors.MapPropertyEditor;
+import org.codehaus.plexus.spring.editors.PropertiesPropertyEditor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * Utility method to convert plexus descriptors to spring bean context.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @version $Id$
+ */
+public class PlexusApplicationContextDelegate
+{
+ /** Logger used by this class. */
+ protected Logger logger = LoggerFactory.getLogger( getClass() );
+
+ private PlexusLifecycleBeanPostProcessor lifecycleBeanPostProcessor;
+
+ /**
+ * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
+ */
+ protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
+ throws BeansException, IOException
+ {
+ logger.info( "Registering Plexus to Spring XML translation" );
+ reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
+ }
+
+ /**
+ * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
+ */
+ protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory, ApplicationContext context )
+ {
+ // Register a PlexusContainerAdapter bean to allow context lookups using plexus API
+ PlexusContainerAdapter plexus = new PlexusContainerAdapter();
+ plexus.setApplicationContext( context );
+ beanFactory.registerSingleton( "plexusContainer", plexus );
+
+ // Register a beanPostProcessor to handle plexus interface-based lifecycle management
+ lifecycleBeanPostProcessor = new PlexusLifecycleBeanPostProcessor();
+ lifecycleBeanPostProcessor.setBeanFactory( context );
+ beanFactory.addBeanPostProcessor( lifecycleBeanPostProcessor );
+
+ // Register a PropertyEditor to support plexus XML <configuration> set as CDATA in
+ // a spring context XML file.
+ beanFactory.addPropertyEditorRegistrar( new PlexusConfigurationPropertyEditor() );
+ beanFactory.addPropertyEditorRegistrar( new PropertiesPropertyEditor() );
+ beanFactory.addPropertyEditorRegistrar( new CollectionPropertyEditor( List.class, ArrayList.class ) );
+ beanFactory.addPropertyEditorRegistrar( new CollectionPropertyEditor( Set.class, HashSet.class ) );
+ beanFactory.addPropertyEditorRegistrar( new MapPropertyEditor( Map.class, HashMap.class ) );
+ }
+
+ /**
+ * @see org.springframework.context.support.AbstractApplicationContext#doClose()
+ */
+ protected void doClose()
+ {
+ try
+ {
+ lifecycleBeanPostProcessor.destroy();
+ }
+ catch ( Throwable ex )
+ {
+ logger.error( "Exception thrown from PlexusLifecycleBeanPostProcessor handling ContextClosedEvent", ex );
+ }
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusApplicationContextDelegate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusApplicationContextDelegate.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,157 @@
+package org.codehaus.plexus.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 java.io.InputStream;
+import java.io.StringWriter;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+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.dom4j.io.DOMReader;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+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>
+ * @version $Id$
+ */
+public class PlexusBeanDefinitionDocumentReader
+ extends DefaultBeanDefinitionDocumentReader
+{
+ private static final String XSL = "PlexusBeanDefinitionDocumentReader.xsl";
+
+ private Transformer transformer;
+
+ public PlexusBeanDefinitionDocumentReader()
+ {
+ super();
+
+ InputStream is = getClass().getResourceAsStream( XSL );
+ if ( is == null )
+ {
+ throw new BeanDefinitionStoreException( "XSL not found in the classpath: " + XSL );
+ }
+ Source xsltSource = new StreamSource( is );
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+
+ try
+ {
+ transformer = tf.newTransformer( xsltSource );
+ }
+ catch ( TransformerConfigurationException e )
+ {
+ String msg = "Failed to load Plexus to Spring XSL " + XSL;
+ throw new BeanDefinitionStoreException( msg, e );
+ }
+ }
+
+ public void registerBeanDefinitions( Document doc, XmlReaderContext readerContext )
+ {
+ doc = convertPlexusDescriptorToSpringBeans( doc, readerContext );
+ super.registerBeanDefinitions( doc, readerContext );
+ }
+
+ /**
+ * @deprecated
+ */
+ protected Document convertPlexusDescriptorToSpringBeans( Document doc )
+ {
+ return convertPlexusDescriptorToSpringBeans( doc, null );
+ }
+
+ protected Document convertPlexusDescriptorToSpringBeans( Document doc, XmlReaderContext readerContext )
+ {
+ if ( "component-set".equals( doc.getDocumentElement().getNodeName() ) )
+ {
+ return translatePlexusDescriptor( doc, readerContext );
+ }
+ if ( "plexus".equals( doc.getDocumentElement().getNodeName() ) )
+ {
+ return translatePlexusDescriptor( doc, readerContext );
+ }
+
+ return doc;
+ }
+
+ private Document translatePlexusDescriptor( Document doc, XmlReaderContext readerContext )
+ {
+ Source xmlSource = new DOMSource( doc );
+ DOMResult transResult = new DOMResult();
+
+ if ( logger.isDebugEnabled() )
+ {
+ log( doc, "Plexus Bean Definition Document to be translated" );
+ }
+
+ try
+ {
+ transformer.transform( xmlSource, transResult );
+
+ if ( logger.isDebugEnabled() )
+ {
+ log( (Document) transResult.getNode(),
+ "Plexus Bean Definition Document successfully translated to Spring" );
+ }
+ return (Document) transResult.getNode();
+ }
+ catch ( TransformerException e )
+ {
+ String msg = "Failed to translate plexus component descriptor to Spring XML context";
+ if ( readerContext != null )
+ {
+ msg += " : " + readerContext.getResource();
+ }
+ throw new BeanDefinitionStoreException( msg, e );
+ }
+ }
+
+ private void log( Document doc, String msg )
+ {
+ try
+ {
+ logger.debug( msg );
+ StringWriter stringWriter = new StringWriter();
+ XMLWriter writer = new XMLWriter( stringWriter, OutputFormat.createPrettyPrint() );
+ writer.write( new DOMReader().read( doc ) );
+ logger.debug( stringWriter.toString() );
+ }
+ catch ( IOException e )
+ {
+ // ignored
+ }
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusBeanDefinitionDocumentReader.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,149 @@
+package org.codehaus.plexus.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.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.beans.factory.xml.ResourceEntityResolver;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * A custom ClassPathXmlApplicationContext to support plexus
+ * <tr>components.xml</tt> descriptors in Spring, with no changes required to
+ * neither plexus nor spring beans.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @version $Id$
+ */
+public class PlexusClassPathXmlApplicationContext
+ extends ClassPathXmlApplicationContext
+{
+ private static PlexusApplicationContextDelegate delegate = new PlexusApplicationContextDelegate();
+
+ 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)
+ */
+ protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
+ throws BeansException, IOException
+ {
+ delegate.loadBeanDefinitions( reader );
+ super.loadBeanDefinitions( reader );
+ }
+
+ /**
+ * Copied from {@link AbstractXmlApplicationContext}
+ * Loads the bean definitions via an XmlBeanDefinitionReader.
+ * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
+ * @see #initBeanDefinitionReader
+ * @see #loadBeanDefinitions
+ */
+ protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
+ // Create a new XmlBeanDefinitionReader for the given BeanFactory.
+ XmlBeanDefinitionReader beanDefinitionReader = new PlexusXmlBeanDefinitionReader(beanFactory);
+
+ // Configure the bean definition reader with this context's
+ // resource loading environment.
+ beanDefinitionReader.setResourceLoader(this);
+ beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
+
+ // Allow a subclass to provide custom initialization of the reader,
+ // then proceed with actually loading the bean definitions.
+ initBeanDefinitionReader(beanDefinitionReader);
+ loadBeanDefinitions(beanDefinitionReader);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
+ */
+ protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
+ {
+ delegate.postProcessBeanFactory( beanFactory, this );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.context.support.AbstractApplicationContext#doClose()
+ */
+ protected void doClose()
+ {
+ delegate.doClose();
+ super.doClose();
+ }
+
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusClassPathXmlApplicationContext.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,348 @@
+package org.codehaus.plexus.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.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.SimpleTypeConverter;
+import org.springframework.beans.TypeConverter;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.ListableBeanFactory;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * A FactoryBean dedicated to building plexus components. This includes :
+ * <ul>
+ * <li>Support for direct field injection or "requirements"</li>
+ * <li>Support for LogEnabled, Initializable and Disposable plexus interfaces</li>
+ * <li>Support for plexus.requirement to get a Map<role-hint, component> for a
+ * role
+ * </ul>
+ * If not set, the beanFactory will auto-detect the loggerManager to use by
+ * searching for the adequate bean in the spring context.
+ * <p>
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @version $Id$
+ */
+public class PlexusComponentFactoryBean
+ implements FactoryBean, BeanFactoryAware
+{
+ /** Logger available to subclasses */
+ protected Logger logger = LoggerFactory.getLogger( getClass() );
+
+ /** The beanFactory */
+ private BeanFactory beanFactory;
+
+ /**
+ * @todo isn't there a constant for this in plexus ?
+ */
+ private static final String SINGLETON = "singleton";
+
+ /** The plexus component role */
+ private Class role;
+
+ /** The Spring bean reference */
+ private String beanRef;
+
+ /** The plexus component implementation class */
+ private Class implementation;
+
+ /** The plexus component instantiation strategy */
+ private String instantiationStrategy;
+
+ /** The plexus component requirements and configurations */
+ private Map requirements;
+
+ private PlexusConfiguration configuration;
+
+ private Object singletonInstance;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.beans.factory.FactoryBean#getObject()
+ */
+ public Object getObject()
+ throws Exception
+ {
+ if ( isSingleton() )
+ {
+ synchronized ( this )
+ {
+ if ( singletonInstance != null )
+ {
+ return singletonInstance;
+ }
+ this.singletonInstance = createInstance();
+ return singletonInstance;
+ }
+ }
+ return createInstance();
+ }
+
+ /**
+ * Create the plexus component instance. Inject dependencies declared as
+ * requirements using direct field injection
+ */
+ public Object createInstance()
+ throws Exception
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug( "Creating Plexus component " + implementation );
+ }
+ final Object component = implementation.newInstance();
+ if ( requirements != null )
+ {
+ for ( Iterator iterator = requirements.entrySet().iterator(); iterator.hasNext(); )
+ {
+ Map.Entry requirement = (Map.Entry) iterator.next();
+ String fieldName = (String) requirement.getKey();
+
+ if ( fieldName.startsWith( "#" ) )
+ {
+ // implicit field injection : the field name was no
+ // specified in the plexus descriptor as only one filed
+ // matches Dependency type
+
+ PlexusRuntimeBeanReference ref = (PlexusRuntimeBeanReference) requirement.getValue();
+ Object dependency = beanFactory.getBean( ref.getBeanName() );
+ List fields = getFieldsIncludingSuperclasses( implementation );
+ for ( Iterator fieldIterator = fields.iterator(); fieldIterator.hasNext(); )
+ {
+ Field field = (Field) fieldIterator.next();
+ if ( ReflectionUtils.COPYABLE_FIELDS.matches( field )
+ && field.getType().isAssignableFrom( dependency.getClass() ) )
+ {
+ if ( logger.isTraceEnabled() )
+ {
+ logger.trace( "Injecting dependency " + dependency + " into field " + field.getName() );
+ }
+ ReflectionUtils.makeAccessible( field );
+ ReflectionUtils.setField( field, component, dependency );
+ }
+ }
+ }
+ else
+ {
+ // explicit field injection
+ fieldName = PlexusToSpringUtils.toCamelCase( fieldName );
+ Field field = findField( fieldName, implementation );
+ Object dependency = resolveRequirement( field, requirement.getValue() );
+ if ( logger.isTraceEnabled() )
+ {
+ logger.trace( "Injecting dependency " + dependency + " into field " + field.getName() );
+ }
+ ReflectionUtils.makeAccessible( field );
+ ReflectionUtils.setField( field, component, dependency );
+ }
+ }
+ }
+
+ // saving the configuration in the container adapter for reuse in the PlexusLifecycleBeanPostProcessor
+ PlexusContainerAdapter plexusContainerAdapter = (PlexusContainerAdapter) beanFactory
+ .getBean( "plexusContainer" );
+ plexusContainerAdapter.getPlexusConfigurationPerComponent().put( beanRef, configuration );
+
+ return component;
+ }
+
+ protected List /* Field */ getFieldsIncludingSuperclasses( Class type )
+ {
+
+ Field[] fields = type.getDeclaredFields();
+
+ List foundFields = new ArrayList();
+
+ for ( int i = 0, size = fields.length; i < size; i++ )
+ {
+ foundFields.add( fields[i] );
+ }
+
+ if ( type.getSuperclass() != Object.class )
+ {
+ List superFields = getFieldsIncludingSuperclasses( type.getSuperclass() );
+
+ foundFields.addAll( superFields );
+ }
+
+ return foundFields;
+ }
+
+ private Field findField( String fieldName, Class type )
+ {
+ Class clazz = implementation;
+ while ( clazz != Object.class )
+ {
+ try
+ {
+ return clazz.getDeclaredField( fieldName );
+ }
+ catch ( NoSuchFieldException e )
+ {
+ clazz = clazz.getSuperclass();
+ }
+ }
+ String error = "No field " + fieldName + " on implementation class " + implementation;
+ logger.error( error );
+ throw new BeanInitializationException( error );
+ }
+
+ /**
+ * Resolve the requirement that this field exposes in the component
+ *
+ * @param field
+ * @return
+ */
+ protected Object resolveRequirement( Field field, Object requirement )
+ {
+ if ( requirement instanceof RuntimeBeanReference )
+ {
+ String beanName = ( (RuntimeBeanReference) requirement ).getBeanName();
+ if ( Map.class.isAssignableFrom( field.getType() ) )
+ {
+ // component ask plexus for a Map of all available
+ // components for the role
+ requirement = PlexusToSpringUtils.lookupMap( beanName, getListableBeanFactory() );
+ }
+ else if ( Collection.class.isAssignableFrom( field.getType() ) )
+ {
+ requirement = PlexusToSpringUtils.lookupList( beanName, getListableBeanFactory() );
+ }
+ else
+ {
+ requirement = beanFactory.getBean( beanName );
+ }
+ }
+ if ( requirement != null )
+ {
+ requirement = getBeanTypeConverter().convertIfNecessary( requirement, field.getType() );
+ }
+ return requirement;
+
+ }
+
+ public Class getObjectType()
+ {
+ return role;
+ }
+
+ public boolean isSingleton()
+ {
+ return SINGLETON.equals( instantiationStrategy );
+ }
+
+ protected TypeConverter getBeanTypeConverter()
+ {
+ if ( beanFactory instanceof ConfigurableBeanFactory )
+ {
+ return ( (ConfigurableBeanFactory) beanFactory ).getTypeConverter();
+ }
+ else
+ {
+ return new SimpleTypeConverter();
+ }
+ }
+
+ private ListableBeanFactory getListableBeanFactory()
+ {
+ if ( beanFactory instanceof ListableBeanFactory )
+ {
+ return (ListableBeanFactory) beanFactory;
+ }
+ throw new BeanInitializationException( "A ListableBeanFactory is required by the PlexusComponentFactoryBean" );
+ }
+
+ /**
+ * @param role the role to set
+ */
+ public void setRole( Class role )
+ {
+ this.role = role;
+ }
+
+ /**
+ * @param implementation the implementation to set
+ */
+ public void setImplementation( Class implementation )
+ {
+ this.implementation = implementation;
+ }
+
+ /**
+ * @param instantiationStrategy the instantiationStrategy to set
+ */
+ public void setInstantiationStrategy( String instantiationStrategy )
+ {
+ if ( instantiationStrategy.length() == 0 )
+ {
+ instantiationStrategy = SINGLETON;
+ }
+ if ( "poolable".equals( instantiationStrategy ) )
+ {
+ throw new BeanCreationException( "Plexus poolable instantiation-strategy is not supported" );
+ }
+ this.instantiationStrategy = instantiationStrategy;
+ }
+
+ /**
+ * @param requirements the requirements to set
+ */
+ public void setRequirements( Map requirements )
+ {
+ this.requirements = requirements;
+ }
+
+ public void setBeanFactory( BeanFactory beanFactory )
+ {
+ this.beanFactory = beanFactory;
+ }
+
+ public PlexusConfiguration getConfiguration()
+ {
+ return configuration;
+ }
+
+ public void setConfiguration( PlexusConfiguration configuration )
+ {
+ this.configuration = configuration;
+ }
+
+ public void setBeanRef( String beanRef )
+ {
+ this.beanRef = beanRef;
+ }
+
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusComponentFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusConfigurationPropertyEditor.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusConfigurationPropertyEditor.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusConfigurationPropertyEditor.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusConfigurationPropertyEditor.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,77 @@
+package org.codehaus.plexus.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.beans.PropertyEditorSupport;
+import java.io.StringReader;
+
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.springframework.beans.PropertyEditorRegistrar;
+import org.springframework.beans.PropertyEditorRegistry;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @version $Id$
+ */
+public class PlexusConfigurationPropertyEditor
+ extends PropertyEditorSupport
+ implements PropertyEditorRegistrar
+{
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.beans.PropertyEditorRegistrar#registerCustomEditors(org.springframework.beans.PropertyEditorRegistry)
+ */
+ public void registerCustomEditors( PropertyEditorRegistry registry )
+ {
+ registry.registerCustomEditor( PlexusConfiguration.class, this );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
+ */
+ public void setAsText( String text )
+ throws IllegalArgumentException
+ {
+ if (StringUtils.isBlank( text ))
+ {
+ setValue( null );
+ return;
+ }
+ try
+ {
+ Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( text ) );
+ XmlPlexusConfiguration configuration = new XmlPlexusConfiguration( dom );
+ setValue( configuration );
+ }
+ catch ( Exception e )
+ {
+ throw new IllegalArgumentException( "Failed to convert to Plexus XML configuration", e );
+ }
+ }
+
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusConfigurationPropertyEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusConfigurationPropertyEditor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,752 @@
+package org.codehaus.plexus.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.File;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.PlexusContainerException;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.composition.CompositionException;
+import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
+import org.codehaus.plexus.component.repository.ComponentDescriptor;
+import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.LoggerManager;
+import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.ServiceLocator;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+/**
+ * An adapter to access Spring ApplicationContext from a plexus component
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @version $Id$
+ */
+public class PlexusContainerAdapter
+ implements PlexusContainer, ApplicationContextAware, ServiceLocator
+{
+
+ private org.slf4j.Logger logger = LoggerFactory.getLogger( getClass() );
+
+ private Context context = new SimpleContext();
+
+ private ApplicationContext applicationContext;
+
+ private String name = "plexus-spring adapter";
+
+ private Date creationDate = new Date();
+
+ /** key : component key , value : PlexusConfiguration */
+ private Map plexusConfigurationPerComponent = new HashMap();
+
+ public PlexusContainerAdapter()
+ {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#addComponentDescriptor(org.codehaus.plexus.component.repository.ComponentDescriptor)
+ */
+ public void addComponentDescriptor( ComponentDescriptor componentDescriptor )
+ throws ComponentRepositoryException
+ {
+ throw new UnsupportedOperationException( "addComponentDescriptor( ComponentDescriptor componentDescriptor )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#addContextValue(java.lang.Object, java.lang.Object)
+ */
+ public void addContextValue( Object key, Object value )
+ {
+ context.put( key, value );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#addJarRepository(java.io.File)
+ */
+ public void addJarRepository( File repository )
+ {
+ throw new UnsupportedOperationException( "addJarRepository( File repository )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#addJarResource(java.io.File)
+ */
+ public void addJarResource( File resource )
+ throws PlexusContainerException
+ {
+ throw new UnsupportedOperationException( "addJarResource( File resource )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#autowire(java.lang.Object)
+ */
+ public Object autowire( Object component )
+ throws CompositionException
+ {
+ throw new UnsupportedOperationException( "autowire( Object component )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#createAndAutowire(java.lang.String)
+ */
+ public Object createAndAutowire( String clazz )
+ throws CompositionException, ClassNotFoundException, InstantiationException, IllegalAccessException
+ {
+ throw new UnsupportedOperationException( "createAndAutowire( String clazz )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map)
+ */
+ public PlexusContainer createChildContainer( String name, List classpathJars, Map context )
+ throws PlexusContainerException
+ {
+ throw new UnsupportedOperationException( "createChildContainer( String name, List classpathJars, Map context )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map, java.util.List)
+ */
+ public PlexusContainer createChildContainer( String name, List classpathJars, Map context, List discoveryListeners )
+ throws PlexusContainerException
+ {
+ throw new UnsupportedOperationException(
+ "createChildContainer( String name, List classpathJars, Map context, List discoveryListeners )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#createComponentRealm(java.lang.String, java.util.List)
+ */
+ public ClassRealm createComponentRealm( String id, List jars )
+ throws PlexusContainerException
+ {
+ throw new UnsupportedOperationException( "createComponentRealm( String id, List jars )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#dispose()
+ */
+ public void dispose()
+ {
+ throw new UnsupportedOperationException( "dispose()" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getChildContainer(java.lang.String)
+ */
+ public PlexusContainer getChildContainer( String name )
+ {
+ throw new UnsupportedOperationException( "getChildContainer( String name )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String)
+ */
+ public ComponentDescriptor getComponentDescriptor( String role )
+ {
+ throw new UnsupportedOperationException( "getComponentDescriptor( String role )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String, java.lang.String)
+ */
+ public ComponentDescriptor getComponentDescriptor( String role, String roleHint )
+ {
+ throw new UnsupportedOperationException( "getComponentDescriptor( String role, String roleHint )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public ComponentDescriptor getComponentDescriptor( String role, ClassRealm realm )
+ {
+ throw new UnsupportedOperationException( "getComponentDescriptor( String role, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String, java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public ComponentDescriptor getComponentDescriptor( String role, String roleHint, ClassRealm realm )
+ {
+ throw new UnsupportedOperationException(
+ "getComponentDescriptor( String role, String roleHint, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorList(java.lang.String)
+ */
+ public List getComponentDescriptorList( String role )
+ {
+ throw new UnsupportedOperationException( "getComponentDescriptorList( String role )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorList(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public List getComponentDescriptorList( String role, ClassRealm componentRealm )
+ {
+ throw new UnsupportedOperationException( "getComponentDescriptorList( String role, ClassRealm componentRealm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorMap(java.lang.String)
+ */
+ public Map getComponentDescriptorMap( String role )
+ {
+ throw new UnsupportedOperationException( "getComponentDescriptorMap( String role )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorMap(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public Map getComponentDescriptorMap( String role, ClassRealm componentRealm )
+ {
+ throw new UnsupportedOperationException( "getComponentDescriptorMap( String role, ClassRealm componentRealm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getComponentRealm(java.lang.String)
+ */
+ public ClassRealm getComponentRealm( String realmId )
+ {
+ throw new UnsupportedOperationException( "getComponentRealm( String realmId )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getContainerRealm()
+ */
+ public ClassRealm getContainerRealm()
+ {
+ throw new UnsupportedOperationException( "getContainerRealm()" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getContext()
+ */
+ public Context getContext()
+ {
+ return context;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getCreationDate()
+ */
+ public Date getCreationDate()
+ {
+ return creationDate;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getLogger()
+ */
+ public Logger getLogger()
+ {
+ return getLoggerManager().getLoggerForComponent( getClass().getName() );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getLoggerManager()
+ */
+ public LoggerManager getLoggerManager()
+ {
+ if ( this.applicationContext.containsBean( "loggerManager" ) )
+ {
+ return (LoggerManager) this.applicationContext.getBean( "loggerManager" );
+ }
+ else
+ {
+ logger.warn( "No loggerManager set in context. Falling back to ConsoleLoggerManager" );
+ ConsoleLoggerManager defaultLoggerManager = new ConsoleLoggerManager();
+ defaultLoggerManager.initialize();
+ return defaultLoggerManager;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getLookupRealm()
+ */
+ public ClassRealm getLookupRealm()
+ {
+ throw new UnsupportedOperationException( "getLookupRealm()" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getLookupRealm(java.lang.Object)
+ */
+ public ClassRealm getLookupRealm( Object component )
+ {
+ throw new UnsupportedOperationException( "getLookupRealm( Object component )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#getName()
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#hasChildContainer(java.lang.String)
+ */
+ public boolean hasChildContainer( String name )
+ {
+ throw new UnsupportedOperationException( "hasChildContainer( String name )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String)
+ */
+ public boolean hasComponent( String role )
+ {
+ return applicationContext.containsBean( PlexusToSpringUtils.buildSpringId( role ) );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String, java.lang.String)
+ */
+ public boolean hasComponent( String role, String roleHint )
+ {
+ return applicationContext.containsBean( PlexusToSpringUtils.buildSpringId( role, roleHint ) );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#isReloadingEnabled()
+ */
+ public boolean isReloadingEnabled()
+ {
+ throw new UnsupportedOperationException( "isReloadingEnabled()" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String)
+ */
+ public Object lookup( String componentKey )
+ throws ComponentLookupException
+ {
+ return lookup( componentKey, (String) null );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class)
+ */
+ public Object lookup( Class componentClass )
+ throws ComponentLookupException
+ {
+ return lookup( componentClass.getName(), (String) null );
+
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public Object lookup( String componentKey, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookup( String componentKey, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, java.lang.String)
+ */
+ public Object lookup( String role, String roleHint )
+ throws ComponentLookupException
+ {
+ return applicationContext.getBean( PlexusToSpringUtils.buildSpringId( role, roleHint ) );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public Object lookup( Class componentClass, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookup( Class componentClass, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class, java.lang.String)
+ */
+ public Object lookup( Class role, String roleHint )
+ throws ComponentLookupException
+ {
+ return lookup( role.getName(), roleHint );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public Object lookup( String role, String roleHint, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookup( String role, String roleHint, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.Class, java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public Object lookup( Class role, String roleHint, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookup( Class role, String roleHint, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.String)
+ */
+ public List lookupList( String role )
+ throws ComponentLookupException
+ {
+ return PlexusToSpringUtils.lookupList( PlexusToSpringUtils.buildSpringId( role ), applicationContext );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.Class)
+ */
+ public List lookupList( Class role )
+ throws ComponentLookupException
+ {
+ return lookupList( role.getName() );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public List lookupList( String role, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookupList( String role, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.Class, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public List lookupList( Class role, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookupList( Class role, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.String)
+ */
+ public Map lookupMap( String role )
+ throws ComponentLookupException
+ {
+ return PlexusToSpringUtils.lookupMap( PlexusToSpringUtils.buildSpringId( role ), applicationContext );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.Class)
+ */
+ public Map lookupMap( Class role )
+ throws ComponentLookupException
+ {
+ return lookupMap( role.getName() );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.String, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public Map lookupMap( String role, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookupMap( String role, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.Class, org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public Map lookupMap( Class role, ClassRealm realm )
+ throws ComponentLookupException
+ {
+ throw new UnsupportedOperationException( "lookupMap( Class role, ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#registerComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener)
+ */
+ public void registerComponentDiscoveryListener( ComponentDiscoveryListener listener )
+ {
+ throw new UnsupportedOperationException(
+ "registerComponentDiscoveryListener( ComponentDiscoveryListener listener )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#release(java.lang.Object)
+ */
+ public void release( Object component )
+ throws ComponentLifecycleException
+ {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.Map)
+ */
+ public void releaseAll( Map components )
+ throws ComponentLifecycleException
+ {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.List)
+ */
+ public void releaseAll( List components )
+ throws ComponentLifecycleException
+ {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#removeChildContainer(java.lang.String)
+ */
+ public void removeChildContainer( String name )
+ {
+ throw new UnsupportedOperationException( "removeChildContainer( String name )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#removeComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener)
+ */
+ public void removeComponentDiscoveryListener( ComponentDiscoveryListener listener )
+ {
+ throw new UnsupportedOperationException(
+ "removeComponentDiscoveryListener( ComponentDiscoveryListener listener )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#resume(java.lang.Object)
+ */
+ public void resume( Object component )
+ throws ComponentLifecycleException
+ {
+ throw new UnsupportedOperationException( "resume( Object component )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#setLoggerManager(org.codehaus.plexus.logging.LoggerManager)
+ */
+ public void setLoggerManager( LoggerManager loggerManager )
+ {
+ // ignored
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#setLookupRealm(org.codehaus.plexus.classworlds.realm.ClassRealm)
+ */
+ public ClassRealm setLookupRealm( ClassRealm realm )
+ {
+ throw new UnsupportedOperationException( "setLookupRealm( ClassRealm realm )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#setName(java.lang.String)
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#setParentPlexusContainer(org.codehaus.plexus.PlexusContainer)
+ */
+ public void setParentPlexusContainer( PlexusContainer container )
+ {
+ throw new UnsupportedOperationException( "setParentPlexusContainer( PlexusContainer container )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#setReloadingEnabled(boolean)
+ */
+ public void setReloadingEnabled( boolean reloadingEnabled )
+ {
+ throw new UnsupportedOperationException( "setReloadingEnabled( boolean reloadingEnabled )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.PlexusContainer#suspend(java.lang.Object)
+ */
+ public void suspend( Object component )
+ throws ComponentLifecycleException
+ {
+ throw new UnsupportedOperationException( "suspend( Object component )" );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+ */
+ public void setApplicationContext( ApplicationContext applicationContext )
+ throws BeansException
+ {
+ this.applicationContext = applicationContext;
+ }
+
+ private class SimpleContext
+ implements Context
+ {
+ private Map map = new HashMap();
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.context.Context#contains(java.lang.Object)
+ */
+ public boolean contains( Object key )
+ {
+ return PlexusConstants.PLEXUS_KEY.equals( key ) || map.containsKey( key );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.context.Context#get(java.lang.Object)
+ */
+ public Object get( Object key )
+ throws ContextException
+ {
+ return PlexusConstants.PLEXUS_KEY.equals( key ) ? PlexusContainerAdapter.this : map.get( key );
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.context.Context#getContextData()
+ */
+ public Map getContextData()
+ {
+ return map;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.context.Context#hide(java.lang.Object)
+ */
+ public void hide( Object key )
+ throws IllegalStateException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.context.Context#makeReadOnly()
+ */
+ public void makeReadOnly()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.context.Context#put(java.lang.Object, java.lang.Object)
+ */
+ public void put( Object key, Object value )
+ throws IllegalStateException
+ {
+ map.put( key, value );
+ }
+
+ }
+
+ public Map getPlexusConfigurationPerComponent()
+ {
+ return plexusConfigurationPerComponent;
+ }
+
+ public void setPlexusConfigurationPerComponent( Map plexusConfigurationPerComponent )
+ {
+ this.plexusConfigurationPerComponent = plexusConfigurationPerComponent;
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusContainerAdapter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,170 @@
+package org.codehaus.plexus.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.File;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.codehaus.plexus.PlexusContainer;
+import org.springframework.context.ConfigurableApplicationContext;
+
+/**
+ * Mimic org.codehaus.plexus.PlexusTestCase as simple replacement for test
+ * cases.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ * @version $Id$
+ */
+public class PlexusInSpringTestCase
+ extends TestCase
+{
+ protected ConfigurableApplicationContext applicationContext;
+
+ protected void setUp()
+ throws Exception
+ {
+ applicationContext = new PlexusClassPathXmlApplicationContext( getConfigLocations() );
+ }
+
+ protected String[] getConfigLocations()
+ {
+ return new String[] {
+ "classpath*:META-INF/spring-context.xml",
+ "classpath*:META-INF/plexus/components.xml",
+ "classpath*:" + getPlexusConfigLocation(),
+ "classpath*:" + getSpringConfigLocation() };
+ }
+
+ protected String getSpringConfigLocation()
+ {
+ return getClass().getName().replace( '.', '/' ) + "-context.xml";
+ }
+
+ protected String getPlexusConfigLocation()
+ {
+ return getClass().getName().replace( '.', '/' ) + ".xml";
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown()
+ throws Exception
+ {
+ if ( applicationContext != null )
+ {
+ applicationContext.close();
+ }
+ }
+
+ public static String getBasedir()
+ {
+ return PlexusToSpringUtils.getBasedir();
+ }
+
+ public String getTestConfiguration()
+ {
+ return getTestConfiguration( getClass() );
+ }
+
+ public static String getTestConfiguration( Class clazz )
+ {
+ String s = clazz.getName().replace( '.', '/' );
+
+ return s.substring( 0, s.indexOf( "$" ) ) + ".xml";
+ }
+
+ public Object lookup( Class role )
+ {
+ return lookup( role, null );
+ }
+
+ public Object lookup( Class role, String roleHint )
+ {
+ return lookup( role.getName(), roleHint );
+
+ }
+
+ public Object lookup( String role )
+ {
+ return lookup( role, null );
+ }
+
+ public Object lookup( String role, String roleHint )
+ {
+ return applicationContext.getBean( PlexusToSpringUtils.buildSpringId( role, roleHint ) );
+ }
+
+ public static File getTestFile( String path )
+ {
+ return new File( PlexusToSpringUtils.getBasedir(), path );
+ }
+
+ public static File getTestFile( String basedir,
+ String path )
+ {
+ File basedirFile = new File( basedir );
+
+ if ( !basedirFile.isAbsolute() )
+ {
+ basedirFile = getTestFile( basedir );
+ }
+
+ return new File( basedirFile, path );
+ }
+
+ public static String getTestPath( String path )
+ {
+ return getTestFile( path ).getAbsolutePath();
+ }
+
+ public static String getTestPath( String basedir,
+ String path )
+ {
+ return getTestFile( basedir, path ).getAbsolutePath();
+ }
+
+ protected ConfigurableApplicationContext getApplicationContext()
+ {
+ return applicationContext;
+ }
+
+ protected void release( Object component )
+ throws Exception
+ {
+ // nothing
+ }
+
+ protected PlexusContainer getContainer()
+ {
+ return (PlexusContainer) applicationContext.getBean( "plexusContainer" );
+ }
+
+ protected InputStream getResourceAsStream( String resource )
+ {
+ return getClass().getResourceAsStream( resource );
+ }
+
+
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/spring/PlexusInSpringTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision