diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
index 1156d8c53..ca14b760e 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
@@ -101,6 +101,7 @@ public class DefaultEmbeddor
projectType = FileUtil.getExtension( location );
}
+ // TODO - reuse the project builders, or dispose them
final ProjectBuilder builder = getProjectBuilder( projectType, parameters );
return builder.build( location );
}
@@ -136,6 +137,8 @@ public class DefaultEmbeddor
// to the workspace
parameters.setParameter( MYRMIDON_HOME, m_parameters.getParameter( MYRMIDON_HOME ) );
setupObject( workspace, m_workspaceServiceManager, parameters );
+
+ // TODO - should keep track of workspaces, to dispose them later
return workspace;
}
@@ -145,7 +148,7 @@ public class DefaultEmbeddor
* @param name The shorthand name of the listener.
* @return the listener.
*/
- public ProjectListener createListener( String name )
+ public ProjectListener createListener( final String name )
throws Exception
{
final TypeFactory factory = m_typeManager.getFactory( ProjectListener.ROLE );
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/ClassicPropertyResolver.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/ClassicPropertyResolver.java
index 3ab7ea443..0bf4592f6 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/ClassicPropertyResolver.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/ClassicPropertyResolver.java
@@ -8,7 +8,8 @@
package org.apache.myrmidon.components.property;
import org.apache.myrmidon.interfaces.property.PropertyResolver;
-import org.apache.myrmidon.api.TaskContext;
+import org.apache.myrmidon.interfaces.property.PropertyStore;
+import org.apache.myrmidon.api.TaskException;
/**
* A {@link PropertyResolver} implementation which resolves properties
@@ -28,19 +29,16 @@ public class ClassicPropertyResolver
* If there is no such value, returns the original property reference.
*
* @param propertyName the name of the property to retrieve
- * @param context the set of known properties
+ * @param properties the set of known properties
*/
protected Object getPropertyValue( final String propertyName,
- final TaskContext context )
+ final PropertyStore properties )
+ throws TaskException
{
- Object propertyValue = context.getProperty( propertyName );
- if ( propertyValue == null )
+ if( ! properties.isPropertySet( propertyName ) )
{
return "${" + propertyName + "}";
}
- else
- {
- return propertyValue;
- }
+ return properties.getProperty( propertyName );
}
}
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/DefaultPropertyResolver.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/DefaultPropertyResolver.java
index e165203a9..74a7a6ad9 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/DefaultPropertyResolver.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/DefaultPropertyResolver.java
@@ -14,9 +14,9 @@ import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.property.PropertyResolver;
+import org.apache.myrmidon.interfaces.property.PropertyStore;
/**
* Base class for PropertyResolver implementations.
@@ -51,12 +51,12 @@ public class DefaultPropertyResolver
* toString()
called on the property value.
*
* @param content the property to resolve
- * @param context the context in which to resolve property
+ * @param properties the context in which to resolve property
* @return the reolved property
* @exception TaskException if an error occurs
*/
public Object resolveProperties( final String content,
- final TaskContext context )
+ final PropertyStore properties )
throws TaskException
{
int start = findNextProperty( content, 0 );
@@ -72,7 +72,7 @@ public class DefaultPropertyResolver
if( 0 == start && end == ( length - 1 ) )
{
return getPropertyValue( content.substring( start + 2, end ),
- context );
+ properties );
}
final StringBuffer sb = new StringBuffer( length * 2 );
@@ -82,7 +82,7 @@ public class DefaultPropertyResolver
{
final String propertyValue =
getPropertyStringValue( content.substring( start + 2, end ),
- context );
+ properties );
sb.append( content.substring( lastPlace, start ) );
sb.append( propertyValue );
@@ -108,12 +108,12 @@ public class DefaultPropertyResolver
* substitutions based on specified context.
*
* @param content the property to resolve
- * @param context the context in which to resolve property
+ * @param properties the context in which to resolve property
* @return the reolved property
* @exception TaskException if an error occurs
*/
private Object recursiveResolveProperty( final String content,
- final TaskContext context )
+ final PropertyStore properties )
throws TaskException
{
int start = findNextProperty( content, 0 );
@@ -129,8 +129,8 @@ public class DefaultPropertyResolver
if( 0 == start && end == ( length - 1 ) )
{
final String propertyName = content.substring( start + 2, end );
- final Object key = recursiveResolveProperty( propertyName, context );
- return getPropertyValue( key.toString(), context );
+ final Object key = recursiveResolveProperty( propertyName, properties );
+ return getPropertyValue( key.toString(), properties );
}
final StringBuffer sb = new StringBuffer( length * 2 );
@@ -140,8 +140,8 @@ public class DefaultPropertyResolver
while( true )
{
final String propertyName = content.substring( start + 2, end );
- final Object key = recursiveResolveProperty( propertyName, context );
- final String value = getPropertyStringValue( key.toString(), context );
+ final Object key = recursiveResolveProperty( propertyName, properties );
+ final String value = getPropertyStringValue( key.toString(), properties );
sb.append( content.substring( lastPlace, start ) );
sb.append( value );
@@ -246,17 +246,17 @@ public class DefaultPropertyResolver
* Returns a property's value, converted to a String.
*/
private String getPropertyStringValue( final String propertyName,
- final TaskContext context )
+ final PropertyStore properties )
throws TaskException
{
- final Object value = getPropertyValue( propertyName, context );
+ final Object value = getPropertyValue( propertyName, properties );
if( value instanceof String )
{
return (String)value;
}
try
{
- return (String)m_converter.convert( String.class, value, context );
+ return (String)m_converter.convert( String.class, value, properties );
}
catch( final ConverterException e )
{
@@ -268,24 +268,15 @@ public class DefaultPropertyResolver
* Retrieve a value from the specified context using the specified key.
*
* @param propertyName the key of value in context
- * @param context the set of known properties
+ * @param properties the set of known properties
* @return the object retrieved from context
* @exception TaskException if the property is undefined
*/
protected Object getPropertyValue( final String propertyName,
- final TaskContext context )
+ final PropertyStore properties )
throws TaskException
{
- Object propertyValue = context.getProperty( propertyName );
- if ( propertyValue == null )
- {
- final String message = REZ.getString( "prop.missing-value.error", propertyName );
- throw new TaskException( message );
- }
- else
- {
- return propertyValue;
- }
+ return properties.getProperty( propertyName );
}
}
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/DefaultPropertyStore.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/DefaultPropertyStore.java
index b512c9f72..b9cc8804b 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/DefaultPropertyStore.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/DefaultPropertyStore.java
@@ -17,7 +17,7 @@ import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.model.DefaultNameValidator;
import org.apache.myrmidon.interfaces.model.NameValidator;
-import org.apache.myrmidon.interfaces.store.PropertyStore;
+import org.apache.myrmidon.interfaces.property.PropertyStore;
/**
* This is the Default implementation of PropertyStore. It follows
@@ -32,7 +32,7 @@ import org.apache.myrmidon.interfaces.store.PropertyStore;
*
* @author Peter Donald
* @version $Revision$ $Date$
- * @see PropertyStore
+ * @see org.apache.myrmidon.interfaces.property.PropertyStore
*/
public class DefaultPropertyStore
implements PropertyStore
@@ -61,15 +61,17 @@ public class DefaultPropertyStore
*/
public DefaultPropertyStore()
{
- this( null, null );
+ this( "", null, null );
}
/**
* Construct a PropertyStore with specified parent.
*
- * @param parent the parent PropertyStore (may be null)
+ * @param parent the parent PropertyStore (may be null).
+ * @param validator the validator to use to check property names (may be null).
*/
- public DefaultPropertyStore( final PropertyStore parent,
+ public DefaultPropertyStore( final String name,
+ final PropertyStore parent,
final NameValidator validator )
{
m_parent = parent;
@@ -82,6 +84,7 @@ public class DefaultPropertyStore
m_validator = candidateValidator;
+ m_contextData.put( TaskContext.NAME, name );
}
/**
@@ -91,10 +94,10 @@ public class DefaultPropertyStore
*
* @param name the name of property
* @param value the value of property
- * @throws Exception if property can not be set
+ * @throws TaskException if property can not be set
*/
public void setProperty( final String name, final Object value )
- throws Exception
+ throws TaskException
{
checkPropertyName( name );
checkPropertyValid( name, value );
@@ -118,11 +121,8 @@ public class DefaultPropertyStore
{
try
{
- final Object value = getProperty( name );
- if( null != value )
- {
- return true;
- }
+ getProperty( name );
+ return true;
}
catch( Exception e )
{
@@ -136,18 +136,24 @@ public class DefaultPropertyStore
*
* @param name the name of the property
* @return the value of the property, or null if no such property
- * @throws Exception if theres an error retrieving property, such
+ * @throws TaskException if theres an error retrieving property, such
* as an invalid property name
*/
- public Object getProperty( String name )
- throws Exception
+ public Object getProperty( final String name )
+ throws TaskException
{
Object value = m_contextData.get( name );
- if( value == null && m_parent != null )
+ if( value != null )
+ {
+ return value;
+ }
+ if( m_parent != null )
{
- value = m_parent.getProperty( name );
+ return m_parent.getProperty( name );
}
- return value;
+
+ final String message = REZ.getString( "unknown-prop.error", name );
+ throw new TaskException( message );
}
/**
@@ -156,10 +162,10 @@ public class DefaultPropertyStore
*
* @return a copy of all the properties that are "in-scope"
* for store.
- * @throws Exception if theres an error retrieving propertys
+ * @throws TaskException if theres an error retrieving propertys
*/
public Map getProperties()
- throws Exception
+ throws TaskException
{
final Map properties = new HashMap();
if( m_parent != null )
@@ -178,17 +184,28 @@ public class DefaultPropertyStore
*
* @param name the name of child store
* @return the child store
- * @throws Exception if theres an error creating child store
+ * @throws TaskException if theres an error creating child store
*/
public PropertyStore createChildStore( final String name )
- throws Exception
+ throws TaskException
{
- final DefaultPropertyStore store = new DefaultPropertyStore( this, m_validator );
-
- final String newName = getProperty( TaskContext.NAME ) + "." + name;
- store.setProperty( TaskContext.NAME, newName );
+ // Build the name for the new store
+ final String thisName = (String)m_contextData.get( TaskContext.NAME );
+ final String newName;
+ if( name == null || name.length() == 0 )
+ {
+ newName = thisName;
+ }
+ else if( thisName.length() == 0 )
+ {
+ newName = name;
+ }
+ else
+ {
+ newName = thisName + "." + name;
+ }
- return store;
+ return new DefaultPropertyStore( newName, this, m_validator );
}
/**
@@ -203,7 +220,7 @@ public class DefaultPropertyStore
}
catch( Exception e )
{
- String message = REZ.getString( "bad-property-name.error" );
+ String message = REZ.getString( "bad-property-name.error", name );
throw new TaskException( message, e );
}
}
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/Resources.properties
index 835067974..d752f86b7 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/Resources.properties
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/store/Resources.properties
@@ -1,5 +1,5 @@
-unknown-prop.error=Unknown property {0}.
-bad-property.error=Property {0} must have a value of type {1}.
-bad-property-name.error=Invalid property name.
+unknown-prop.error=Unknown property "{0}".
+bad-property.error=Property "{0}" must have a value of type {1}.
+bad-property-name.error=Invalid property name "{0}".
null-resolved-value.error=Value "{0}" resolved to null.
bad-resolve.error=Unable to resolve value "{0}".
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
index 83498b3a1..3858e8f0a 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
@@ -19,7 +19,7 @@ import org.apache.avalon.framework.service.ServiceManager;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.property.PropertyResolver;
-import org.apache.myrmidon.interfaces.store.PropertyStore;
+import org.apache.myrmidon.interfaces.property.PropertyStore;
/**
* Default implementation of TaskContext.
@@ -44,7 +44,6 @@ public class DefaultTaskContext
public DefaultTaskContext( final ServiceManager serviceManager,
final Logger logger,
final PropertyStore store )
- throws TaskException
{
m_serviceManager = serviceManager;
m_logger = logger;
@@ -150,7 +149,7 @@ public class DefaultTaskContext
m_propertyResolver = (PropertyResolver)getService( PropertyResolver.class );
}
final Object object =
- m_propertyResolver.resolveProperties( value, this );
+ m_propertyResolver.resolveProperties( value, m_store );
if( null == object )
{
final String message = REZ.getString( "null-resolved-value.error", value );
@@ -192,14 +191,7 @@ public class DefaultTaskContext
public Map getProperties()
throws TaskException
{
- try
- {
- return m_store.getProperties();
- }
- catch( final Exception e )
- {
- throw new TaskException( e.getMessage(), e );
- }
+ return m_store.getProperties();
}
/**
@@ -211,14 +203,7 @@ public class DefaultTaskContext
public void setProperty( final String name, final Object value )
throws TaskException
{
- try
- {
- m_store.setProperty( name, value );
- }
- catch( final Exception e )
- {
- throw new TaskException( e.getMessage(), e );
- }
+ m_store.setProperty( name, value );
}
/**
@@ -387,18 +372,11 @@ public class DefaultTaskContext
public TaskContext createSubContext( final String name )
throws TaskException
{
- try
- {
- final PropertyStore store = m_store.createChildStore( name );
- final DefaultServiceManager serviceManager =
- new DefaultServiceManager( m_serviceManager );
- final Logger logger = m_logger.getChildLogger( name );
+ final PropertyStore store = m_store.createChildStore( name );
+ final DefaultServiceManager serviceManager =
+ new DefaultServiceManager( m_serviceManager );
+ final Logger logger = m_logger.getChildLogger( name );
- return new DefaultTaskContext( serviceManager, logger, store );
- }
- catch( final Exception e )
- {
- throw new TaskException( e.getMessage(), e );
- }
+ return new DefaultTaskContext( serviceManager, logger, store );
}
}
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
index e71d84c4d..0b95c4696 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
@@ -37,7 +37,7 @@ import org.apache.myrmidon.interfaces.model.Target;
import org.apache.myrmidon.interfaces.model.TypeLib;
import org.apache.myrmidon.interfaces.type.TypeManager;
import org.apache.myrmidon.interfaces.workspace.Workspace;
-import org.apache.myrmidon.interfaces.store.PropertyStore;
+import org.apache.myrmidon.interfaces.property.PropertyStore;
import org.apache.myrmidon.listeners.ProjectListener;
import org.apache.myrmidon.components.store.DefaultPropertyStore;
@@ -227,6 +227,8 @@ public class DefaultWorkspace
final TypeManager typeManager = m_typeManager.createChildTypeManager();
serviceManager.put( TypeManager.ROLE, typeManager );
+ // TODO - Add child role manager
+
//We need to create a new deployer so that it deploys
//to project specific TypeManager
final Deployer deployer = m_deployer.createChildDeployer( serviceManager );
@@ -427,6 +429,7 @@ public class DefaultWorkspace
getLogger().debug( message );
}
+ //TODO - put this back in
//frame.getContext().setProperty( Project.TARGET, target );
// Execute all tasks assciated with target
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyResolver.java b/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyResolver.java
index 66d09dd22..a97fbe754 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyResolver.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyResolver.java
@@ -8,7 +8,6 @@
package org.apache.myrmidon.interfaces.property;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
/**
*
@@ -31,11 +30,11 @@ public interface PropertyResolver
* Rules used for property resolution are implementation dependent.
*
* @param value the value to resolve, which may contain property identifiers
- * @param context the set of properties to resolve against.
+ * @param properties the set of properties to resolve against.
* @return the resolved content
* @exception TaskException if an error occurs
*/
Object resolveProperties( final String value,
- final TaskContext context )
+ final PropertyStore properties )
throws TaskException;
}
diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/store/PropertyStore.java b/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyStore.java
similarity index 77%
rename from proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/store/PropertyStore.java
rename to proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyStore.java
index 1a66864d5..a3402c644 100644
--- a/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/store/PropertyStore.java
+++ b/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyStore.java
@@ -5,9 +5,10 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
-package org.apache.myrmidon.interfaces.store;
+package org.apache.myrmidon.interfaces.property;
import java.util.Map;
+import org.apache.myrmidon.api.TaskException;
/**
* This component stores and manages properties. It is also
@@ -36,10 +37,10 @@ public interface PropertyStore
*
* @param name the name of property
* @param value the value of property
- * @throws Exception if property can not be set
+ * @throws TaskException if property can not be set
*/
void setProperty( String name, Object value )
- throws Exception;
+ throws TaskException;
/**
* Return true
if the specified property is set.
@@ -50,15 +51,14 @@ public interface PropertyStore
/**
* Retrieve the value of specified property.
- * Will return null if no such property exists.
*
* @param name the name of the property
- * @return the value of the property, or null if no such property
- * @throws Exception if theres an error retrieving property, such
- * as an invalid property name
+ * @return the value of the property. Never returns null.
+ * @throws TaskException if there is no such property, or on error
+ * retrieving property, such as an invalid property name.
*/
Object getProperty( String name )
- throws Exception;
+ throws TaskException;
/**
* Retrieve a copy of all the properties that are "in-scope"
@@ -66,10 +66,10 @@ public interface PropertyStore
*
* @return a copy of all the properties that are "in-scope"
* for store.
- * @throws Exception if theres an error retrieving propertys
+ * @throws TaskException if theres an error retrieving propertys
*/
Map getProperties()
- throws Exception;
+ throws TaskException;
/**
* Return a child PropertyStore with specified name.
@@ -79,8 +79,8 @@ public interface PropertyStore
*
* @param name the name of child store
* @return the child store
- * @throws Exception if theres an error creating child store
+ * @throws TaskException if theres an error creating child store
*/
PropertyStore createChildStore( String name )
- throws Exception;
+ throws TaskException;
}
diff --git a/proposal/myrmidon/src/test/org/apache/antlib/core/test/PropertyTestCase.java b/proposal/myrmidon/src/test/org/apache/antlib/core/test/PropertyTestCase.java
index b4f43f075..03a2ce8f5 100644
--- a/proposal/myrmidon/src/test/org/apache/antlib/core/test/PropertyTestCase.java
+++ b/proposal/myrmidon/src/test/org/apache/antlib/core/test/PropertyTestCase.java
@@ -13,6 +13,7 @@ import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.LogMessageTracker;
import org.apache.myrmidon.components.workspace.DefaultTaskContext;
+import org.apache.myrmidon.components.store.DefaultPropertyStore;
/**
* Test cases for task.
@@ -98,18 +99,29 @@ public class PropertyTestCase
{
final File projectFile = getTestResource( "property.ant" );
- final Resources contextResources
- = ResourceManager.getPackageResources( DefaultTaskContext.class );
+ final Resources rez
+ = ResourceManager.getPackageResources( DefaultPropertyStore.class );
// Invalid names
String[] messages = new String[]
{
null,
- contextResources.getString( "bad-property-name.error" ),
- null
+ rez.getString( "bad-property-name.error", "badname!" )
};
executeTargetExpectError( projectFile, "bad-prop-name1", messages );
+
+ messages = new String[]
+ {
+ null,
+ rez.getString( "bad-property-name.error", "bad name" )
+ };
executeTargetExpectError( projectFile, "bad-prop-name2", messages );
+
+ messages = new String[]
+ {
+ null,
+ rez.getString( "bad-property-name.error", "" )
+ };
executeTargetExpectError( projectFile, "bad-prop-name3", messages );
}
diff --git a/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/AbstractPropertyResolverTestCase.java b/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/AbstractPropertyResolverTestCase.java
index 74d959cd2..b2925afa8 100644
--- a/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/AbstractPropertyResolverTestCase.java
+++ b/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/AbstractPropertyResolverTestCase.java
@@ -11,13 +11,12 @@ import java.io.File;
import java.util.Date;
import org.apache.aut.converter.lib.ObjectToStringConverter;
import org.apache.avalon.excalibur.i18n.Resources;
-import org.apache.avalon.framework.service.DefaultServiceManager;
-import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.components.AbstractComponentTest;
+import org.apache.myrmidon.components.property.DefaultPropertyResolver;
import org.apache.myrmidon.components.store.DefaultPropertyStore;
-import org.apache.myrmidon.components.workspace.DefaultTaskContext;
import org.apache.myrmidon.interfaces.property.PropertyResolver;
+import org.apache.myrmidon.interfaces.property.PropertyStore;
/**
* General-purpose property resolver test cases.
@@ -28,10 +27,8 @@ import org.apache.myrmidon.interfaces.property.PropertyResolver;
public abstract class AbstractPropertyResolverTestCase
extends AbstractComponentTest
{
- protected final static Resources REZ = getResourcesForTested( AbstractPropertyResolverTestCase.class );
-
protected PropertyResolver m_resolver;
- protected DefaultTaskContext m_context;
+ protected PropertyStore m_store;
public AbstractPropertyResolverTestCase( final String name )
{
@@ -42,11 +39,9 @@ public abstract class AbstractPropertyResolverTestCase
{
m_resolver = (PropertyResolver)getServiceManager().lookup( PropertyResolver.ROLE );
- final DefaultPropertyStore store = new DefaultPropertyStore();
- final DefaultServiceManager serviceManager = new DefaultServiceManager();
- m_context = new DefaultTaskContext( serviceManager, getLogger(), store );
- m_context.setProperty( "intProp", new Integer( 333 ) );
- m_context.setProperty( "stringProp", "String property" );
+ m_store = new DefaultPropertyStore();
+ m_store.setProperty( "intProp", new Integer( 333 ) );
+ m_store.setProperty( "stringProp", "String property" );
registerConverter( ObjectToStringConverter.class, Object.class, String.class );
}
@@ -92,14 +87,14 @@ public abstract class AbstractPropertyResolverTestCase
private void testPropertyValue( final Object propObject )
throws Exception
{
- m_context.setProperty( "typedProp", propObject );
+ m_store.setProperty( "typedProp", propObject );
final String propString = propObject.toString();
- doTestResolution( "${typedProp}", propObject, m_context );
+ doTestResolution( "${typedProp}", propObject, m_store );
doTestResolution( "${typedProp} with following text",
- propString + " with following text", m_context );
+ propString + " with following text", m_store );
doTestResolution( "Preceding text with ${typedProp}",
- "Preceding text with " + propString, m_context );
+ "Preceding text with " + propString, m_store );
}
/**
@@ -107,15 +102,15 @@ public abstract class AbstractPropertyResolverTestCase
*/
public void testMultipleProperties() throws Exception
{
- m_context.setProperty( "prop1", "value1" );
- m_context.setProperty( "prop2", "value2" );
- m_context.setProperty( "int1", new Integer( 123 ) );
+ m_store.setProperty( "prop1", "value1" );
+ m_store.setProperty( "prop2", "value2" );
+ m_store.setProperty( "int1", new Integer( 123 ) );
- doTestResolution( "${prop1}${prop2}", "value1value2", m_context );
- doTestResolution( "${prop1}${prop1}${prop1}", "value1value1value1", m_context );
+ doTestResolution( "${prop1}${prop2}", "value1value2", m_store );
+ doTestResolution( "${prop1}${prop1}${prop1}", "value1value1value1", m_store );
doTestResolution( "before ${prop2} between ${prop1} after",
- "before value2 between value1 after", m_context );
- doTestResolution( "${prop1}-${int1}-${prop2}", "value1-123-value2", m_context );
+ "before value2 between value1 after", m_store );
+ doTestResolution( "${prop1}-${int1}-${prop2}", "value1-123-value2", m_store );
}
/**
@@ -123,13 +118,13 @@ public abstract class AbstractPropertyResolverTestCase
*/
public void testInvalidTypeDeclarations() throws Exception
{
-
+ final Resources rez = getResourcesForTested( DefaultPropertyResolver.class );
doTestFailure( "${unclosed",
- REZ.getString( "prop.mismatched-braces.error" ),
- m_context );
+ rez.getString( "prop.mismatched-braces.error" ),
+ m_store );
doTestFailure( "${",
- REZ.getString( "prop.mismatched-braces.error" ),
- m_context );
+ rez.getString( "prop.mismatched-braces.error" ),
+ m_store );
/* TODO - need to handle these cases. */
// testFailure( "${bad${}", "", m_context );
@@ -141,10 +136,10 @@ public abstract class AbstractPropertyResolverTestCase
*/
protected void doTestResolution( final String value,
final Object expected,
- final TaskContext context )
+ final PropertyStore properties )
throws Exception
{
- final Object resolved = m_resolver.resolveProperties( value, context );
+ final Object resolved = m_resolver.resolveProperties( value, properties );
assertEquals( expected, resolved );
}
@@ -155,11 +150,11 @@ public abstract class AbstractPropertyResolverTestCase
*/
protected void doTestFailure( final String value,
final String expectedErrorMessage,
- final TaskContext context )
+ final PropertyStore properties )
{
try
{
- m_resolver.resolveProperties( value, context );
+ m_resolver.resolveProperties( value, properties );
fail( "Unexpected sucess - test should have failed." );
}
catch( TaskException e )
diff --git a/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/ClassicPropertyResolverTestCase.java b/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/ClassicPropertyResolverTestCase.java
index 12eef075a..742e2478d 100644
--- a/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/ClassicPropertyResolverTestCase.java
+++ b/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/ClassicPropertyResolverTestCase.java
@@ -37,6 +37,6 @@ public class ClassicPropertyResolverTestCase
{
final String undefinedProp = "undefinedProperty";
final String propRef = "${" + undefinedProp + "}";
- doTestResolution( propRef, propRef, m_context );
+ doTestResolution( propRef, propRef, m_store );
}
}
diff --git a/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/DefaultPropertyResolverTestCase.java b/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/DefaultPropertyResolverTestCase.java
index 0183adea8..cc358f07f 100644
--- a/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/DefaultPropertyResolverTestCase.java
+++ b/proposal/myrmidon/src/test/org/apache/myrmidon/components/property/test/DefaultPropertyResolverTestCase.java
@@ -10,6 +10,8 @@ package org.apache.myrmidon.components.property.test;
import org.apache.myrmidon.interfaces.property.PropertyResolver;
import org.apache.myrmidon.components.property.test.AbstractPropertyResolverTestCase;
import org.apache.myrmidon.components.property.DefaultPropertyResolver;
+import org.apache.myrmidon.components.store.DefaultPropertyStore;
+import org.apache.avalon.excalibur.i18n.Resources;
/**
* Functional tests for {@link org.apache.myrmidon.components.property.DefaultPropertyResolver}.
@@ -35,14 +37,15 @@ public class DefaultPropertyResolverTestCase
*/
public void testUndefinedProp() throws Exception
{
+ final Resources rez = getResourcesForTested( DefaultPropertyStore.class );
final String undefinedProp = "undefinedProperty";
doTestFailure( "${" + undefinedProp + "}",
- REZ.getString( "prop.missing-value.error", undefinedProp ),
- m_context );
+ rez.getString( "unknown-prop.error", undefinedProp ),
+ m_store );
//TODO - "" should be disallowed as a property name
doTestFailure( "${}",
- REZ.getString( "prop.missing-value.error", "" ),
- m_context );
+ rez.getString( "unknown-prop.error", "" ),
+ m_store );
}
}