diff --git a/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java b/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java index 49542b7fb..8ad58241c 100644 --- a/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java +++ b/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java @@ -17,12 +17,14 @@ import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.Set; +import org.apache.aut.converter.Converter; +import org.apache.aut.converter.ConverterException; import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.components.property.ClassicPropertyResolver; +import org.apache.myrmidon.interfaces.property.PropertyResolver; import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; import org.apache.myrmidon.interfaces.type.TypeManager; -import org.apache.myrmidon.interfaces.property.PropertyResolver; -import org.apache.myrmidon.components.property.ClassicPropertyResolver; /** * Ant1 Project proxy for Myrmidon. Provides hooks between Myrmidon TaskContext @@ -38,13 +40,18 @@ public class Ant1CompatProject extends Project { public static final String ANT1_TASK_PREFIX = "ant1."; - private static final PropertyResolver c_ant1PropertyResolver = - new ClassicPropertyResolver(); + private final PropertyResolver m_ant1PropertyResolver; + private final Converter m_converter; private Set m_userProperties = new HashSet(); private TaskContext m_context; + /** + * Create an Ant1 project. + * @param context The context for the first Ant1 Task loaded. + */ public Ant1CompatProject( TaskContext context ) + throws TaskException { super(); m_context = context; @@ -55,6 +62,18 @@ public class Ant1CompatProject extends Project { setName( projectName ); } + + m_ant1PropertyResolver = new ClassicPropertyResolver(); + m_converter = (Converter)context.getService( Converter.class ); + } + + /** + * Update the TaskContext for the current task. + * @param context The TaskContext for the currently executing Task. + */ + void recontextulize( TaskContext context ) + { + m_context = context; } /** @@ -357,14 +376,24 @@ public class Ant1CompatProject extends Project { Object value = m_context.getProperty( name ); - // In Ant1, all properties are strings. - if( value instanceof String ) + if( value == null ) + { + return null; + } + else if( value instanceof String ) { return (String)value; } else { - return null; + try + { + return (String)m_converter.convert( String.class, value, m_context ); + } + catch( ConverterException e ) + { + throw new BuildException( e ); + } } } @@ -403,8 +432,6 @@ public class Ant1CompatProject extends Project while( propNames.hasNext() ) { String name = (String)propNames.next(); - - // Use getProperty() to only return Strings. String value = getProperty( name ); if( value != null ) { @@ -453,7 +480,7 @@ public class Ant1CompatProject extends Project { try { - return (String)c_ant1PropertyResolver.resolveProperties( value, + return (String)m_ant1PropertyResolver.resolveProperties( value, m_context ); } catch( TaskException e ) diff --git a/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java b/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java index 6620e74f8..688392243 100644 --- a/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java +++ b/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java @@ -42,29 +42,56 @@ public class Task extends OriginalAnt1Task this.setTaskType( context.getName() ); this.setTaskName( context.getName() ); - Project project = (Project)context.getProperty( "ant1.project" ); + // Create/recontextualise the Ant1 Project. + Ant1CompatProject project = + (Ant1CompatProject)context.getProperty( "ant1.project" ); if( project == null ) { project = createProject(); m_context.setProperty( "ant1.project", project ); } + else + { + project.recontextulize( context ); + } + this.setProject( project ); } - private Project createProject() + /** + * Create and initialise an Ant1CompatProject + */ + private Ant1CompatProject createProject() throws TaskException { - Project project = new Ant1CompatProject( m_context ); + Ant1CompatProject project = new Ant1CompatProject( m_context ); project.init(); return project; } + /** + * Uses the task Configuration to perform Ant1-style configuration + * on the Ant1 task. + * @param configuration The TaskModel for this Ant1 Task. + * @throws ConfigurationException if the Configuration supplied is not valid + */ public void configure( Configuration configuration ) throws ConfigurationException { configure( this, configuration ); this.init(); } + /** + * Uses reflection to configure any Object, with the help of the Ant1 + * IntrospectionHelper. using . This aims to mimic (to some extent) the + * Ant1-style configuration rules implemented by ProjectHelperImpl. + * @param target + * The object to be configured. + * @param configuration + * The data to configure the object with. + * @throws ConfigurationException + * If the Configuration is not valid for the configured object + */ protected void configure( Object target, Configuration configuration ) throws ConfigurationException { IntrospectionHelper helper = IntrospectionHelper.getHelper( target.getClass() ); @@ -118,6 +145,12 @@ public class Task extends OriginalAnt1Task } + /** + * Returns the name of a Task/Datatype as referred to by Ant1 code, without + * the "ant1." prefix. + * @param fullName The full name as known by Myrmidon. + * @return the name without the Ant1 prefix. + */ protected String getAnt1Name( String fullName ) { return fullName.substring( Ant1CompatProject.ANT1_TASK_PREFIX.length() );