darrell 02/03/21 21:54:22
Modified: proposal/myrmidon/src/ant1compat/org/apache/tools/ant
Ant1CompatProject.java Task.java
Log:
Modifications to Ant1 compatibility layer.
* Recontextualize Ant1 project for every Task.contextualize()
* Use Converter so that non-string properties are not ignored
* Javadoc
Revision Changes Path
1.4 +38 -11
jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java
Index: Ant1CompatProject.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Ant1CompatProject.java 20 Mar 2002 22:30:55 -0000 1.3
+++ Ant1CompatProject.java 22 Mar 2002 05:54:22 -0000 1.4
@@ -17,12 +17,14 @@
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
@@ -32,19 +34,24 @@
* Ant1 original, this class contains the extensions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
- * @version $Revision: 1.3 $ $Date: 2002/03/20 22:30:55 $
+ * @version $Revision: 1.4 $ $Date: 2002/03/22 05:54:22 $
*/
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 @@
{
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 @@
{
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 @@
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 @@
{
try
{
- return (String)c_ant1PropertyResolver.resolveProperties( value,
+ return (String)m_ant1PropertyResolver.resolveProperties( value,
m_context );
}
catch( TaskException e )
1.3 +37 -4
jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java
Index: Task.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Task.java 20 Mar 2002 01:14:26 -0000 1.2
+++ Task.java 22 Mar 2002 05:54:22 -0000 1.3
@@ -22,7 +22,7 @@
* all of the Myrmidon-specific adaptations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
- * @version $Revision: 1.2 $ $Date: 2002/03/20 01:14:26 $
+ * @version $Revision: 1.3 $ $Date: 2002/03/22 05:54:22 $
*/
public class Task extends OriginalAnt1Task
implements org.apache.myrmidon.api.Task, Configurable
@@ -42,29 +42,56 @@
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 @@
}
+ /**
+ * 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() );
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>