Browse Source

Modifications to Ant1 compatibility layer.

* Recontextualize Ant1 project for every Task.contextualize()
* Use Converter so that non-string properties are not ignored
* Javadoc


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271950 13f79535-47bb-0310-9956-ffa450edef68
master
Darrell DeBoer 23 years ago
parent
commit
8bd077c556
2 changed files with 73 additions and 13 deletions
  1. +37
    -10
      proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java
  2. +36
    -3
      proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java

+ 37
- 10
proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java View File

@@ -17,12 +17,14 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; 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.TaskContext;
import org.apache.myrmidon.api.TaskException; 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.DefaultTypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager; 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 * 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."; 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 Set m_userProperties = new HashSet();
private TaskContext m_context; private TaskContext m_context;


/**
* Create an Ant1 project.
* @param context The context for the first Ant1 Task loaded.
*/
public Ant1CompatProject( TaskContext context ) public Ant1CompatProject( TaskContext context )
throws TaskException
{ {
super(); super();
m_context = context; m_context = context;
@@ -55,6 +62,18 @@ public class Ant1CompatProject extends Project
{ {
setName( projectName ); 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 ); 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; return (String)value;
} }
else 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() ) while( propNames.hasNext() )
{ {
String name = (String)propNames.next(); String name = (String)propNames.next();

// Use getProperty() to only return Strings.
String value = getProperty( name ); String value = getProperty( name );
if( value != null ) if( value != null )
{ {
@@ -453,7 +480,7 @@ public class Ant1CompatProject extends Project
{ {
try try
{ {
return (String)c_ant1PropertyResolver.resolveProperties( value,
return (String)m_ant1PropertyResolver.resolveProperties( value,
m_context ); m_context );
} }
catch( TaskException e ) catch( TaskException e )


+ 36
- 3
proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java View File

@@ -42,29 +42,56 @@ public class Task extends OriginalAnt1Task
this.setTaskType( context.getName() ); this.setTaskType( context.getName() );
this.setTaskName( 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 ) if( project == null )
{ {
project = createProject(); project = createProject();
m_context.setProperty( "ant1.project", project ); m_context.setProperty( "ant1.project", project );
} }
else
{
project.recontextulize( context );
}

this.setProject( project ); this.setProject( project );
} }


private Project createProject()
/**
* Create and initialise an Ant1CompatProject
*/
private Ant1CompatProject createProject()
throws TaskException throws TaskException
{ {
Project project = new Ant1CompatProject( m_context );
Ant1CompatProject project = new Ant1CompatProject( m_context );
project.init(); project.init();
return project; 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 public void configure( Configuration configuration ) throws ConfigurationException
{ {
configure( this, configuration ); configure( this, configuration );
this.init(); 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 protected void configure( Object target, Configuration configuration ) throws ConfigurationException
{ {
IntrospectionHelper helper = IntrospectionHelper.getHelper( target.getClass() ); 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 ) protected String getAnt1Name( String fullName )
{ {
return fullName.substring( Ant1CompatProject.ANT1_TASK_PREFIX.length() ); return fullName.substring( Ant1CompatProject.ANT1_TASK_PREFIX.length() );


Loading…
Cancel
Save