git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269050 13f79535-47bb-0310-9956-ffa450edef68master
@@ -32,6 +32,7 @@ import org.apache.ant.runtime.AntEngine; | |||||
import org.apache.ant.runtime.DefaultAntEngine; | import org.apache.ant.runtime.DefaultAntEngine; | ||||
import org.apache.myrmidon.api.JavaVersion; | import org.apache.myrmidon.api.JavaVersion; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.DefaultTaskContext; | |||||
import org.apache.ant.tasklet.engine.TaskletEngine; | import org.apache.ant.tasklet.engine.TaskletEngine; | ||||
import org.apache.avalon.excalibur.cli.CLArgsParser; | import org.apache.avalon.excalibur.cli.CLArgsParser; | ||||
import org.apache.avalon.excalibur.cli.CLOption; | import org.apache.avalon.excalibur.cli.CLOption; | ||||
@@ -317,7 +318,6 @@ public class Main | |||||
//create the project | //create the project | ||||
final Project project = builder.build( buildFile ); | final Project project = builder.build( buildFile ); | ||||
setupProjectContext( project, defines ); | |||||
final ProjectEngine engine = antEngine.getProjectEngine(); | final ProjectEngine engine = antEngine.getProjectEngine(); | ||||
engine.addProjectListener( listener ); | engine.addProjectListener( listener ); | ||||
@@ -328,7 +328,14 @@ public class Main | |||||
while( true ) | while( true ) | ||||
{ | { | ||||
//actually do the build ... | //actually do the build ... | ||||
doBuild( engine, project, targets ); | |||||
final TaskContext context = new DefaultTaskContext(); | |||||
setupContext( context, defines ); | |||||
context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() ); | |||||
context.setProperty( Project.PROJECT_FILE, buildFile ); | |||||
//context.setProperty( Project.PROJECT, projectName ); | |||||
doBuild( engine, project, context, targets ); | |||||
if( !incremental ) break; | if( !incremental ) break; | ||||
@@ -357,6 +364,7 @@ public class Main | |||||
*/ | */ | ||||
protected void doBuild( final ProjectEngine engine, | protected void doBuild( final ProjectEngine engine, | ||||
final Project project, | final Project project, | ||||
final TaskContext context, | |||||
final ArrayList targets ) | final ArrayList targets ) | ||||
{ | { | ||||
try | try | ||||
@@ -366,13 +374,13 @@ public class Main | |||||
//if we didn't specify a target on CLI then choose default | //if we didn't specify a target on CLI then choose default | ||||
if( 0 == targetCount ) | if( 0 == targetCount ) | ||||
{ | { | ||||
engine.execute( project, project.getDefaultTargetName() ); | |||||
engine.executeTarget( project, project.getDefaultTargetName(), context ); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
for( int i = 0; i < targetCount; i++ ) | for( int i = 0; i < targetCount; i++ ) | ||||
{ | { | ||||
engine.execute( project, (String)targets.get( i ) ); | |||||
engine.executeTarget( project, (String)targets.get( i ), context ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -483,7 +491,7 @@ public class Main | |||||
* @param defines the defines | * @param defines the defines | ||||
* @exception AntException if an error occurs | * @exception AntException if an error occurs | ||||
*/ | */ | ||||
protected void setupProjectContext( final Project project, final HashMap defines ) | |||||
protected void setupContext( final TaskContext context, final HashMap defines ) | |||||
throws AntException | throws AntException | ||||
{ | { | ||||
//put these values into defines so that they overide | //put these values into defines so that they overide | ||||
@@ -494,7 +502,7 @@ public class Main | |||||
//defines.put( AntContextResources.TASKLIB_DIR, m_taskLibDir ); | //defines.put( AntContextResources.TASKLIB_DIR, m_taskLibDir ); | ||||
//defines.put( TaskletContext.JAVA_VERSION, getJavaVersion() ); | //defines.put( TaskletContext.JAVA_VERSION, getJavaVersion() ); | ||||
final TaskContext context = project.getContext(); | |||||
//final TaskContext context = project.getContext(); | |||||
addToContext( context, defines ); | addToContext( context, defines ); | ||||
//Add system properties second so that they overide user-defined properties | //Add system properties second so that they overide user-defined properties | ||||
@@ -82,6 +82,7 @@ public class AntCall | |||||
} | } | ||||
getLogger().info( "Calling target " + m_target ); | getLogger().info( "Calling target " + m_target ); | ||||
m_projectEngine.execute( m_project, m_target, m_childContext ); | |||||
//This calls startProject() which is probably not wanted??? | |||||
m_projectEngine.executeTarget( m_project, m_target, m_childContext ); | |||||
} | } | ||||
} | } |
@@ -9,27 +9,27 @@ package org.apache.ant.modules.basic; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import org.apache.ant.AntException; | import org.apache.ant.AntException; | ||||
import org.apache.myrmidon.components.Configurer; | |||||
import org.apache.ant.convert.Converter; | import org.apache.ant.convert.Converter; | ||||
import org.apache.ant.tasklet.DataType; | import org.apache.ant.tasklet.DataType; | ||||
import org.apache.ant.tasklet.engine.DataTypeEngine; | import org.apache.ant.tasklet.engine.DataTypeEngine; | ||||
import org.apache.myrmidon.api.AbstractTask; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import org.apache.ant.tasklet.engine.TaskletEngine; | import org.apache.ant.tasklet.engine.TaskletEngine; | ||||
import org.apache.avalon.framework.component.ComponentManager; | |||||
import org.apache.avalon.framework.component.ComponentException; | import org.apache.avalon.framework.component.ComponentException; | ||||
import org.apache.avalon.framework.component.ComponentManager; | |||||
import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
import org.apache.avalon.framework.configuration.Configurable; | import org.apache.avalon.framework.configuration.Configurable; | ||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
import org.apache.avalon.framework.context.Resolvable; | import org.apache.avalon.framework.context.Resolvable; | ||||
import org.apache.myrmidon.api.AbstractTask; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import org.apache.myrmidon.components.configurer.Configurer; | |||||
/** | /** | ||||
* This is the property "task" to declare a binding of a datatype to a name. | * This is the property "task" to declare a binding of a datatype to a name. | ||||
* | |||||
* | |||||
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
*/ | */ | ||||
public class Property | |||||
public class Property | |||||
extends AbstractTask | extends AbstractTask | ||||
implements Configurable, Composable | implements Configurable, Composable | ||||
{ | { | ||||
@@ -39,12 +39,12 @@ public class Property | |||||
protected DataTypeEngine m_engine; | protected DataTypeEngine m_engine; | ||||
protected Converter m_converter; | protected Converter m_converter; | ||||
protected Configurer m_configurer; | protected Configurer m_configurer; | ||||
public void compose( final ComponentManager componentManager ) | public void compose( final ComponentManager componentManager ) | ||||
throws ComponentException | throws ComponentException | ||||
{ | { | ||||
m_configurer = (Configurer)componentManager. | m_configurer = (Configurer)componentManager. | ||||
lookup( "org.apache.myrmidon.components.Configurer" ); | |||||
lookup( "org.apache.myrmidon.components.configurer.Configurer" ); | |||||
m_engine = (DataTypeEngine)componentManager. | m_engine = (DataTypeEngine)componentManager. | ||||
lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" ); | lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" ); | ||||
@@ -71,9 +71,9 @@ public class Property | |||||
if( name.equals( "name" ) ) | if( name.equals( "name" ) ) | ||||
{ | { | ||||
try | |||||
try | |||||
{ | { | ||||
final String convertedValue = | |||||
final String convertedValue = | |||||
(String)m_converter.convert( String.class, object, getContext() ); | (String)m_converter.convert( String.class, object, getContext() ); | ||||
setName( convertedValue ); | setName( convertedValue ); | ||||
} | } | ||||
@@ -86,13 +86,13 @@ public class Property | |||||
{ | { | ||||
setValue( object ); | setValue( object ); | ||||
} | } | ||||
else if( name.equals( "local-scope" ) ) | |||||
else if( name.equals( "local-scope" ) ) | |||||
{ | { | ||||
try | |||||
try | |||||
{ | { | ||||
final Boolean localScope = | |||||
final Boolean localScope = | |||||
(Boolean)m_converter.convert( Boolean.class, object, getContext() ); | (Boolean)m_converter.convert( Boolean.class, object, getContext() ); | ||||
setLocalScope( Boolean.TRUE == localScope ); | |||||
setLocalScope( Boolean.TRUE == localScope ); | |||||
} | } | ||||
catch( final Exception e ) | catch( final Exception e ) | ||||
{ | { | ||||
@@ -128,7 +128,7 @@ public class Property | |||||
{ | { | ||||
m_name = name; | m_name = name; | ||||
} | } | ||||
public void setValue( final Object value ) | public void setValue( final Object value ) | ||||
throws AntException | throws AntException | ||||
{ | { | ||||
@@ -139,7 +139,7 @@ public class Property | |||||
m_value = value; | m_value = value; | ||||
} | } | ||||
public void setLocalScope( final boolean localScope ) | public void setLocalScope( final boolean localScope ) | ||||
{ | { | ||||
m_localScope = localScope; | m_localScope = localScope; | ||||
@@ -24,19 +24,35 @@ import org.apache.myrmidon.api.TaskContext; | |||||
public class DefaultProject | public class DefaultProject | ||||
implements Project | implements Project | ||||
{ | { | ||||
protected final TaskContext m_baseContext = new DefaultTaskContext(); | |||||
protected final HashMap m_targets = new HashMap(); | |||||
protected Target m_implicitTarget; | |||||
protected String m_defaultTarget; | |||||
///The targets contained by this project | |||||
private final HashMap m_targets = new HashMap(); | |||||
///The implicit target (not present in m_targets) | |||||
private Target m_implicitTarget; | |||||
///The name of the default target | |||||
private String m_defaultTarget; | |||||
///The base directory of project | |||||
private File m_baseDirectory; | |||||
/** | |||||
* Retrieve base directory of project. | |||||
* | |||||
* @return the projects base directory | |||||
*/ | |||||
public final File getBaseDirectory() | |||||
{ | |||||
return m_baseDirectory; | |||||
} | |||||
/** | /** | ||||
* Retrieve implicit target. | * Retrieve implicit target. | ||||
* The implicit target is top level tasks. | |||||
* Currently restricted to property tasks. | |||||
* The implicit target contains all the top level tasks. | |||||
* | * | ||||
* @return the Target | * @return the Target | ||||
*/ | */ | ||||
public Target getImplicitTarget() | |||||
public final Target getImplicitTarget() | |||||
{ | { | ||||
return m_implicitTarget; | return m_implicitTarget; | ||||
} | } | ||||
@@ -46,7 +62,7 @@ public class DefaultProject | |||||
* | * | ||||
* @param target the implicit target | * @param target the implicit target | ||||
*/ | */ | ||||
public void setImplicitTarget( final Target target ) | |||||
public final void setImplicitTarget( final Target target ) | |||||
{ | { | ||||
m_implicitTarget = target; | m_implicitTarget = target; | ||||
} | } | ||||
@@ -57,7 +73,7 @@ public class DefaultProject | |||||
* @param name the name of target | * @param name the name of target | ||||
* @return the Target or null if no target exists with name | * @return the Target or null if no target exists with name | ||||
*/ | */ | ||||
public Target getTarget( final String targetName ) | |||||
public final Target getTarget( final String targetName ) | |||||
{ | { | ||||
return (Target)m_targets.get( targetName ); | return (Target)m_targets.get( targetName ); | ||||
} | } | ||||
@@ -67,7 +83,7 @@ public class DefaultProject | |||||
* | * | ||||
* @return the default target name | * @return the default target name | ||||
*/ | */ | ||||
public String getDefaultTargetName() | |||||
public final String getDefaultTargetName() | |||||
{ | { | ||||
return m_defaultTarget; | return m_defaultTarget; | ||||
} | } | ||||
@@ -75,31 +91,31 @@ public class DefaultProject | |||||
/** | /** | ||||
* Retrieve names of all targets in project. | * Retrieve names of all targets in project. | ||||
* | * | ||||
* @return the iterator of project names | |||||
* @return an array target names | |||||
*/ | */ | ||||
public Iterator getTargetNames() | |||||
public final String[] getTargetNames() | |||||
{ | { | ||||
return m_targets.keySet().iterator(); | |||||
return (String[])m_targets.keySet().toArray( new String[ 0 ] ); | |||||
} | } | ||||
/** | /** | ||||
* Get project (top-level) context. | |||||
* Set DefaultTargetName. | |||||
* | * | ||||
* @return the context | |||||
*/ | |||||
public TaskContext getContext() | |||||
* @param defaultTarget the default target name | |||||
*/ | |||||
public final void setDefaultTargetName( final String defaultTarget ) | |||||
{ | { | ||||
return m_baseContext; | |||||
m_defaultTarget = defaultTarget; | |||||
} | } | ||||
/** | /** | ||||
* Set DefaultTargetName. | |||||
* Retrieve base directory of project. | |||||
* | * | ||||
* @param defaultTarget the default target name | |||||
* @return the projects base directory | |||||
*/ | */ | ||||
public void setDefaultTargetName( final String defaultTarget ) | |||||
public final void setBaseDirectory( final File baseDirectory ) | |||||
{ | { | ||||
m_defaultTarget = defaultTarget; | |||||
m_baseDirectory = baseDirectory; | |||||
} | } | ||||
/** | /** | ||||
@@ -109,7 +125,7 @@ public class DefaultProject | |||||
* @param target the Target | * @param target the Target | ||||
* @exception AntException if an error occurs | * @exception AntException if an error occurs | ||||
*/ | */ | ||||
public void addTarget( final String name, final Target target ) | |||||
public final void addTarget( final String name, final Target target ) | |||||
throws AntException | throws AntException | ||||
{ | { | ||||
if( null != m_targets.get( name ) ) | if( null != m_targets.get( name ) ) | ||||
@@ -105,23 +105,20 @@ public class DefaultProjectBuilder | |||||
//get project-level attributes | //get project-level attributes | ||||
final String baseDirectoryName = configuration.getAttribute( "basedir" ); | final String baseDirectoryName = configuration.getAttribute( "basedir" ); | ||||
final String defaultTarget = configuration.getAttribute( "default" ); | final String defaultTarget = configuration.getAttribute( "default" ); | ||||
final String projectName = configuration.getAttribute( "name" ); | |||||
//Ignore Project name in the future ok?? | |||||
//final String projectName = configuration.getAttribute( "name" ); | |||||
//determine base directory for project | //determine base directory for project | ||||
final File baseDirectory = | final File baseDirectory = | ||||
(new File( file.getParentFile(), baseDirectoryName )).getAbsoluteFile(); | (new File( file.getParentFile(), baseDirectoryName )).getAbsoluteFile(); | ||||
getLogger().debug( "Project " + projectName + " base directory: " + baseDirectory ); | |||||
getLogger().debug( "Project " + file + " base directory: " + baseDirectory ); | |||||
//create project and ... | //create project and ... | ||||
final DefaultProject project = new DefaultProject(); | final DefaultProject project = new DefaultProject(); | ||||
project.setDefaultTargetName( defaultTarget ); | project.setDefaultTargetName( defaultTarget ); | ||||
//setup basic context of project | |||||
final TaskContext context = project.getContext(); | |||||
context.setProperty( TaskContext.BASE_DIRECTORY, baseDirectory ); | |||||
context.setProperty( Project.PROJECT_FILE, file ); | |||||
context.setProperty( Project.PROJECT, projectName ); | |||||
project.setBaseDirectory( baseDirectory ); | |||||
//build using all top-level attributes | //build using all top-level attributes | ||||
buildTopLevelProject( project, configuration ); | buildTopLevelProject( project, configuration ); | ||||
@@ -81,13 +81,13 @@ public class DefaultProjectEngine | |||||
* @param target the name of the target | * @param target the name of the target | ||||
* @exception AntException if an error occurs | * @exception AntException if an error occurs | ||||
*/ | */ | ||||
public void execute( final Project project, final String target ) | |||||
public void executeTarget( final Project project, final String target, final TaskContext context ) | |||||
throws AntException | throws AntException | ||||
{ | { | ||||
//HACK: should do this a better way !!!!!! | //HACK: should do this a better way !!!!!! | ||||
m_componentManager.put( "org.apache.ant.project.Project", project ); | m_componentManager.put( "org.apache.ant.project.Project", project ); | ||||
final TaskContext context = project.getContext(); | |||||
//final TaskContext context = project.getContext(); | |||||
final String projectName = (String)context.getProperty( Project.PROJECT ); | final String projectName = (String)context.getProperty( Project.PROJECT ); | ||||
@@ -7,13 +7,12 @@ | |||||
*/ | */ | ||||
package org.apache.ant.project; | package org.apache.ant.project; | ||||
import java.util.Iterator; | |||||
import org.apache.ant.AntException; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import java.io.File; | |||||
import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
/** | /** | ||||
* Interface through which to interact with projects. | |||||
* Abstraction used to interact with projects. | |||||
* Implementations may choose to structure it anyway they choose. | |||||
* | * | ||||
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
*/ | */ | ||||
@@ -58,12 +57,12 @@ public interface Project | |||||
* | * | ||||
* @return the iterator of project names | * @return the iterator of project names | ||||
*/ | */ | ||||
Iterator getTargetNames(); | |||||
String[] getTargetNames(); | |||||
/** | /** | ||||
* Get project (top-level) context. | |||||
* Retrieve base directory of project. | |||||
* | * | ||||
* @return the context | |||||
* @return the projects base directory | |||||
*/ | */ | ||||
TaskContext getContext(); | |||||
File getBaseDirectory(); | |||||
} | } |
@@ -36,17 +36,6 @@ public interface ProjectEngine | |||||
*/ | */ | ||||
void removeProjectListener( ProjectListener listener ); | void removeProjectListener( ProjectListener listener ); | ||||
/** | |||||
* Execute a target in a particular project. | |||||
* Execute in the project context. | |||||
* | |||||
* @param project the Project | |||||
* @param target the name of the target | |||||
* @exception AntException if an error occurs | |||||
*/ | |||||
void execute( Project project, String target ) | |||||
throws AntException; | |||||
/** | /** | ||||
* Execute a target in a particular project, in a particular context. | * Execute a target in a particular project, in a particular context. | ||||
* | * | ||||
@@ -55,6 +44,6 @@ public interface ProjectEngine | |||||
* @param context the context | * @param context the context | ||||
* @exception AntException if an error occurs | * @exception AntException if an error occurs | ||||
*/ | */ | ||||
void execute( Project project, String target, TaskContext context ) | |||||
void executeTarget( Project project, String target, TaskContext context ) | |||||
throws AntException; | throws AntException; | ||||
} | } |
@@ -10,7 +10,7 @@ package org.apache.ant.runtime; | |||||
import java.io.File; | import java.io.File; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.ant.AntException; | import org.apache.ant.AntException; | ||||
import org.apache.myrmidon.components.Configurer; | |||||
import org.apache.myrmidon.components.configurer.Configurer; | |||||
import org.apache.ant.convert.engine.ConverterEngine; | import org.apache.ant.convert.engine.ConverterEngine; | ||||
import org.apache.ant.project.ProjectBuilder; | import org.apache.ant.project.ProjectBuilder; | ||||
import org.apache.ant.project.ProjectEngine; | import org.apache.ant.project.ProjectEngine; | ||||
@@ -193,7 +193,7 @@ public class DefaultAntEngine | |||||
componentManager.put( "org.apache.ant.project.ProjectBuilder", m_builder ); | componentManager.put( "org.apache.ant.project.ProjectBuilder", m_builder ); | ||||
componentManager.put( "org.apache.ant.tasklet.engine.TskDeployer", m_deployer ); | componentManager.put( "org.apache.ant.tasklet.engine.TskDeployer", m_deployer ); | ||||
componentManager.put( "org.apache.avalon.framework.camelot.Factory", m_factory ); | componentManager.put( "org.apache.avalon.framework.camelot.Factory", m_factory ); | ||||
componentManager.put( "org.apache.myrmidon.components.Configurer", m_configurer ); | |||||
componentManager.put( "org.apache.myrmidon.components.configurer.Configurer", m_configurer ); | |||||
return componentManager; | return componentManager; | ||||
} | } | ||||
@@ -34,8 +34,7 @@ import org.apache.avalon.framework.logger.Loggable; | |||||
import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
import org.apache.myrmidon.api.Task; | import org.apache.myrmidon.api.Task; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.components.Configurer; | |||||
import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||||
import org.apache.myrmidon.components.configurer.Configurer; | |||||
public class DefaultTaskletEngine | public class DefaultTaskletEngine | ||||
extends AbstractLoggable | extends AbstractLoggable | ||||
@@ -91,7 +90,7 @@ public class DefaultTaskletEngine | |||||
m_tskDeployer = (TskDeployer)componentManager. | m_tskDeployer = (TskDeployer)componentManager. | ||||
lookup( "org.apache.ant.tasklet.engine.TskDeployer" ); | lookup( "org.apache.ant.tasklet.engine.TskDeployer" ); | ||||
m_configurer = (Configurer)componentManager. | m_configurer = (Configurer)componentManager. | ||||
lookup( "org.apache.myrmidon.components.Configurer" ); | |||||
lookup( "org.apache.myrmidon.components.configurer.Configurer" ); | |||||
m_dataTypeEngine = (DataTypeEngine)componentManager. | m_dataTypeEngine = (DataTypeEngine)componentManager. | ||||
lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" ); | lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" ); | ||||
m_converterEngine = (ConverterEngine)componentManager. | m_converterEngine = (ConverterEngine)componentManager. | ||||
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE file. | * the LICENSE file. | ||||
*/ | */ | ||||
package org.apache.myrmidon.components; | |||||
package org.apache.myrmidon.components.configurer; | |||||
import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; |
@@ -25,7 +25,6 @@ import org.apache.avalon.framework.context.Context; | |||||
import org.apache.avalon.framework.logger.AbstractLoggable; | import org.apache.avalon.framework.logger.AbstractLoggable; | ||||
import org.apache.avalon.framework.logger.Loggable; | import org.apache.avalon.framework.logger.Loggable; | ||||
import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
import org.apache.myrmidon.components.Configurer; | |||||
/** | /** | ||||
* Class used to configure tasks. | * Class used to configure tasks. | ||||