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 [2/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-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/DefaultExpressionEvaluator.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/DefaultExpressionEvaluator.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/DefaultExpressionEvaluator.java (added)
+++ archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/DefaultExpressionEvaluator.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,143 @@
+package org.codehaus.plexus.evaluator;
+
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * DefaultExpressionEvaluator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ * @plexus.component role="org.codehaus.plexus.evaluator.ExpressionEvaluator"
+ * role-hint="default"
+ * instantiation-strategy="per-lookup"
+ */
+public class DefaultExpressionEvaluator
+ implements ExpressionEvaluator
+{
+ private List expressionSources;
+
+ public DefaultExpressionEvaluator()
+ {
+ expressionSources = new ArrayList();
+ }
+
+ public void addExpressionSource( ExpressionSource source )
+ {
+ expressionSources.add( source );
+ }
+
+ public String expand( String str )
+ throws EvaluatorException
+ {
+ return recursiveExpand( str, new ArrayList() );
+ }
+
+ private String recursiveExpand( String str, List seenExpressions )
+ throws EvaluatorException
+ {
+ if ( StringUtils.isEmpty( str ) )
+ {
+ // Empty string. Fail fast.
+ return str;
+ }
+
+ if ( str.indexOf( "${" ) < 0 )
+ {
+ // Contains no potential expressions. Fail fast.
+ return str;
+ }
+
+ if ( this.expressionSources.isEmpty() )
+ {
+ throw new EvaluatorException( "Unable to expand expressions with empty ExpressionSource list." );
+ }
+
+ Pattern pat = Pattern.compile( "(?<=[^$]|^)(\\$\\{[^}]*\\})" );
+ Matcher mat = pat.matcher( str );
+ int offset = 0;
+ String expression;
+ String value;
+ StringBuffer expanded = new StringBuffer();
+
+ while ( mat.find( offset ) )
+ {
+ expression = mat.group( 1 );
+
+ if ( seenExpressions.contains( expression ) )
+ {
+ throw new EvaluatorException( "A recursive cycle has been detected with expression " + expression + "." );
+ }
+
+ seenExpressions.add( expression );
+
+ expanded.append( str.substring( offset, mat.start( 1 ) ) );
+ value = findValue( expression );
+ if ( value != null )
+ {
+ String resolvedValue = recursiveExpand( value, seenExpressions );
+ expanded.append( resolvedValue );
+ }
+ else
+ {
+ expanded.append( expression );
+ }
+ offset = mat.end( 1 );
+ }
+
+ expanded.append( str.substring( offset ) );
+
+ if ( expanded.indexOf( "$$" ) >= 0 )
+ {
+ // Special case for escaped content.
+ return expanded.toString().replaceAll( "\\$\\$", "\\$" );
+ }
+ else
+ {
+ // return expanded
+ return expanded.toString();
+ }
+ }
+
+ private String findValue( String expression )
+ {
+ String newExpression = expression.trim();
+ if ( newExpression.startsWith( "${" ) && newExpression.endsWith( "}" ) )
+ {
+ newExpression = newExpression.substring( 2, newExpression.length() - 1 );
+ }
+
+ if ( StringUtils.isEmpty( newExpression ) )
+ {
+ return null;
+ }
+
+ String value = null;
+ Iterator it = this.expressionSources.iterator();
+ while ( it.hasNext() )
+ {
+ ExpressionSource source = (ExpressionSource) it.next();
+ value = source.getExpressionValue( newExpression );
+ if ( value != null )
+ {
+ return value;
+ }
+ }
+ return null;
+ }
+
+ public List getExpressionSourceList()
+ {
+ return this.expressionSources;
+ }
+
+ public boolean removeExpressionSource( ExpressionSource source )
+ {
+ return this.expressionSources.remove( source );
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/DefaultExpressionEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/DefaultExpressionEvaluator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/EvaluatorException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/EvaluatorException.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/EvaluatorException.java (added)
+++ archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/EvaluatorException.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,47 @@
+package org.codehaus.plexus.evaluator;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * 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.
+ */
+
+/**
+ * EvaluatorException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class EvaluatorException
+ extends Exception
+{
+ public EvaluatorException()
+ {
+ super();
+ }
+
+ public EvaluatorException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public EvaluatorException( String message )
+ {
+ super( message );
+ }
+
+ public EvaluatorException( Throwable cause )
+ {
+ super( cause );
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/EvaluatorException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/EvaluatorException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionEvaluator.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionEvaluator.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionEvaluator.java (added)
+++ archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionEvaluator.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,62 @@
+package org.codehaus.plexus.evaluator;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * 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 java.util.List;
+
+/**
+ * ExpressionEvaluator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface ExpressionEvaluator
+{
+ String ROLE = ExpressionEvaluator.class.getName();
+
+ /**
+ * Add a source for expression resolution.
+ *
+ * @param source the source to add.
+ */
+ void addExpressionSource( ExpressionSource source );
+
+ /**
+ * Evaluate a string, and expand expressions as needed.
+ *
+ * @param str the expression
+ * @return the value of the expression
+ * @throws EvaluatorException if a problem occurs whilst evaluating
+ */
+ String expand( String str )
+ throws EvaluatorException;
+
+ /**
+ * Get the List of expression sources.
+ *
+ * @return the list of expression sources.
+ */
+ List getExpressionSourceList();
+
+ /**
+ * Remove a specific expression source.
+ *
+ * @param source the source to remove.
+ * @return true if expression source was removed.
+ */
+ boolean removeExpressionSource( ExpressionSource source );
+}
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionEvaluator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionSource.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionSource.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionSource.java (added)
+++ archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionSource.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,34 @@
+package org.codehaus.plexus.evaluator;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * 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.
+ */
+
+/**
+ * ExpressionSource
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface ExpressionSource
+{
+ /**
+ * Gets a value for a provided Expression.
+ *
+ * @param expression the expression to attempt to get a value for.
+ * @return the value for the expression, or null if no value found.
+ */
+ public String getExpressionValue( String expression );
+}
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/ExpressionSource.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/PropertiesExpressionSource.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/PropertiesExpressionSource.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/PropertiesExpressionSource.java (added)
+++ archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/PropertiesExpressionSource.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,64 @@
+package org.codehaus.plexus.evaluator.sources;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * 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.evaluator.ExpressionSource;
+
+import java.util.Properties;
+
+/**
+ * PropertiesExpressionSource
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.codehaus.plexus.evaluator.ExpressionSource"
+ * role-hint="properties"
+ */
+public class PropertiesExpressionSource
+ implements ExpressionSource
+{
+ private Properties properties;
+
+ public String getExpressionValue( String expression )
+ {
+ if ( properties == null )
+ {
+ throw new IllegalStateException( "Properties object has not been initialized." );
+ }
+
+ try
+ {
+ return properties.getProperty( expression );
+ }
+ catch ( Exception e )
+ {
+ return null;
+ }
+ }
+
+ public Properties getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperties( Properties properties )
+ {
+ this.properties = properties;
+ }
+
+}
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/PropertiesExpressionSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/PropertiesExpressionSource.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/SystemPropertyExpressionSource.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/SystemPropertyExpressionSource.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/SystemPropertyExpressionSource.java (added)
+++ archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/SystemPropertyExpressionSource.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,28 @@
+package org.codehaus.plexus.evaluator.sources;
+
+import org.codehaus.plexus.evaluator.ExpressionSource;
+
+/**
+ * SystemPropertyExpressionSource
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.codehaus.plexus.evaluator.ExpressionSource"
+ * role-hint="sysprops"
+ */
+public class SystemPropertyExpressionSource
+ implements ExpressionSource
+{
+ public String getExpressionValue( String expression )
+ {
+ try
+ {
+ return System.getProperty( expression );
+ }
+ catch ( Exception e )
+ {
+ return null;
+ }
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/SystemPropertyExpressionSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/main/java/org/codehaus/plexus/evaluator/sources/SystemPropertyExpressionSource.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/test/java/org/codehaus/plexus/evaluator/sources/DefaultExpressionEvaluatorTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/test/java/org/codehaus/plexus/evaluator/sources/DefaultExpressionEvaluatorTest.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/test/java/org/codehaus/plexus/evaluator/sources/DefaultExpressionEvaluatorTest.java (added)
+++ archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/test/java/org/codehaus/plexus/evaluator/sources/DefaultExpressionEvaluatorTest.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,208 @@
+package org.codehaus.plexus.evaluator.sources;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * 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.PlexusTestCase;
+import org.codehaus.plexus.evaluator.EvaluatorException;
+import org.codehaus.plexus.evaluator.ExpressionEvaluator;
+
+import java.util.Properties;
+
+/**
+ * DefaultExpressionEvaluatorTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class DefaultExpressionEvaluatorTest
+ extends PlexusTestCase
+{
+ private ExpressionEvaluator evaluator;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ evaluator = (ExpressionEvaluator) lookup( ExpressionEvaluator.ROLE, "default" );
+ }
+
+ public void testSimple()
+ throws EvaluatorException
+ {
+ Properties props = new Properties();
+ props.setProperty( "fruit", "apple" );
+
+ PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
+ propsSource.setProperties( props );
+ evaluator.addExpressionSource( propsSource );
+
+ String expression = "${fruit}";
+ String expected = "apple";
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ public void testSimpleStartOfLine()
+ throws EvaluatorException
+ {
+ Properties props = new Properties();
+ props.setProperty( "fruit", "apple" );
+
+ PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
+ propsSource.setProperties( props );
+ evaluator.addExpressionSource( propsSource );
+
+ String expression = "${fruit} is good for you.";
+ String expected = "apple is good for you.";
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ public void testSimpleEndOfLine()
+ throws EvaluatorException
+ {
+ Properties props = new Properties();
+ props.setProperty( "fruit", "apple" );
+
+ PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
+ propsSource.setProperties( props );
+ evaluator.addExpressionSource( propsSource );
+
+ String expression = "watch out for the worm in the ${fruit}";
+ String expected = "watch out for the worm in the apple";
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ public void testSimpleSystemProperty()
+ throws EvaluatorException
+ {
+ evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
+
+ String userHome = System.getProperty( "user.home" );
+ String expression = "My HOME directory is ${user.home}";
+ String expected = "My HOME directory is " + userHome;
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ public void testMultiExpression()
+ throws EvaluatorException
+ {
+ evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
+
+ String userName = System.getProperty( "user.name" );
+ String userHome = System.getProperty( "user.home" );
+ String expression = "${user.name}'s home directory is ${user.home}";
+ String expected = userName + "'s home directory is " + userHome;
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ /**
+ * This use case was discovered by a user of archiva.
+ * The last expression doesn't get evaluated properly.
+ *
+ * The result (with the bug) was "2.0.4${prj.ver.suf}"
+ */
+ public void testMultiExpressionVersionBug()
+ throws EvaluatorException
+ {
+ Properties props = new Properties();
+ props.setProperty( "prj.ver.maj", "2" );
+ props.setProperty( "prj.ver.min", "0" );
+ props.setProperty( "prj.ver.inc", "4" );
+ props.setProperty( "prj.ver.suf", "-SNAPSHOT" );
+
+ PropertiesExpressionSource propsSource = new PropertiesExpressionSource();
+ propsSource.setProperties( props );
+ evaluator.addExpressionSource( propsSource );
+
+ String expression = "${prj.ver.maj}.${prj.ver.min}.${prj.ver.inc}${prj.ver.suf}";
+ String expected = "2.0.4-SNAPSHOT";
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ public void testEscaping()
+ throws EvaluatorException
+ {
+ evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
+
+ String userName = System.getProperty( "user.name" );
+ String userHome = System.getProperty( "user.home" );
+ String expression = "${user.name}'s home directory is ${user.home} (fetched via $${user.home} expression)";
+ String expected = userName + "'s home directory is " + userHome + " (fetched via ${user.home} expression)";
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ public void testRecursiveSimple()
+ throws EvaluatorException
+ {
+ PropertiesExpressionSource propsource = new PropertiesExpressionSource();
+ Properties props = new Properties();
+
+ // Create intentional recursive lookup.
+ props.setProperty( "main.dir", "${target.dir}/classes" );
+ props.setProperty( "target.dir", "./target" );
+
+ propsource.setProperties( props );
+
+ evaluator.addExpressionSource( propsource );
+ evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
+
+ String expression = "My classes directory is ${main.dir}";
+ String expected = "My classes directory is ./target/classes";
+
+ String actual = evaluator.expand( expression );
+ assertEquals( expected, actual );
+ }
+
+ public void testRecursiveCycle()
+ {
+ PropertiesExpressionSource propsource = new PropertiesExpressionSource();
+ Properties props = new Properties();
+
+ // Create intentional recursive lookup.
+ props.setProperty( "main.dir", "${test.dir}/target/classes" );
+ props.setProperty( "test.dir", "${main.dir}/target/test-classes" );
+
+ propsource.setProperties( props );
+
+ evaluator.addExpressionSource( propsource );
+ evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
+
+ try
+ {
+ evaluator.expand( "My main dir is ${main.dir}" );
+ fail( "Should have thrown an EvaluatorException due to recursive cycle." );
+ }
+ catch ( EvaluatorException e )
+ {
+ // Expected path.
+ }
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/test/java/org/codehaus/plexus/evaluator/sources/DefaultExpressionEvaluatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-expression-evaluator/src/test/java/org/codehaus/plexus/evaluator/sources/DefaultExpressionEvaluatorTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-jabber/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-jabber/pom.xml?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-jabber/pom.xml (added)
+++ archiva/redback/redback-components/trunk/plexus-jabber/pom.xml Fri Apr 6 09:33:40 2012
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.codehaus.redback.components</groupId>
+ <artifactId>redback-components</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ <relativePath>../redback-components-parent/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-jabber</artifactId>
+ <name>Plexus Jabber Client Component</name>
+ <version>1.0-SNAPSHOT</version>
+
+ <url>http://redback.codehaus.org/components/${project.artifactId}</url>
+
+ <distributionManagement>
+ <site>
+ <id>codehaus.org</id>
+ <url>dav:https://dav.codehaus.org/redback/components/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+ <scm>
+ <connection>scm:svn:https://svn.codehaus.org/redback/components/trunk/plexus-jabber</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/redback/components/trunk/plexus-jabber</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/redback/components/trunk/plexus-jabber</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smackx</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smack</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+ </dependencies>
+</project>
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/DefaultJabberClient.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/DefaultJabberClient.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/DefaultJabberClient.java (added)
+++ archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/DefaultJabberClient.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,308 @@
+package org.codehaus.plexus.jabber;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.jivesoftware.smack.SSLXMPPConnection;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class DefaultJabberClient
+ extends AbstractLogEnabled
+ implements JabberClient
+{
+ private static final String RESOURCE_NAME = "plexus-jabber";
+
+ private String host;
+
+ private int port = -1;
+
+ private String user;
+
+ private String password;
+
+ private String imDomainName;
+
+ private boolean isSslConnection;
+
+ private XMPPConnection conn;
+
+ /**
+ * @see org.codehaus.plexus.jabber.JabberClient#connect()
+ */
+ public void connect()
+ throws JabberClientException
+ {
+ try
+ {
+ if ( !isSslConnection )
+ {
+ conn = new XMPPConnection( getHost(), getPort(), getImDomainName() );
+ }
+ else
+ {
+ conn = new SSLXMPPConnection( getHost(), getPort(), getImDomainName() );
+ }
+ }
+ catch ( XMPPException e )
+ {
+ throw new JabberClientException( "Can't connect to " + getHost() + ":" + getPort(), e );
+ }
+ }
+
+ /**
+ * @see org.codehaus.plexus.jabber.JabberClient#disconnect()
+ */
+ public void disconnect()
+ throws JabberClientException
+ {
+ if ( conn != null )
+ {
+ if ( conn.isConnected() )
+ {
+ conn.close();
+ }
+ conn = null;
+ }
+ }
+
+ private XMPPConnection getConnection()
+ throws JabberClientException
+ {
+ if ( conn == null || !conn.isConnected() )
+ {
+ connect();
+ }
+
+ return conn;
+ }
+
+ /**
+ * @see org.codehaus.plexus.jabber.JabberClient#logon()
+ */
+ public void logon()
+ throws JabberClientException
+ {
+ XMPPConnection conn = getConnection();
+
+ if ( user != null )
+ {
+ try
+ {
+ conn.login( user, password, RESOURCE_NAME );
+
+ if ( !conn.isAuthenticated() )
+ {
+ throw new JabberClientException( "Authentication failed." );
+ }
+ }
+ catch ( XMPPException e )
+ {
+ if ( e.getXMPPError() != null && e.getXMPPError().getCode() == 401 )
+ {
+ getLogger().info( "User " + user + " doesn't exist. Trying to create it." );
+
+ try
+ {
+ conn.getAccountManager().createAccount( user, password );
+
+ conn.login( user, password, RESOURCE_NAME );
+ }
+ catch ( XMPPException createException )
+ {
+ throw new JabberClientException( "Can't create an account for user " + user + " on "
+ + getHost(), createException );
+ }
+ }
+ else
+ {
+ throw new JabberClientException( "Can't connect to " + getHost() + " with user " + user, e );
+ }
+ }
+ }
+ else
+ {
+ try
+ {
+ conn.loginAnonymously();
+ }
+ catch ( XMPPException e )
+ {
+ throw new JabberClientException( "Can't open an anonymous session on " + getHost(), e );
+ }
+ }
+ }
+
+ /**
+ * @see org.codehaus.plexus.jabber.JabberClient#logoff()
+ */
+ public void logoff()
+ throws JabberClientException
+ {
+ disconnect();
+ }
+
+ /**
+ * @see org.codehaus.plexus.jabber.JabberClient#sendMessageToUser(java.lang.String, java.lang.String)
+ */
+ public void sendMessageToUser( String recipientUser, String message )
+ throws JabberClientException
+ {
+ XMPPConnection conn = getConnection();
+
+ try
+ {
+ conn.createChat( recipientUser ).sendMessage( message );
+ }
+ catch ( XMPPException e )
+ {
+ throw new JabberClientException( "Can't send a message to " + recipientUser + " user", e );
+ }
+
+ // TODO: replace with test from smack API to see if message was delivered
+ // little sleep to be sure that message was sent
+ try
+ {
+ Thread.sleep( 1000 );
+ }
+ catch( InterruptedException e )
+ {
+ }
+ }
+
+ /**
+ * @see org.codehaus.plexus.jabber.JabberClient#sendMessageToGroup(java.lang.String, java.lang.String)
+ */
+ public void sendMessageToGroup( String recipientGroup, String message )
+ throws JabberClientException
+ {
+ XMPPConnection conn = getConnection();
+
+ try
+ {
+ conn.createGroupChat( recipientGroup ).sendMessage( message );
+ }
+ catch ( XMPPException e )
+ {
+ throw new JabberClientException( "Can't send a message to " + recipientGroup + " group", e );
+ }
+
+ // TODO: replace with test from smack API to see if message was delivered
+ // little sleep to be sure that message was sent
+ try
+ {
+ Thread.sleep( 1000 );
+ }
+ catch( InterruptedException e )
+ {
+ }
+ }
+
+ /**
+ * @return Returns the host
+ */
+ public String getHost()
+ {
+ return host;
+ }
+
+ /**
+ * @param host The host to set.
+ */
+ public void setHost( String host )
+ {
+ this.host = host;
+ }
+
+ /**
+ * @return Returns the port
+ */
+ public int getPort()
+ {
+ if ( port <= 0 )
+ {
+ return port;
+ }
+ else if ( isSslConnection )
+ {
+ return 5223;
+ }
+ else
+ {
+ return 5222;
+ }
+ }
+
+ /**
+ * @param port The port to set.
+ */
+ public void setPort( int port )
+ {
+ this.port = port;
+ }
+
+ /**
+ * @return Returns the isSslConnection.
+ */
+ public boolean isSslConnection()
+ {
+ return isSslConnection;
+ }
+
+ /**
+ * @param isSslConnection The isSslConnection to set.
+ */
+ public void setSslConnection( boolean isSslConnection )
+ {
+ this.isSslConnection = isSslConnection;
+ }
+
+ /**
+ * @return Returns the IM domain name.
+ */
+ public String getImDomainName()
+ {
+ if ( imDomainName == null )
+ {
+ return getHost();
+ }
+ else
+ {
+ return imDomainName;
+ }
+ }
+
+ /**
+ * @param host The IM domain name to set.
+ */
+ public void setImDomainName( String imDomainName )
+ {
+ this.imDomainName = imDomainName;
+ }
+
+ /**
+ * @return Returns the user.
+ */
+ public String getUser()
+ {
+ return user;
+ }
+
+ /**
+ * @param user The user to set.
+ */
+ public void setUser( String user )
+ {
+ this.user = user;
+ }
+
+ /**
+ * @param password The password to set.
+ */
+ public void setPassword( String password )
+ {
+ this.password = password;
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/DefaultJabberClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/DefaultJabberClient.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClient.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClient.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClient.java (added)
+++ archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClient.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,50 @@
+package org.codehaus.plexus.jabber;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public interface JabberClient
+{
+ static final String ROLE = JabberClient.class.getName();
+
+ void connect()
+ throws JabberClientException;
+
+ void disconnect()
+ throws JabberClientException;
+
+ void logon()
+ throws JabberClientException;
+
+ void logoff()
+ throws JabberClientException;
+
+ void sendMessageToUser( String recipient, String message )
+ throws JabberClientException;
+
+ void sendMessageToGroup( String recipient, String message )
+ throws JabberClientException;
+
+ String getHost();
+
+ void setHost( String host );
+
+ int getPort();
+
+ void setPort( int port );
+
+ boolean isSslConnection();
+
+ void setSslConnection( boolean isSslConnection );
+
+ String getUser();
+
+ void setUser( String user );
+
+ void setPassword( String password );
+
+ String getImDomainName();
+
+ void setImDomainName( String imDomainName );
+}
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClient.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClientException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClientException.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClientException.java (added)
+++ archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClientException.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,19 @@
+package org.codehaus.plexus.jabber;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class JabberClientException
+ extends Exception
+{
+ public JabberClientException( String message )
+ {
+ super( message );
+ }
+
+ public JabberClientException( String message, Throwable throwable )
+ {
+ super( message, throwable );
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClientException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-jabber/src/main/java/org/codehaus/plexus/jabber/JabberClientException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-msn/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-msn/pom.xml?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-msn/pom.xml (added)
+++ archiva/redback/redback-components/trunk/plexus-msn/pom.xml Fri Apr 6 09:33:40 2012
@@ -0,0 +1,60 @@
+<project>
+ <parent>
+ <groupId>org.codehaus.redback.components</groupId>
+ <artifactId>redback-components</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ <relativePath>../redback-components-parent/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-msn</artifactId>
+ <name>Plexus MSN Client Component</name>
+ <version>1.0-SNAPSHOT</version>
+
+ <url>http://redback.codehaus.org/components/${project.artifactId}</url>
+
+ <distributionManagement>
+ <site>
+ <id>codehaus.org</id>
+ <url>dav:https://dav.codehaus.org/redback/components/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+ <scm>
+ <connection>scm:svn:https://svn.codehaus.org/redback/components/trunk/plexus-msn</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/redback/components/trunk/plexus-msn</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/redback/components/trunk/plexus-msn</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jmsn</groupId>
+ <artifactId>msnmlib</artifactId>
+ <version>1.4-20050613</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <version>1.3.4</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: archiva/redback/redback-components/trunk/plexus-msn/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-msn/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/DefaultMsnClient.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/DefaultMsnClient.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/DefaultMsnClient.java (added)
+++ archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/DefaultMsnClient.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,195 @@
+package org.codehaus.plexus.msn;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.logging.Logger;
+
+import java.io.IOException;
+
+import rath.msnm.MSNMessenger;
+import rath.msnm.SwitchboardSession;
+import rath.msnm.UserStatus;
+import rath.msnm.entity.MsnFriend;
+import rath.msnm.event.MsnAdapter;
+import rath.msnm.msg.MimeMessage;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class DefaultMsnClient
+ extends AbstractLogEnabled
+ implements MsnClient
+{
+ private String login;
+
+ private String password;
+
+ private MSNMessenger msn;
+
+ private String initialStatus = UserStatus.ONLINE;
+
+ public void login()
+ throws MsnException
+ {
+ msn = new MSNMessenger( login, password );
+
+ msn.setInitialStatus( initialStatus );
+
+ LoginAdapter adapter = new LoginAdapter( msn, getLogger() );
+
+ msn.addMsnListener( adapter );
+
+ msn.login();
+
+ getLogger().info( "Connection. Waiting for the response...." );
+
+ while ( adapter.getStatus() == LoginAdapter.NOT_INITIALIZED )
+ {
+ try
+ {
+ Thread.sleep( 1000 );
+ }
+ catch ( InterruptedException e )
+ {
+ }
+ }
+
+ if ( adapter.getStatus() == LoginAdapter.LOGIN_ERROR )
+ {
+ throw new MsnException( "Login failed : " + adapter.getError() );
+ }
+ }
+
+ public void logout()
+ throws MsnException
+ {
+ if ( msn != null )
+ {
+ msn.logout();
+ }
+ }
+
+ public void sendMessage( String recipient, String message )
+ throws MsnException
+ {
+ SwitchboardSession ss = null;
+
+ try
+ {
+ ss = msn.doCallWait( recipient );
+ }
+ catch ( InterruptedException e )
+ {
+ }
+ catch ( IOException e )
+ {
+ }
+
+ try
+ {
+ while ( ss == null )
+ {
+ ss = msn.doCallWait( recipient );
+ }
+ }
+ catch ( InterruptedException e )
+ {
+ System.out.println( "session docallwait InterruptedException:" );
+ e.printStackTrace();
+ }
+ catch ( IOException e )
+ {
+ System.out.println( "session docallwait:" );
+ e.printStackTrace();
+ }
+
+ if ( ss == null )
+ {
+ throw new MsnException( "Can't create a SwitchboardSession." );
+ }
+
+ MimeMessage msg = new MimeMessage();
+
+ msg.setKind( MimeMessage.KIND_MESSAGE );
+
+ msg.setMessage( message );
+
+ try
+ {
+ ss.sendInstantMessage( msg );
+ }
+ catch ( IOException e )
+ {
+ throw new MsnException( "The message isn't send.", e );
+ }
+ }
+
+ public void setLogin( String login )
+ {
+ this.login = login;
+ }
+
+ public String getLogin()
+ {
+ return login;
+ }
+
+ public void setPassword( String password )
+ {
+ this.password = password;
+ }
+}
+
+class LoginAdapter
+ extends MsnAdapter
+{
+ public static final int NOT_INITIALIZED = -1;
+
+ public static final int LOGIN_OK = 0;
+
+ public static final int LOGIN_ERROR = 1;
+
+ private int status = NOT_INITIALIZED;
+
+ private String error;
+
+ private MSNMessenger messenger;
+
+ private Logger logger;
+
+ public LoginAdapter( MSNMessenger messenger, Logger logger )
+ {
+ this.messenger = messenger;
+
+ this.logger = logger;
+ }
+
+ public void loginComplete( MsnFriend own )
+ {
+ if ( own.getLoginName().equals( messenger.getLoginName() ) )
+ {
+ status = LOGIN_OK;
+
+ logger.info( "Connected." );
+ }
+ }
+
+ public void loginError( String header )
+ {
+ logger.error( header );
+
+ status = LOGIN_ERROR;
+
+ error = header;
+ }
+
+ public int getStatus()
+ {
+ return status;
+ }
+
+ public String getError()
+ {
+ return error;
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/DefaultMsnClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/DefaultMsnClient.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnClient.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnClient.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnClient.java (added)
+++ archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnClient.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,25 @@
+package org.codehaus.plexus.msn;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public interface MsnClient
+{
+ String ROLE = MsnClient.class.getName();
+
+ void login()
+ throws MsnException;
+
+ void logout()
+ throws MsnException;
+
+ void sendMessage( String receiver, String message )
+ throws MsnException;
+
+ void setLogin( String login );
+
+ String getLogin();
+
+ void setPassword( String password );
+}
Propchange: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnClient.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnException.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnException.java (added)
+++ archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnException.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,19 @@
+package org.codehaus.plexus.msn;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class MsnException
+ extends Exception
+{
+ public MsnException( String message )
+ {
+ super( message );
+ }
+
+ public MsnException( String message, Throwable throwable )
+ {
+ super( message, throwable );
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-msn/src/main/java/org/codehaus/plexus/msn/MsnException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/pom.xml?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/pom.xml (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/pom.xml Fri Apr 6 09:33:40 2012
@@ -0,0 +1,252 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback.components</groupId>
+ <artifactId>redback-components</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ <relativePath>../redback-components-parent/pom.xml</relativePath>
+ </parent>
+ <artifactId>plexus-spring</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ <name>Plexus to Spring Adapter</name>
+ <description>Bridge utility to use plexus components in a SpringFramework context.</description>
+ <properties>
+ <mavenVersion>2.0.8</mavenVersion>
+ </properties>
+
+ <url>http://redback.codehaus.org/components/${project.artifactId}</url>
+
+ <distributionManagement>
+ <site>
+ <id>codehaus.org</id>
+ <url>dav:https://dav.codehaus.org/redback/components/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+ <scm>
+ <connection>scm:svn:https://svn.codehaus.org/redback/components/trunk/plexus-spring</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/redback/components/trunk/plexus-spring</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/redback/components/trunk/plexus-spring</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${springVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${springVersion}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${springVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ <version>1.0-alpha-22</version>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.3</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.5.6</version>
+ </dependency>
+
+ <!-- for struts2 integration -->
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-spring-plugin</artifactId>
+ <version>2.2.3.1</version>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.struts.xwork</groupId>
+ <artifactId>xwork-core</artifactId>
+ <version>2.2.3.1</version>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ <version>${slf4jVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <scope>test</scope>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-command-line</artifactId>
+ <version>1.0-alpha-2</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback.components.registry</groupId>
+ <artifactId>spring-registry-commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>ant</groupId>
+ <artifactId>ant-optional</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback.components.registry</groupId>
+ <artifactId>spring-registry-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <developers>
+ <developer>
+ <email>nicolas@apache.org</email>
+ <name>Nicolas De Loof</name>
+ </developer>
+ <developer>
+ <email>olamy@apache.org</email>
+ <name>Olivier Lamy</name>
+ </developer>
+ </developers>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: archiva/redback/redback-components/trunk/plexus-spring/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/component/configurator/ComponentConfigurationException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/component/configurator/ComponentConfigurationException.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/component/configurator/ComponentConfigurationException.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/component/configurator/ComponentConfigurationException.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,59 @@
+package org.codehaus.plexus.component.configurator;
+
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+/**
+ *
+ *
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ *
+ * @version $Id$
+ */
+public class ComponentConfigurationException
+ extends Exception
+{
+ private PlexusConfiguration failedConfiguration;
+
+ public ComponentConfigurationException( String message )
+ {
+ super( message );
+ }
+
+ public ComponentConfigurationException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public ComponentConfigurationException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public ComponentConfigurationException( PlexusConfiguration failedConfiguration, String message )
+ {
+ super( message );
+ this.failedConfiguration = failedConfiguration;
+ }
+
+ public ComponentConfigurationException( PlexusConfiguration failedConfiguration, String message, Throwable cause )
+ {
+ super( message, cause );
+ this.failedConfiguration = failedConfiguration;
+ }
+
+ public ComponentConfigurationException( PlexusConfiguration failedConfiguration, Throwable cause )
+ {
+ super( cause );
+ this.failedConfiguration = failedConfiguration;
+ }
+
+ public void setFailedConfiguration( PlexusConfiguration failedConfiguration )
+ {
+ this.failedConfiguration = failedConfiguration;
+ }
+
+ public PlexusConfiguration getFailedConfiguration()
+ {
+ return failedConfiguration;
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/component/configurator/ComponentConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/component/configurator/ComponentConfigurationException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/configuration/xml/XmlPlexusConfiguration.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/configuration/xml/XmlPlexusConfiguration.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/configuration/xml/XmlPlexusConfiguration.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/configuration/xml/XmlPlexusConfiguration.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,307 @@
+package org.codehaus.plexus.configuration.xml;
+
+/*
+ * 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.configuration.PlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+/**
+ * @version $Id$
+ */
+public class XmlPlexusConfiguration
+ implements PlexusConfiguration
+{
+ private Xpp3Dom dom;
+
+ public XmlPlexusConfiguration( String name )
+ {
+ this.dom = new Xpp3Dom( name );
+ }
+
+ public XmlPlexusConfiguration( Xpp3Dom dom )
+ {
+ this.dom = dom;
+ }
+
+ public Xpp3Dom getXpp3Dom()
+ {
+ return dom;
+ }
+
+ // ----------------------------------------------------------------------
+ // Name handling
+ // ----------------------------------------------------------------------
+
+ public String getName()
+ {
+ return dom.getName();
+ }
+
+ // ----------------------------------------------------------------------
+ // Value handling
+ // ----------------------------------------------------------------------
+
+ public String getValue()
+ {
+ return dom.getValue();
+ }
+
+ public String getValue( String defaultValue )
+ {
+ String value = dom.getValue();
+
+ if ( value == null )
+ {
+ value = defaultValue;
+ }
+
+ return value;
+ }
+
+ public void setValue( String value )
+ {
+ dom.setValue( value );
+ }
+
+ // ----------------------------------------------------------------------
+ // Attribute handling
+ // ----------------------------------------------------------------------
+
+ public void setAttribute( String name, String value )
+ {
+ dom.setAttribute( name, value );
+ }
+
+ public String getAttribute( String name, String defaultValue )
+ {
+ String attribute = getAttribute( name );
+
+ if ( attribute == null )
+ {
+ attribute = defaultValue;
+ }
+
+ return attribute;
+ }
+
+ public String getAttribute( String name )
+ {
+ return dom.getAttribute( name );
+ }
+
+ public String[] getAttributeNames()
+ {
+ return dom.getAttributeNames();
+ }
+
+ // ----------------------------------------------------------------------
+ // Child handling
+ // ----------------------------------------------------------------------
+
+ // The behaviour of getChild* that we adopted from avalon is that if the child
+ // does not exist then we create the child.
+
+ public PlexusConfiguration getChild( String name )
+ {
+ return getChild( name, true );
+ }
+
+ public PlexusConfiguration getChild( int i )
+ {
+ return new XmlPlexusConfiguration( dom.getChild( i ) );
+ }
+
+ public PlexusConfiguration getChild( String name, boolean createChild )
+ {
+ Xpp3Dom child = dom.getChild( name );
+
+ if ( child == null )
+ {
+ if ( createChild )
+ {
+ child = new Xpp3Dom( name );
+
+ dom.addChild( child );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ return new XmlPlexusConfiguration( child );
+ }
+
+ public PlexusConfiguration[] getChildren()
+ {
+ Xpp3Dom[] doms = dom.getChildren();
+
+ PlexusConfiguration[] children = new XmlPlexusConfiguration[doms.length];
+
+ for ( int i = 0; i < children.length; i++ )
+ {
+ children[i] = new XmlPlexusConfiguration( doms[i] );
+ }
+
+ return children;
+ }
+
+ public PlexusConfiguration[] getChildren( String name )
+ {
+ Xpp3Dom[] doms = dom.getChildren( name );
+
+ PlexusConfiguration[] children = new XmlPlexusConfiguration[doms.length];
+
+ for ( int i = 0; i < children.length; i++ )
+ {
+ children[i] = new XmlPlexusConfiguration( doms[i] );
+ }
+
+ return children;
+ }
+
+ public void addChild( PlexusConfiguration configuration )
+ {
+ dom.addChild( ( (XmlPlexusConfiguration) configuration ).getXpp3Dom() );
+ }
+
+ public void addAllChildren( PlexusConfiguration other )
+ {
+ PlexusConfiguration[] children = other.getChildren();
+
+ for ( int i = 0; i < children.length; i++ )
+ {
+ addChild( children[i] );
+ }
+ }
+
+ public int getChildCount()
+ {
+ return dom.getChildCount();
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ int depth = 0;
+
+ display( this, sb, depth );
+
+ return sb.toString();
+ }
+
+ private void display( PlexusConfiguration c, StringBuffer sb, int depth )
+ {
+ int count = c.getChildCount();
+
+ if (count == 0)
+ {
+ displayTag( c, sb, depth );
+ }
+ else
+ {
+ sb.append( indent( depth ) ).
+ append( '<' ).
+ append( c.getName() );
+
+ attributes( c, sb );
+
+ sb.append( '>' ).
+ append( '\n' );
+
+ for ( int i = 0; i < count; i++ )
+ {
+ PlexusConfiguration child = c.getChild( i );
+
+ display( child, sb, depth + 1 );
+ }
+
+ sb.append( indent( depth ) ).
+ append( '<' ).
+ append( '/' ).
+ append( c.getName() ).
+ append( '>' ).
+ append( '\n' );
+ }
+ }
+
+ private void displayTag( PlexusConfiguration c, StringBuffer sb, int depth )
+ {
+ String value = c.getValue( null );
+
+ if ( value != null )
+ {
+ sb.append( indent( depth ) ).
+ append( '<' ).
+ append( c.getName() );
+
+ attributes( c, sb );
+
+ sb.append( '>' ).
+ append( c.getValue( null ) ).
+ append( '<' ).
+ append( '/' ).
+ append( c.getName() ).
+ append( '>' ).
+ append( '\n' );
+ }
+ else
+ {
+ sb.append( indent( depth ) ).
+ append( '<' ).
+ append( c.getName() );
+
+ attributes( c, sb );
+
+ sb.append( '/' ).
+ append( '>' ).
+ append( "\n" );
+ }
+ }
+
+ private void attributes( PlexusConfiguration c, StringBuffer sb )
+ {
+ String[] names = c.getAttributeNames();
+
+ for ( int i = 0; i < names.length; i++ )
+ {
+ sb.append( ' ' ).
+ append( names[i] ).
+ append( '=' ).
+ append( '"' ).
+ append( c.getAttribute( names[i], null ) ).
+ append( '"' );
+ }
+ }
+
+ private String indent( int depth )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ for ( int i = 0; i < depth; i++ )
+ {
+ sb.append( ' ' );
+ }
+
+ return sb.toString();
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/configuration/xml/XmlPlexusConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/configuration/xml/XmlPlexusConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/BaseLoggerManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/BaseLoggerManager.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/BaseLoggerManager.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/BaseLoggerManager.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,198 @@
+package org.codehaus.plexus.logging;
+
+/*
+ * 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.personality.plexus.lifecycle.phase.Initializable;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Base class for all LoggerManagers which use cache of Loggers.
+ *
+ * @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
+ * @version $Id$
+ */
+public abstract class BaseLoggerManager
+ extends AbstractLoggerManager implements Initializable
+{
+ /** */
+ private Map loggerCache = new HashMap();
+
+ private String threshold = "info";
+
+ private int currentThreshold;
+
+ public void initialize()
+ {
+ currentThreshold = parseThreshold( threshold );
+
+ if ( currentThreshold == -1 )
+ {
+ currentThreshold = Logger.LEVEL_DEBUG;
+ }
+ }
+
+ protected int parseThreshold( String text )
+ {
+ text = text.trim().toLowerCase();
+
+ if ( text.equals( "debug" ) )
+ {
+ return Logger.LEVEL_DEBUG;
+ }
+ else if ( text.equals( "info" ) )
+ {
+ return Logger.LEVEL_INFO;
+ }
+ else if ( text.equals( "warn" ) )
+ {
+ return Logger.LEVEL_WARN;
+ }
+ else if ( text.equals( "error" ) )
+ {
+ return Logger.LEVEL_ERROR;
+ }
+ else if ( text.equals( "fatal" ) )
+ {
+ return Logger.LEVEL_FATAL;
+ }
+
+ return -1;
+ }
+
+ /**
+ * Sets the threshold for all new loggers. It will NOT affect the existing loggers.
+ * <p/>
+ * This is usually only set once while the logger manager is configured.
+ *
+ * @param currentThreshold The new threshold.
+ */
+ public void setThreshold( int currentThreshold )
+ {
+ this.currentThreshold = currentThreshold;
+ }
+
+ /**
+ * Sets the threshold for all new loggers. It will NOT affect the existing loggers.
+ * <p/>
+ * This is usually only set once while the logger manager is configured.
+ *
+ * @param currentThreshold The new threshold.
+ */
+ public void setThresholds( int currentThreshold )
+ {
+ this.currentThreshold = currentThreshold;
+
+ for ( Iterator logs = loggerCache.values().iterator(); logs.hasNext(); )
+ {
+ Logger logger = (Logger) logs.next();
+ logger.setThreshold( currentThreshold );
+ }
+ }
+
+ /**
+ * Returns the current threshold for all new loggers.
+ *
+ * @return Returns the current threshold for all new loggers.
+ */
+ public int getThreshold()
+ {
+ return currentThreshold;
+ }
+
+ public void setThreshold( String role, String roleHint, int threshold )
+ {
+ AbstractLogger logger;
+
+ String key = toMapKey( role, roleHint );
+
+ logger = ( AbstractLogger ) loggerCache.get( key );
+
+ if ( logger == null )
+ {
+ return; // nothing to do
+ }
+
+ logger.setThreshold( threshold );
+ }
+
+ public int getThreshold( String role, String roleHint )
+ {
+ AbstractLogger logger;
+
+ String key = toMapKey( role, roleHint );
+
+ logger = ( AbstractLogger ) loggerCache.get( key );
+
+ if ( logger == null )
+ {
+ return Logger.LEVEL_DEBUG; // does not return null because that could create a NPE
+ }
+
+ return logger.getThreshold();
+ }
+
+ public Logger getLoggerForComponent( String role, String roleHint )
+ {
+ Logger logger;
+
+ String key = toMapKey( role, roleHint );
+
+ logger = ( Logger ) loggerCache.get( key );
+
+ if ( logger != null )
+ {
+ return logger;
+ }
+
+ logger = createLogger( key );
+
+ loggerCache.put( key, logger );
+
+ return logger;
+ }
+
+ protected abstract Logger createLogger( String key );
+
+ public void returnComponentLogger( String role, String roleHint )
+ {
+ Object obj;
+
+ String key = toMapKey( role, roleHint );
+
+ obj = loggerCache.remove( key );
+
+ if ( obj == null )
+ {
+ // TODO: use a logger!
+ System.err.println( "There was no such logger '" + key + "' " + hashCode() + "." );
+ }
+ }
+
+ public int getActiveLoggerCount()
+ {
+ return loggerCache.size();
+ }
+
+ public String getThresholdAsString()
+ {
+ return threshold;
+ }
+
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/BaseLoggerManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/BaseLoggerManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLogger.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLogger.java?rev=1310262&view=auto
==============================================================================
--- archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLogger.java (added)
+++ archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLogger.java Fri Apr 6 09:33:40 2012
@@ -0,0 +1,112 @@
+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.AbstractLogger;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * Logger sending everything to the standard output streams.
+ * This is mainly for the cases when you have a utility that
+ * does not have a logger to supply.
+ *
+ * @author <a href="mailto:dev@avalon.codehaus.org">Avalon Development Team</a>
+ * @version $Id$
+ */
+public final class ConsoleLogger
+ extends AbstractLogger
+{
+ public ConsoleLogger( int threshold, String name )
+ {
+ super( threshold, name );
+ }
+
+ public void debug( String message, Throwable throwable )
+ {
+ if ( isDebugEnabled() )
+ {
+ System.out.print( "[DEBUG] " );
+ System.out.println( message );
+
+ if ( null != throwable )
+ {
+ throwable.printStackTrace( System.out );
+ }
+ }
+ }
+
+ public void info( String message, Throwable throwable )
+ {
+ if ( isInfoEnabled() )
+ {
+ System.out.print( "[INFO] " );
+ System.out.println( message );
+
+ if ( null != throwable )
+ {
+ throwable.printStackTrace( System.out );
+ }
+ }
+ }
+
+ public void warn( String message, Throwable throwable )
+ {
+ if ( isWarnEnabled() )
+ {
+ System.out.print( "[WARNING] " );
+ System.out.println( message );
+
+ if ( null != throwable )
+ {
+ throwable.printStackTrace( System.out );
+ }
+ }
+ }
+
+ public void error( String message, Throwable throwable )
+ {
+ if ( isErrorEnabled() )
+ {
+ System.out.print( "[ERROR] " );
+ System.out.println( message );
+
+ if ( null != throwable )
+ {
+ throwable.printStackTrace( System.out );
+ }
+ }
+ }
+
+ public void fatalError( String message, Throwable throwable )
+ {
+ if ( isFatalErrorEnabled() )
+ {
+ System.out.print( "[FATAL ERROR] " );
+ System.out.println( message );
+
+ if ( null != throwable )
+ {
+ throwable.printStackTrace( System.out );
+ }
+ }
+ }
+
+ public Logger getChildLogger( String name )
+ {
+ return this;
+ }
+}
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLogger.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-components/trunk/plexus-spring/src/main/java/org/codehaus/plexus/logging/console/ConsoleLogger.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision