From 8e684f3e6e608fb3d36212faea4c1c7ad80f4323 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Fri, 8 Feb 2002 13:04:46 +0000 Subject: [PATCH] Improved support for taskdef Renamed a few classes git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271219 13f79535-47bb-0310-9956-ffa450edef68 --- proposal/mutant/build.xml | 2 +- .../apache/ant/antcore/antlib/AntLibrary.java | 51 +++-- .../ant/antcore/antlib/ComponentLibrary.java | 106 +++++++++++ .../ant/antcore/antlib/DynamicLibrary.java | 165 +++++++++++++++++ .../antcore/execution/ComponentManager.java | 174 ++++++++---------- ...nDataService.java => CoreDataService.java} | 10 +- .../antcore/execution/CoreEventService.java | 6 +- .../antcore/execution/CoreExecService.java | 136 ++++++++++++++ ...nFileService.java => CoreFileService.java} | 14 +- .../antcore/execution/ExecutionContext.java | 6 +- .../antcore/execution/ExecutionManager.java | 6 +- .../{ExecutionFrame.java => Frame.java} | 71 +++---- .../ant/antcore/execution/ImportInfo.java | 11 +- .../ant/antcore/execution/TaskContext.java | 2 +- .../org/apache/tools/ant/Ant1Factory.java | 6 +- .../org/apache/tools/ant/Project.java | 22 ++- .../org/apache/ant/antlib/system/Ant.java | 8 +- .../org/apache/ant/antlib/system/AntCall.java | 10 +- .../apache/ant/common/event/BuildEvent.java | 2 +- .../ant/common/service/ComponentService.java | 53 ++---- .../ant/common/service/ExecService.java | 101 ++++++++++ 21 files changed, 716 insertions(+), 246 deletions(-) create mode 100644 proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/ComponentLibrary.java create mode 100644 proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/DynamicLibrary.java rename proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/{ExecutionDataService.java => CoreDataService.java} (97%) create mode 100644 proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java rename proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/{ExecutionFileService.java => CoreFileService.java} (90%) rename proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/{ExecutionFrame.java => Frame.java} (95%) mode change 100755 => 100644 create mode 100644 proposal/mutant/src/java/common/org/apache/ant/common/service/ExecService.java diff --git a/proposal/mutant/build.xml b/proposal/mutant/build.xml index 3fbea496d..520f7528e 100644 --- a/proposal/mutant/build.xml +++ b/proposal/mutant/build.xml @@ -158,7 +158,7 @@ - diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibrary.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibrary.java index e24f18b75..1cc62ebb1 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibrary.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibrary.java @@ -55,10 +55,10 @@ package org.apache.ant.antcore.antlib; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.ant.common.antlib.AntContext; import org.apache.ant.common.antlib.AntLibFactory; import org.apache.ant.common.util.ExecutionException; @@ -68,12 +68,7 @@ import org.apache.ant.common.util.ExecutionException; * @author Conor MacNeill * @created 14 January 2002 */ -public class AntLibrary { - - /** constant indicating a taskdef definition */ - public final static int TASKDEF = 1; - /** constant indicating a typedef definition */ - public final static int TYPEDEF = 2; +public class AntLibrary implements ComponentLibrary { /** A counter for generating unique ids */ private static int implicitLibCount = 0; @@ -128,25 +123,6 @@ public class AntLibrary { this.definitionURL = spec.getLibraryURL(); } - /** - * Create an Ant library to wrap around an existing class - * - * @param componentName the name of the component to be wrapped - * @param componentClass the class to be wrapped - * @param defType the type of definition being defined - */ - public AntLibrary(int defType, String componentName, Class componentClass) { - this.libraryId = "_internal" + (implicitLibCount++); - this.definitions = new HashMap(); - AntLibDefinition definition = new AntLibDefinition(defType, - componentName, componentClass.getName()); - this.definitions.put(componentName, definition); - this.isolated = false; - this.factoryClassName = null; - this.definitionURL = null; - loader = componentClass.getClassLoader(); - } - /** * Sets the Library which this library extends * @@ -191,10 +167,21 @@ public class AntLibrary { /** * Gets the definitions (taskdefs and typedefs) of the AntLibrary * - * @return the definitions map + * @return an iterator over the definition names + */ + public Iterator getDefinitionNames() { + return definitions.keySet().iterator(); + } + + /** + * Get the definition of a particular component + * + * @param definitionName the name of the component within the library + * @return an AntLibDefinition instance with information about the + * component's definition */ - public Map getDefinitions() { - return definitions; + public AntLibDefinition getDefinition(String definitionName) { + return (AntLibDefinition)definitions.get(definitionName); } /** @@ -220,11 +207,14 @@ public class AntLibrary { * Gat an instance of a factory object for creating objects in this * library. * + * @param context the context to use for the factory creation if + * required * @return an instance of the factory, or null if this library does not * support a factory * @exception ExecutionException if the factory cannot be created */ - public AntLibFactory getFactory() throws ExecutionException { + public AntLibFactory getFactory(AntContext context) + throws ExecutionException { try { AntLibFactory libFactory = null; if (factoryClassName != null) { @@ -232,6 +222,7 @@ public class AntLibrary { true, getClassLoader()); libFactory = (AntLibFactory)factoryClass.newInstance(); + libFactory.init(context); } return libFactory; } catch (ClassNotFoundException e) { diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/ComponentLibrary.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/ComponentLibrary.java new file mode 100644 index 000000000..c1e60ffe8 --- /dev/null +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/ComponentLibrary.java @@ -0,0 +1,106 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.ant.antcore.antlib; +import org.apache.ant.common.antlib.AntContext; +import org.apache.ant.common.antlib.AntLibFactory; +import org.apache.ant.common.util.ExecutionException; + +/** + * A Component Library supplies components to the Ant core. + * + * @author Conor MacNeill + * @created 8 February 2002 + */ +public interface ComponentLibrary { + /** constant indicating a taskdef definition */ + final static int TASKDEF = 1; + /** constant indicating a typedef definition */ + final static int TYPEDEF = 2; + + /** + * Gets the ClassLoader of the AntLibrary + * + * @return The ClassLoader value + */ + ClassLoader getClassLoader(); + + /** + * Gat an instance of a factory object for creating objects in this + * library. + * + * @param context the context to use for the factory creation if + * required + * @return an instance of the factory, or null if this library does not + * support a factory + * @exception ExecutionException if the factory cannot be created + */ + AntLibFactory getFactory(AntContext context) throws ExecutionException; + + /** + * Gets the libraryId of the AntLibrary + * + * @return the libraryId value + */ + String getLibraryId(); + + /** + * Get the definition of a particular component + * + * @param definitionName the name of the component within the library + * @return an AntLibDefinition instance with information about the + * component's definition + */ + AntLibDefinition getDefinition(String definitionName); +} + diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/DynamicLibrary.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/DynamicLibrary.java new file mode 100644 index 000000000..42fb4bc21 --- /dev/null +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/DynamicLibrary.java @@ -0,0 +1,165 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.ant.antcore.antlib; +import java.util.HashMap; +import java.util.Map; +import org.apache.ant.common.antlib.AntContext; +import org.apache.ant.common.antlib.AntLibFactory; + +/** + * A dynamic library is created at runtime to hold newly defined components. + * + * @author Conor MacNeill + * @created 8 February 2002 + */ +public class DynamicLibrary implements ComponentLibrary { + /** The name profix for naming dynamic libraries */ + public final static String DYNAMIC_LIB_PREFIX = "_internal"; + /** A static field used to uniquely name dynamic libraries */ + private static int dynamicIdCounter = 0; + + /** + * the factory this dynamic library will use to create instances of its + * components + */ + private AntLibFactory factory; + /** + * the classloader that will be used to create new instances of the + * library's components + */ + private ClassLoader loader; + /** the library's unique id */ + private String libraryId; + /** + * the component definitions of this library. This map contains + * AntLibDefinition instances indexed on the definition names. + */ + private Map definitions = new HashMap(); + + + /** + * Constructor for the DynamicLibrary object + * + * @param factory the factory to use to create instances. May be null + * @param loader the loader to use to load the instance classes + */ + public DynamicLibrary(AntLibFactory factory, ClassLoader loader) { + int dynamicId = 0; + synchronized (DynamicLibrary.class) { + dynamicId = dynamicIdCounter++; + } + this.libraryId = DYNAMIC_LIB_PREFIX + dynamicId; + this.loader = loader; + this.factory = factory; + } + + /** + * Gets the ClassLoader of the AntLibrary + * + * @return The ClassLoader value + */ + public ClassLoader getClassLoader() { + return loader; + } + + /** + * Gat an instance of a factory object for creating objects in this + * library. + * + * @param context the context to use for the factory creation if + * required + * @return an instance of the factory, or null if this library does not + * support a factory + */ + public AntLibFactory getFactory(AntContext context) { + return factory; + } + + /** + * Gets the libraryId of the AntLibrary + * + * @return the libraryId value + */ + public String getLibraryId() { + return libraryId; + } + + /** + * Get the definition of a particular component + * + * @param definitionName the name of the component within the library + * @return an AntLibDefinition instance with information about the + * component's definition + */ + public AntLibDefinition getDefinition(String definitionName) { + return (AntLibDefinition)definitions.get(definitionName); + } + + /** + * Add a new component definition to this library + * + * @param componentType the type of the component + * @param componentName the name of the component + * @param componentClassName the component's class + */ + public void addComponent(int componentType, String componentName, + String componentClassName) { + AntLibDefinition newDefinition + = new AntLibDefinition(componentType, componentName, + componentClassName); + + definitions.put(componentName, newDefinition); + } +} + diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java index 730edf2bd..4ce85251b 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java @@ -52,24 +52,20 @@ * . */ package org.apache.ant.antcore.execution; -import java.io.File; import java.net.MalformedURLException; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import org.apache.ant.antcore.antlib.AntLibDefinition; import org.apache.ant.antcore.antlib.AntLibManager; import org.apache.ant.antcore.antlib.AntLibrary; -import org.apache.ant.antcore.modelparser.XMLProjectParser; -import org.apache.ant.antcore.xml.XMLParseException; +import org.apache.ant.antcore.antlib.ComponentLibrary; +import org.apache.ant.antcore.antlib.DynamicLibrary; import org.apache.ant.common.antlib.AntLibFactory; import org.apache.ant.common.antlib.Converter; import org.apache.ant.common.antlib.StandardLibFactory; -import org.apache.ant.common.model.Project; import org.apache.ant.common.service.ComponentService; import org.apache.ant.common.util.ExecutionException; -import org.apache.ant.init.InitUtils; /** * The instance of the ComponentServices made available by the core to the @@ -83,16 +79,16 @@ public class ComponentManager implements ComponentService { public final static String ANT_LIB_PREFIX = "ant."; /** - * Type converters for this executionFrame. Converters are used when - * configuring Tasks to handle special type conversions. + * Type converters for this frame. Converters are used when configuring + * Tasks to handle special type conversions. */ private Map converters = new HashMap(); /** The factory objects for each library, indexed by the library Id */ private Map libFactories = new HashMap(); - /** The ExecutionFrame this service instance is working for */ - private ExecutionFrame frame; + /** The Frame this service instance is working for */ + private Frame frame; /** The library manager instance used to configure libraries. */ private AntLibManager libManager; @@ -102,20 +98,25 @@ public class ComponentManager implements ComponentService { * manager */ private Map antLibraries; + + /** dynamic libraries which have been defined */ + private Map dynamicLibraries; + /** The definitions which have been imported into this frame. */ private Map definitions = new HashMap(); /** * Constructor * - * @param executionFrame the frame containing this context + * @param frame the frame containing this context * @param allowRemoteLibs true if remote libraries can be loaded though * this service. */ - protected ComponentManager(ExecutionFrame executionFrame, + protected ComponentManager(Frame frame, boolean allowRemoteLibs) { - this.frame = executionFrame; + this.frame = frame; libManager = new AntLibManager(allowRemoteLibs); + dynamicLibraries = new HashMap(); } /** @@ -148,78 +149,38 @@ public class ComponentManager implements ComponentService { } } - /** - * Run a sub-build. - * - * @param antFile the file containing the XML description of the model - * @param targets A list of targets to be run - * @param properties the initiali properties to be used in the build - * @exception ExecutionException if the subbuild cannot be run - */ - public void runBuild(File antFile, Map properties, List targets) - throws ExecutionException { - try { - // Parse the build file into a project - XMLProjectParser parser = new XMLProjectParser(); - Project project - = parser.parseBuildFile(InitUtils.getFileURL(antFile)); - runBuild(project, properties, targets); - } catch (MalformedURLException e) { - throw new ExecutionException(e); - } catch (XMLParseException e) { - throw new ExecutionException(e); - } - } - - /** - * Run a sub-build. - * - * @param model the project model to be used for the build - * @param targets A list of targets to be run - * @param properties the initiali properties to be used in the build - * @exception ExecutionException if the subbuild cannot be run - */ - public void runBuild(Project model, Map properties, List targets) - throws ExecutionException { - ExecutionFrame newFrame = frame.createFrame(model); - newFrame.setInitialProperties(properties); - newFrame.runBuild(targets); - } - - /** - * Run a sub-build using the current frame's project model - * - * @param targets A list of targets to be run - * @param properties the initiali properties to be used in the build - * @exception ExecutionException if the subbuild cannot be run - */ - public void callTarget(Map properties, List targets) - throws ExecutionException { - runBuild(frame.getProject(), properties, targets); - } - /** * Experimental - define a new task * * @param taskName the name by which this task will be referred - * @param taskClass the class of the task + * @param factory the library factory object to create the task + * instances + * @param loader the class loader to use to create the particular tasks + * @param className the name of the class implementing the task * @exception ExecutionException if the task cannot be defined */ - public void taskdef(String taskName, Class taskClass) + public void taskdef(AntLibFactory factory, ClassLoader loader, + String taskName, String className) throws ExecutionException { - defineComponent(AntLibrary.TASKDEF, taskName, taskClass); + defineComponent(factory, loader, ComponentLibrary.TASKDEF, + taskName, className); } /** * Experimental - define a new type * * @param typeName the name by which this type will be referred - * @param typeClass the class of the type + * @param factory the library factory object to create the type + * instances + * @param loader the class loader to use to create the particular types + * @param className the name of the class implementing the type * @exception ExecutionException if the type cannot be defined */ - public void typedef(String typeName, Class typeClass) + public void typedef(AntLibFactory factory, ClassLoader loader, + String typeName, String className) throws ExecutionException { - defineComponent(AntLibrary.TYPEDEF, typeName, typeClass); + defineComponent(factory, loader, ComponentLibrary.TYPEDEF, + typeName, className); } /** @@ -233,6 +194,7 @@ public class ComponentManager implements ComponentService { */ protected void setStandardLibraries(Map standardLibs) throws ExecutionException { + antLibraries = new HashMap(standardLibs); // go through the libraries and import all standard ant libraries @@ -256,33 +218,26 @@ public class ComponentManager implements ComponentService { } /** - * Get the collection of Ant Libraries defined for this frame - * - * @return a map of Ant Libraries indexed by thier library Id - */ - protected Map getAntLibraries() { - return antLibraries; - } - - /** - * Gets the factory object for the given library + * Get the collection of Ant Libraries defined for this frame Gets the + * factory object for the given library * - * @param antLibrary the library for which the factory is required + * @param componentLibrary the compnent library for which a factory + * objetc is required * @return the library's factory object - * @exception ExecutionException if the factory cannot be initialised + * @exception ExecutionException if the factory cannot be created */ - protected AntLibFactory getLibFactory(AntLibrary antLibrary) + protected AntLibFactory getLibFactory(ComponentLibrary componentLibrary) throws ExecutionException { - String libraryId = antLibrary.getLibraryId(); + String libraryId = componentLibrary.getLibraryId(); if (libFactories.containsKey(libraryId)) { return (AntLibFactory)libFactories.get(libraryId); } - AntLibFactory libFactory = antLibrary.getFactory(); + AntLibFactory libFactory + = componentLibrary.getFactory(new ExecutionContext(frame)); if (libFactory == null) { libFactory = new StandardLibFactory(); } libFactories.put(libraryId, libFactory); - libFactory.init(new ExecutionContext(frame)); return libFactory; } @@ -309,32 +264,53 @@ public class ComponentManager implements ComponentService { throw new ExecutionException("Unable to import library " + libraryId + " as it has not been loaded"); } - Map libDefs = library.getDefinitions(); - for (Iterator i = libDefs.keySet().iterator(); i.hasNext(); ) { + for (Iterator i = library.getDefinitionNames(); i.hasNext(); ) { String defName = (String)i.next(); - AntLibDefinition libdef - = (AntLibDefinition)libDefs.get(defName); - definitions.put(defName, new ImportInfo(library, libdef)); + importLibraryDef(library, defName, null); } addLibraryConverters(library); } /** - * Experimental - define a new component + * Import a single component from the given library + * + * @param library the library which provides the component + * @param defName the name of the component in the library + * @param alias the name to be used for the component in build files. If + * this is null, the component's name within its library is used. + */ + protected void importLibraryDef(ComponentLibrary library, String defName, + String alias) { + String label = alias; + if (label == null) { + label = defName; + } + + AntLibDefinition libDef = library.getDefinition(defName); + definitions.put(label, new ImportInfo(library, libDef)); + } + + /** + * Define a new component * * @param componentName the name this component will take - * @param componentClass the component's class * @param defType the type of component being defined + * @param factory the library factory object to create the component + * instances + * @param loader the class loader to use to create the particular + * components + * @param className the name of the class implementing the component * @exception ExecutionException if the component cannot be defined */ - private void defineComponent(int defType, String componentName, - Class componentClass) + private void defineComponent(AntLibFactory factory, ClassLoader loader, + int defType, String componentName, + String className) throws ExecutionException { - AntLibrary wrapperLibrary - = new AntLibrary(defType, componentName, componentClass); - String libraryId = wrapperLibrary.getLibraryId(); - antLibraries.put(libraryId, wrapperLibrary); - importLibrary(libraryId); + DynamicLibrary dynamicLibrary + = new DynamicLibrary(factory, loader); + dynamicLibrary.addComponent(defType, componentName, className); + dynamicLibraries.put(dynamicLibrary.getLibraryId(), dynamicLibrary); + importLibraryDef(dynamicLibrary, componentName, null); } /** diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionDataService.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreDataService.java similarity index 97% rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionDataService.java rename to proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreDataService.java index edabad719..ace9eb95e 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionDataService.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreDataService.java @@ -63,14 +63,14 @@ import org.apache.ant.common.util.PropertyUtils; /** * This is the core's implementation of the DataService service interface. * It gives Ant libraries access to property values maintained in the - * ExecutionFrame. + * Frame. * * @author Conor MacNeill * @created 31 January 2002 */ -public class ExecutionDataService implements DataService { - /** The ExecutionFrame this service instance is working for */ - private ExecutionFrame frame; +public class CoreDataService implements DataService { + /** The Frame this service instance is working for */ + private Frame frame; /** all properties to be unset without throwing an exception */ private boolean allowUnsetProperties; @@ -82,7 +82,7 @@ public class ExecutionDataService implements DataService { * @param allowUnsetProperties true if the reference to an unset * property should not throw an exception */ - public ExecutionDataService(ExecutionFrame frame, + public CoreDataService(Frame frame, boolean allowUnsetProperties) { this.frame = frame; this.allowUnsetProperties = allowUnsetProperties; diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreEventService.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreEventService.java index 980bc40a0..a996d27e0 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreEventService.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreEventService.java @@ -63,15 +63,15 @@ import org.apache.ant.common.util.ExecutionException; * @created 7 February 2002 */ public class CoreEventService implements EventService { - /** The ExecutionFrame this service instance is working for */ - private ExecutionFrame frame; + /** The Frame this service instance is working for */ + private Frame frame; /** * Constructor * * @param frame the frame for which this instance is providing service */ - public CoreEventService(ExecutionFrame frame) { + public CoreEventService(Frame frame) { this.frame = frame; } diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java new file mode 100644 index 000000000..a81aad2c7 --- /dev/null +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java @@ -0,0 +1,136 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.ant.antcore.execution; +import java.io.File; +import java.net.MalformedURLException; +import java.util.List; +import java.util.Map; +import org.apache.ant.antcore.modelparser.XMLProjectParser; +import org.apache.ant.antcore.xml.XMLParseException; +import org.apache.ant.common.model.Project; +import org.apache.ant.common.service.ExecService; +import org.apache.ant.common.util.ExecutionException; +import org.apache.ant.init.InitUtils; + +/** + *This is the core's implementation of the Execution Service. + * + * @author Conor MacNeill + * @created 8 February 2002 + */ +public class CoreExecService implements ExecService { + /** The Frame this service instance is working for */ + private Frame frame; + + /** + * Constructor + * + * @param frame the frame containing this context + */ + protected CoreExecService(Frame frame) { + this.frame = frame; + } + + /** + * Run a sub-build. + * + * @param antFile the file containing the XML description of the model + * @param targets A list of targets to be run + * @param properties the initiali properties to be used in the build + * @exception ExecutionException if the subbuild cannot be run + */ + public void runBuild(File antFile, Map properties, List targets) + throws ExecutionException { + try { + // Parse the build file into a project + XMLProjectParser parser = new XMLProjectParser(); + Project project + = parser.parseBuildFile(InitUtils.getFileURL(antFile)); + runBuild(project, properties, targets); + } catch (MalformedURLException e) { + throw new ExecutionException(e); + } catch (XMLParseException e) { + throw new ExecutionException(e); + } + } + + /** + * Run a sub-build. + * + * @param model the project model to be used for the build + * @param targets A list of targets to be run + * @param properties the initiali properties to be used in the build + * @exception ExecutionException if the subbuild cannot be run + */ + public void runBuild(Project model, Map properties, List targets) + throws ExecutionException { + Frame newFrame = frame.createFrame(model); + newFrame.setInitialProperties(properties); + newFrame.runBuild(targets); + } + + /** + * Run a sub-build using the current frame's project model + * + * @param targets A list of targets to be run + * @param properties the initiali properties to be used in the build + * @exception ExecutionException if the subbuild cannot be run + */ + public void callTarget(Map properties, List targets) + throws ExecutionException { + runBuild(frame.getProject(), properties, targets); + } + +} + diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFileService.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreFileService.java similarity index 90% rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFileService.java rename to proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreFileService.java index e46503762..b09596a45 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFileService.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreFileService.java @@ -64,9 +64,9 @@ import org.apache.ant.common.util.FileUtils; * @author Conor MacNeill * @created 27 January 2002 */ -public class ExecutionFileService implements FileService { - /** The ExecutionFrame this service instance is working for */ - private ExecutionFrame executionFrame; +public class CoreFileService implements FileService { + /** The Frame this service instance is working for */ + private Frame frame; /** General file utilities */ private FileUtils fileUtils = new FileUtils(); @@ -74,10 +74,10 @@ public class ExecutionFileService implements FileService { /** * Constructor * - * @param executionFrame the frame containing this context + * @param frame the frame containing this context */ - public ExecutionFileService(ExecutionFrame executionFrame) { - this.executionFrame = executionFrame; + public CoreFileService(Frame frame) { + this.frame = frame; } /** @@ -89,7 +89,7 @@ public class ExecutionFileService implements FileService { * @exception ExecutionException if the file cannot be resolved. */ public File resolveFile(String fileName) throws ExecutionException { - File base = executionFrame.getBaseDir(); + File base = frame.getBaseDir(); return fileUtils.resolveFile(fileUtils.normalize(base.getPath()), fileName); } diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java index bf28d8318..5725edeff 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java @@ -65,8 +65,8 @@ import org.apache.ant.common.util.ExecutionException; * @created 20 January 2002 */ public class ExecutionContext implements AntContext { - /** The ExecutionFrame containing this context */ - private ExecutionFrame frame; + /** The Frame containing this context */ + private Frame frame; /** the event support instance used to manage build events */ private BuildEventSupport eventSupport; @@ -79,7 +79,7 @@ public class ExecutionContext implements AntContext { * * @param frame the frame containing this context */ - public ExecutionContext(ExecutionFrame frame) { + public ExecutionContext(Frame frame) { this.frame = frame; this.eventSupport = frame.getEventSupport(); } diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java index 538872ba5..1a29085c6 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java @@ -70,7 +70,7 @@ import org.apache.ant.init.InitConfig; /** * The ExecutionManager is used to manage the execution of a build. The * Execution manager is responsible for loading the Ant task libraries, - * creating ExecutionFrames for each project that is part of the build and + * creating Frames for each project that is part of the build and * then executing the tasks within those Execution Frames. * * @author Conor MacNeill @@ -84,7 +84,7 @@ public class ExecutionManager { private BuildEventSupport eventSupport = new BuildEventSupport(); /** The Execution Frame for the top level project being executed */ - private ExecutionFrame mainFrame; + private Frame mainFrame; /** * The configuration to be used in this execution of Ant. It is formed @@ -136,7 +136,7 @@ public class ExecutionManager { addConfigLibPaths(); - mainFrame = new ExecutionFrame(antLibraries, initConfig, config); + mainFrame = new Frame(antLibraries, initConfig, config); } catch (MalformedURLException e) { throw new ExecutionException("Unable to load Ant libraries", e); } diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java old mode 100755 new mode 100644 similarity index 95% rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java rename to proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java index 5f6ee1419..1db6dc2d2 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java @@ -60,6 +60,7 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; import org.apache.ant.antcore.antlib.AntLibrary; +import org.apache.ant.antcore.antlib.ComponentLibrary; import org.apache.ant.antcore.config.AntConfig; import org.apache.ant.common.antlib.AntLibFactory; import org.apache.ant.common.antlib.ExecutionComponent; @@ -80,16 +81,17 @@ import org.apache.ant.common.util.ExecutionException; import org.apache.ant.common.util.FileUtils; import org.apache.ant.common.util.MessageLevel; import org.apache.ant.init.InitConfig; +import org.apache.ant.common.service.ExecService; /** - * An ExecutionFrame maintains the state of a project during an execution. - * The ExecutionFrame contains the data values set by Ant tasks as they are + * An Frame maintains the state of a project during an execution. + * The Frame contains the data values set by Ant tasks as they are * executed, including task definitions, property values, etc. * * @author Conor MacNeill * @created 14 January 2002 */ -public class ExecutionFrame { +public class Frame { /** The Ant aspect used to identify Ant metadata */ public final static String ANT_ASPECT = "ant"; @@ -162,7 +164,7 @@ public class ExecutionFrame { * @exception ExecutionException if a component of the library cannot be * imported */ - protected ExecutionFrame(Map standardLibs, InitConfig initConfig, + protected Frame(Map standardLibs, InitConfig initConfig, AntConfig config) throws ExecutionException { this.standardLibs = standardLibs; this.config = config; @@ -184,7 +186,7 @@ public class ExecutionFrame { } /** - * Sets the Project of the ExecutionFrame + * Sets the Project of the Frame * * @param project The new Project value * @exception ExecutionException if any required sub-frames cannot be @@ -198,7 +200,7 @@ public class ExecutionFrame { String referenceName = (String)i.next(); Project referencedProject = project.getReferencedProject(referenceName); - ExecutionFrame referencedFrame = createFrame(referencedProject); + Frame referencedFrame = createFrame(referencedProject); referencedFrames.put(referenceName, referencedFrame); } @@ -218,7 +220,7 @@ public class ExecutionFrame { */ protected void setDataValue(String name, Object value, boolean mutable) throws ExecutionException { - ExecutionFrame frame = getContainingFrame(name); + Frame frame = getContainingFrame(name); if (frame == this) { if (dataValues.containsKey(name) && !mutable) { log("Ignoring oveeride for data value " + name, @@ -282,7 +284,7 @@ public class ExecutionFrame { Iterator i = referencedFrames.keySet().iterator(); while (i.hasNext()) { String refName = (String)i.next(); - ExecutionFrame refFrame = getReferencedFrame(refName); + Frame refFrame = getReferencedFrame(refName); Map refProperties = refFrame.getAllProperties(); Iterator j = refProperties.keySet().iterator(); while (j.hasNext()) { @@ -345,7 +347,7 @@ public class ExecutionFrame { } /** - * Gets the baseDir of the ExecutionFrame + * Gets the baseDir of the Frame * * @return the baseDir value */ @@ -357,11 +359,11 @@ public class ExecutionFrame { * Get a referenced frame by its reference name * * @param referenceName the name under which the frame was imported. - * @return the ExecutionFrame asscociated with the given reference name + * @return the Frame asscociated with the given reference name * or null if there is no such project. */ - protected ExecutionFrame getReferencedFrame(String referenceName) { - return (ExecutionFrame)referencedFrames.get(referenceName); + protected Frame getReferencedFrame(String referenceName) { + return (Frame)referencedFrames.get(referenceName); } /** @@ -396,7 +398,7 @@ public class ExecutionFrame { * @exception ExecutionException if the value is not defined */ protected Object getDataValue(String name) throws ExecutionException { - ExecutionFrame frame = getContainingFrame(name); + Frame frame = getContainingFrame(name); if (frame == this) { return dataValues.get(name); } else { @@ -414,7 +416,7 @@ public class ExecutionFrame { * does not exist */ protected boolean isDataValueSet(String name) throws ExecutionException { - ExecutionFrame frame = getContainingFrame(name); + Frame frame = getContainingFrame(name); if (frame == this) { return dataValues.containsKey(name); } else { @@ -441,13 +443,13 @@ public class ExecutionFrame { * Create a new frame for a given project * * @param project the project model the frame will deal with - * @return an ExecutionFrame ready to build the project + * @return an Frame ready to build the project * @exception ExecutionException if the frame cannot be created. */ - protected ExecutionFrame createFrame(Project project) + protected Frame createFrame(Project project) throws ExecutionException { - ExecutionFrame newFrame - = new ExecutionFrame(standardLibs, initConfig, config); + Frame newFrame + = new Frame(standardLibs, initConfig, config); newFrame.setProject(project); for (Iterator j = eventSupport.getListeners(); j.hasNext(); ) { BuildListener listener = (BuildListener)j.next(); @@ -473,7 +475,7 @@ public class ExecutionFrame { */ protected void addBuildListener(BuildListener listener) { for (Iterator i = getReferencedFrames(); i.hasNext(); ) { - ExecutionFrame referencedFrame = (ExecutionFrame)i.next(); + Frame referencedFrame = (Frame)i.next(); referencedFrame.addBuildListener(listener); } eventSupport.addBuildListener(listener); @@ -486,7 +488,7 @@ public class ExecutionFrame { */ protected void removeBuildListener(BuildListener listener) { for (Iterator i = getReferencedFrames(); i.hasNext(); ) { - ExecutionFrame subFrame = (ExecutionFrame)i.next(); + Frame subFrame = (Frame)i.next(); subFrame.removeBuildListener(listener); } eventSupport.removeBuildListener(listener); @@ -536,7 +538,7 @@ public class ExecutionFrame { List dependencyOrder = project.getTargetDependencies(targetName); for (Iterator i = dependencyOrder.iterator(); i.hasNext(); ) { String fullTargetName = (String)i.next(); - ExecutionFrame frame = getContainingFrame(fullTargetName); + Frame frame = getContainingFrame(fullTargetName); String localTargetName = getNameInFrame(fullTargetName); frame.executeTargetTasks(localTargetName); } @@ -661,7 +663,7 @@ public class ExecutionFrame { */ protected void initialize() throws ExecutionException { for (Iterator i = getReferencedFrames(); i.hasNext(); ) { - ExecutionFrame referencedFrame = (ExecutionFrame)i.next(); + Frame referencedFrame = (Frame)i.next(); referencedFrame.initialize(); } Iterator taskIterator = project.getTasks(); @@ -695,13 +697,13 @@ public class ExecutionFrame { * @return the execution frame for the project that contains the given * target */ - private ExecutionFrame getContainingFrame(String targetName) { + private Frame getContainingFrame(String targetName) { int index = targetName.lastIndexOf(Project.REF_DELIMITER); if (index == -1) { return this; } - ExecutionFrame currentFrame = this; + Frame currentFrame = this; String relativeName = targetName.substring(0, index); StringTokenizer tokenizer = new StringTokenizer(relativeName, Project.REF_DELIMITER); @@ -745,7 +747,7 @@ public class ExecutionFrame { setDataValue(MagicProperties.BASEDIR, baseDir.getAbsolutePath(), true); for (Iterator i = getReferencedFrames(); i.hasNext(); ) { - ExecutionFrame refFrame = (ExecutionFrame)i.next(); + Frame refFrame = (Frame)i.next(); refFrame.determineBaseDirs(); } } @@ -756,16 +758,17 @@ public class ExecutionFrame { */ private void configureServices() { // create services and make them available in our services map - fileService = new ExecutionFileService(this); + fileService = new CoreFileService(this); componentManager = new ComponentManager(this, config.isRemoteLibAllowed()); - dataService = new ExecutionDataService(this, + dataService = new CoreDataService(this, config.isUnsetPropertiesAllowed()); services.put(FileService.class, fileService); services.put(ComponentService.class, componentManager); services.put(DataService.class, dataService); services.put(EventService.class, new CoreEventService(this)); + services.put(ExecService.class, new CoreExecService(this)); } /** @@ -986,14 +989,15 @@ public class ExecutionFrame { } String className = taskDefInfo.getClassName(); - AntLibrary antLibrary = taskDefInfo.getAntLibrary(); + ComponentLibrary componentLibrary + = taskDefInfo.getComponentLibrary(); try { - ClassLoader taskClassLoader = antLibrary.getClassLoader(); + ClassLoader taskClassLoader = componentLibrary.getClassLoader(); Class elementClass = Class.forName(className, true, taskClassLoader); AntLibFactory libFactory - = componentManager.getLibFactory(antLibrary); + = componentManager.getLibFactory(componentLibrary); Object element = libFactory.createTaskInstance(elementClass); Task task = null; @@ -1058,16 +1062,17 @@ public class ExecutionFrame { } String className = typeDefInfo.getClassName(); - AntLibrary antLibrary = typeDefInfo.getAntLibrary(); + ComponentLibrary componentLibrary + = typeDefInfo.getComponentLibrary(); try { - ClassLoader typeClassLoader = antLibrary.getClassLoader(); + ClassLoader typeClassLoader = componentLibrary.getClassLoader(); Class typeClass = Class.forName(className, true, typeClassLoader); ClassLoader currentLoader = setContextLoader(typeClassLoader); AntLibFactory libFactory - = componentManager.getLibFactory(antLibrary); + = componentManager.getLibFactory(componentLibrary); Object typeInstance = createTypeInstance(typeClass, libFactory, model); setContextLoader(currentLoader); diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ImportInfo.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ImportInfo.java index 00c7c86f2..b114f7b99 100644 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ImportInfo.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ImportInfo.java @@ -54,7 +54,7 @@ package org.apache.ant.antcore.execution; import org.apache.ant.antcore.antlib.AntLibDefinition; -import org.apache.ant.antcore.antlib.AntLibrary; +import org.apache.ant.antcore.antlib.ComponentLibrary; /** * This class is used to maintain information about imports @@ -63,8 +63,8 @@ import org.apache.ant.antcore.antlib.AntLibrary; * @created 16 January 2002 */ public class ImportInfo { - /** the ant library from which the import is made */ - private AntLibrary library; + /** the component library from which the import is made */ + private ComponentLibrary library; /** the library definition information */ private AntLibDefinition libDefinition; @@ -74,7 +74,8 @@ public class ImportInfo { * @param library The library from which the import was made * @param libDefinition the library definition information */ - public ImportInfo(AntLibrary library, AntLibDefinition libDefinition) { + public ImportInfo(ComponentLibrary library, + AntLibDefinition libDefinition) { this.library = library; this.libDefinition = libDefinition; } @@ -93,7 +94,7 @@ public class ImportInfo { * * @return the library from which the import was made */ - public AntLibrary getAntLibrary() { + public ComponentLibrary getComponentLibrary() { return library; } diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/TaskContext.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/TaskContext.java index 50c1c58d6..34bb4a84c 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/TaskContext.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/TaskContext.java @@ -78,7 +78,7 @@ public class TaskContext extends ExecutionContext { * * @param frame the frame containing this context */ - public TaskContext(ExecutionFrame frame) { + public TaskContext(Frame frame) { super(frame); } diff --git a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java b/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java index b2d14698f..f5b5e6dec 100644 --- a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java +++ b/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java @@ -82,13 +82,17 @@ public class Ant1Factory extends StandardLibFactory { * @exception ExecutionException if the factory cannot be initialised. */ public void init(AntContext context) throws ExecutionException { + if (project != null) { + return; + } + this.context = context; // set the system classpath. In Ant2, the system classpath will not // in general, have any useful information. For Ant1 compatability // we set it now to include the Ant1 facade classes System.setProperty("java.class.path", getAnt1Classpath()); - project = new Project(); + project = new Project(this); project.init(context); EventService eventService = diff --git a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Project.java b/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Project.java index 01c2ad5d6..bdde0ce27 100644 --- a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Project.java +++ b/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Project.java @@ -63,6 +63,7 @@ import java.util.Properties; import java.util.Stack; import java.util.Vector; import org.apache.ant.common.antlib.AntContext; +import org.apache.ant.common.antlib.AntLibFactory; import org.apache.ant.common.service.ComponentService; import org.apache.ant.common.service.DataService; import org.apache.ant.common.service.FileService; @@ -116,6 +117,10 @@ public class Project implements org.apache.ant.common.event.BuildListener { /** The java version detected that Ant is running on */ private static String javaVersion; + /** the factory which created this project instance. This is used to + define new types and tasks */ + private AntLibFactory factory; + /** Collection of Ant1 type definitions */ private Hashtable dataClassDefinitions = new Hashtable(); /** Collection of Ant1 task definitions */ @@ -175,8 +180,13 @@ public class Project implements org.apache.ant.common.event.BuildListener { } } - /** Create the project */ - public Project() { + /** + * Create the project + * + * @param factory the factory object creating this project + */ + public Project(AntLibFactory factory) { + this.factory = factory; fileUtils = FileUtils.newFileUtils(); } @@ -468,6 +478,8 @@ public class Project implements org.apache.ant.common.event.BuildListener { * @param event target finished event */ public void targetFinished(org.apache.ant.common.event.BuildEvent event) { + org.apache.ant.common.model.Target realTarget = + (org.apache.ant.common.model.Target)event.getModelElement(); Target currentTarget = (Target)targetStack.pop(); fireTargetFinished(currentTarget, event.getCause()); currentTarget = null; @@ -818,7 +830,8 @@ public class Project implements org.apache.ant.common.event.BuildListener { public void addTaskDefinition(String taskName, Class taskClass) throws BuildException { try { - componentService.taskdef(taskName, taskClass); + componentService.taskdef(factory, taskClass.getClassLoader(), + taskName, taskClass.getName()); taskClassDefinitions.put(taskName, taskClass); } catch (ExecutionException e) { throw new BuildException(e); @@ -833,7 +846,8 @@ public class Project implements org.apache.ant.common.event.BuildListener { */ public void addDataTypeDefinition(String typeName, Class typeClass) { try { - componentService.typedef(typeName, typeClass); + componentService.typedef(factory, typeClass.getClassLoader(), + typeName, typeClass.getName()); dataClassDefinitions.put(typeName, typeClass); } catch (ExecutionException e) { throw new BuildException(e); diff --git a/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/Ant.java b/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/Ant.java index de1416436..b620bc245 100644 --- a/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/Ant.java +++ b/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/Ant.java @@ -53,7 +53,7 @@ */ package org.apache.ant.antlib.system; import java.io.File; -import org.apache.ant.common.service.ComponentService; +import org.apache.ant.common.service.ExecService; import org.apache.ant.common.util.ExecutionException; /** @@ -113,10 +113,10 @@ public class Ant extends AntBase { } } - ComponentService componentService - = (ComponentService)getCoreService(ComponentService.class); + ExecService execService + = (ExecService)getCoreService(ExecService.class); - componentService.runBuild(antFile, getProperties(), getTargets()); + execService.runBuild(antFile, getProperties(), getTargets()); } } diff --git a/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/AntCall.java b/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/AntCall.java index 0df3fbd29..90589fc23 100644 --- a/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/AntCall.java +++ b/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/AntCall.java @@ -52,7 +52,7 @@ * . */ package org.apache.ant.antlib.system; -import org.apache.ant.common.service.ComponentService; +import org.apache.ant.common.service.ExecService; import org.apache.ant.common.util.ExecutionException; /** @@ -68,10 +68,10 @@ public class AntCall extends AntBase { * @exception ExecutionException if the build fails */ public void execute() throws ExecutionException { - ComponentService componentService - = (ComponentService)getCoreService(ComponentService.class); - - componentService.callTarget(getProperties(), getTargets()); + ExecService execService + = (ExecService)getCoreService(ExecService.class); + + execService.callTarget(getProperties(), getTargets()); } /** diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java b/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java index 33864a414..826a2db36 100644 --- a/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java +++ b/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java @@ -58,7 +58,7 @@ import org.apache.ant.common.model.ModelElement; /** * A BuildEvent indicates the occurence of a significant event in the build. - * All build events come from an ExecutionFrame or an ExecutionManager. + * All build events come from an Frame or an ExecutionManager. * There are a number of different types of event and they will generally be * associated with some build element from the build model. * diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java b/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java index 65747163c..ddde6b699 100644 --- a/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java +++ b/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java @@ -52,10 +52,7 @@ * . */ package org.apache.ant.common.service; -import java.io.File; -import java.util.List; -import java.util.Map; -import org.apache.ant.common.model.Project; +import org.apache.ant.common.antlib.AntLibFactory; import org.apache.ant.common.util.ExecutionException; /** @@ -85,56 +82,30 @@ public interface ComponentService { void loadLib(String libLocation, boolean importAll) throws ExecutionException; - /** - * Run a sub-build. - * - * @param antFile the file containing the XML description of the model - * @param targets A list of targets to be run - * @param properties the initiali properties to be used in the build - * @exception ExecutionException if the subbuild cannot be run - */ - void runBuild(File antFile, Map properties, List targets) - throws ExecutionException; - - /** - * Run a sub-build. - * - * @param model the project model to be used for the build - * @param targets A list of targets to be run - * @param properties the initiali properties to be used in the build - * @exception ExecutionException if the subbuild cannot be run - */ - void runBuild(Project model, Map properties, List targets) - throws ExecutionException; - - /** - * Run a sub-build using the current frame's project model - * - * @param targets A list of targets to be run - * @param properties the initiali properties to be used in the build - * @exception ExecutionException if the subbuild cannot be run - */ - void callTarget(Map properties, List targets) - throws ExecutionException; - /** * Experimental - define a new type * * @param typeName the name by which this type will be referred - * @param typeClass the class of the type + * @param factory the library factory object to create the type instances + * @param loader the class loader to use to create the particular types + * @param className the name of the class implementing the type * @exception ExecutionException if the type cannot be defined */ - void typedef(String typeName, Class typeClass) + void typedef(AntLibFactory factory, ClassLoader loader, + String typeName, String className) throws ExecutionException; - + /** * Experimental - define a new task * * @param taskName the name by which this task will be referred - * @param taskClass the class of the task + * @param factory the library factory object to create the task instances + * @param loader the class loader to use to create the particular tasks + * @param className the name of the class implementing the task * @exception ExecutionException if the task cannot be defined */ - void taskdef(String taskName, Class taskClass) + void taskdef(AntLibFactory factory, ClassLoader loader, + String taskName, String className) throws ExecutionException; } diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/service/ExecService.java b/proposal/mutant/src/java/common/org/apache/ant/common/service/ExecService.java new file mode 100644 index 000000000..6e31723ee --- /dev/null +++ b/proposal/mutant/src/java/common/org/apache/ant/common/service/ExecService.java @@ -0,0 +1,101 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.ant.common.service; +import java.io.File; +import java.util.List; +import java.util.Map; +import org.apache.ant.common.model.Project; +import org.apache.ant.common.util.ExecutionException; + +/** + * The ExecService provides executiuon services to tasks + * + * @author Conor MacNeill + * @created 8 February 2002 + */ +public interface ExecService { + /** + * Run a sub-build. + * + * @param antFile the file containing the XML description of the model + * @param targets A list of targets to be run + * @param properties the initiali properties to be used in the build + * @exception ExecutionException if the subbuild cannot be run + */ + void runBuild(File antFile, Map properties, List targets) + throws ExecutionException; + + /** + * Run a sub-build. + * + * @param model the project model to be used for the build + * @param targets A list of targets to be run + * @param properties the initiali properties to be used in the build + * @exception ExecutionException if the subbuild cannot be run + */ + void runBuild(Project model, Map properties, List targets) + throws ExecutionException; + + /** + * Run a sub-build using the current frame's project model + * + * @param targets A list of targets to be run + * @param properties the initiali properties to be used in the build + * @exception ExecutionException if the subbuild cannot be run + */ + void callTarget(Map properties, List targets) + throws ExecutionException; + +} +