diff --git a/proposal/mutant/ant1compat.xml b/proposal/mutant/ant1compat.xml index c367f448c..92db09f2c 100644 --- a/proposal/mutant/ant1compat.xml +++ b/proposal/mutant/ant1compat.xml @@ -29,9 +29,9 @@ - - - + + + @@ -61,6 +61,9 @@ + + + diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibDefinition.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibDefinition.java index 21975af2d..973e5f85f 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibDefinition.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibDefinition.java @@ -60,7 +60,7 @@ package org.apache.ant.antcore.antlib; * @created 19 January 2002 */ public class AntLibDefinition { - /** The tpye of element being defined int his definition */ + /** The type of element being defined int his definition */ private int definitionType; /** The default name for the defintion */ private String definitionName; 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 bee388aff..e24f18b75 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,6 +55,7 @@ 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; @@ -68,10 +69,13 @@ import org.apache.ant.common.util.ExecutionException; * @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; + /** A counter for generating unique ids */ + private static int implicitLibCount = 0; /** * This is the globally unique name of this library. It uses the same @@ -124,6 +128,25 @@ 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 * 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 d1aca6a53..730edf2bd 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 @@ -198,6 +198,30 @@ public class ComponentManager implements ComponentService { 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 + * @exception ExecutionException if the task cannot be defined + */ + public void taskdef(String taskName, Class taskClass) + throws ExecutionException { + defineComponent(AntLibrary.TASKDEF, taskName, taskClass); + } + + /** + * Experimental - define a new type + * + * @param typeName the name by which this type will be referred + * @param typeClass the class of the type + * @exception ExecutionException if the type cannot be defined + */ + public void typedef(String typeName, Class typeClass) + throws ExecutionException { + defineComponent(AntLibrary.TYPEDEF, typeName, typeClass); + } + /** * Set the standard libraries (i.e. those which are independent of the * build files) to be used in this component manager @@ -295,6 +319,24 @@ public class ComponentManager implements ComponentService { addLibraryConverters(library); } + /** + * Experimental - 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 + * @exception ExecutionException if the component cannot be defined + */ + private void defineComponent(int defType, String componentName, + Class componentClass) + throws ExecutionException { + AntLibrary wrapperLibrary + = new AntLibrary(defType, componentName, componentClass); + String libraryId = wrapperLibrary.getLibraryId(); + antLibraries.put(libraryId, wrapperLibrary); + importLibrary(libraryId); + } + /** * Add the converters from the given library to those managed by this * frame. diff --git a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/BuildListener.java b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreEventService.java similarity index 66% rename from proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/BuildListener.java rename to proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreEventService.java index 983b010cc..980bc40a0 100644 --- a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/BuildListener.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreEventService.java @@ -51,15 +51,50 @@ * information on the Apache Software Foundation, please see * . */ -package org.apache.tools.ant; +package org.apache.ant.antcore.execution; +import org.apache.ant.common.event.BuildListener; +import org.apache.ant.common.service.EventService; +import org.apache.ant.common.util.ExecutionException; /** - * BuildListener facade + * Core implementation of the event service * * @author Conor MacNeill - * @created 31 January 2002 + * @created 7 February 2002 */ -public interface BuildListener - extends org.apache.ant.common.event.BuildListener { +public class CoreEventService implements EventService { + /** The ExecutionFrame this service instance is working for */ + private ExecutionFrame frame; + + /** + * Constructor + * + * @param frame the frame for which this instance is providing service + */ + public CoreEventService(ExecutionFrame frame) { + this.frame = frame; + } + + /** + * Add a build listener to the current frame + * + * @param listener the lister which will receive build events + * @exception ExecutionException if the listener cannot be added + */ + public void addBuildListener(BuildListener listener) + throws ExecutionException { + frame.addBuildListener(listener); + } + + /** + * Remove a listener from the current frame + * + * @param listener the listener to be removed + * @exception ExecutionException if the listener could not be removed + */ + public void removeBuildListener(BuildListener listener) + throws ExecutionException { + frame.removeBuildListener(listener); + } } 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/ExecutionFrame.java index 9e8133a03..5f6ee1419 100755 --- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java +++ b/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java @@ -72,6 +72,7 @@ import org.apache.ant.common.model.Target; import org.apache.ant.common.service.ComponentService; import org.apache.ant.common.service.DataService; import org.apache.ant.common.service.FileService; +import org.apache.ant.common.service.EventService; import org.apache.ant.common.service.MagicProperties; import org.apache.ant.common.util.AntException; import org.apache.ant.common.util.ConfigException; @@ -764,6 +765,7 @@ public class ExecutionFrame { services.put(FileService.class, fileService); services.put(ComponentService.class, componentManager); services.put(DataService.class, dataService); + services.put(EventService.class, new CoreEventService(this)); } /** 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 9b5822bfc..b2d14698f 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 @@ -56,6 +56,7 @@ import org.apache.ant.common.antlib.AntContext; import org.apache.ant.common.antlib.Converter; import org.apache.ant.common.antlib.StandardLibFactory; import org.apache.ant.common.util.ExecutionException; +import org.apache.ant.common.service.EventService; import org.apache.ant.init.LoaderUtils; /** @@ -89,6 +90,10 @@ public class Ant1Factory extends StandardLibFactory { project = new Project(); project.init(context); + + EventService eventService = + (EventService)context.getCoreService(EventService.class); + eventService.addBuildListener(project); } diff --git a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/AntClassLoader.java b/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/AntClassLoader.java deleted file mode 100644 index b3e23f3ac..000000000 --- a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/AntClassLoader.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * 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.tools.ant; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import org.apache.ant.common.event.BuildEvent; -import org.apache.ant.init.InitUtils; -import org.apache.tools.ant.types.Path; - -/** - * AntClassLoader facade - * - * @author Conor MacNeill - * @created 2 February 2002 - */ -public class AntClassLoader extends URLClassLoader - implements BuildListener { - /** - * The context loader saved when setting the thread's current context - * loader. - */ - private ClassLoader savedContextLoader = null; - - /** - * Flag which indicates if this loader is currently set as the thread's - * context loader - */ - private boolean isContextLoaderSaved = false; - - /** - * indicates this loader should load classes by delegating to the parent - * loader first - */ - private boolean parentFirst = true; - - /** label used in debugging messages */ - private String debugLabel = null; - - /** flag to indicate of debugging is turned on */ - private boolean debug = false; - - /** - * Create an AntClassLoader - * - * @param project Project instance this loader is associated with - * @param classpath the classpath to use in searching for classes - */ - public AntClassLoader(Project project, Path classpath) { - super(new URL[0]); - addPath(classpath); - } - - /** - * Constructor for the AntClassLoader object - * - * @param project Project instance this loader is associated with - * @param classpath the classpath to use in searching for classes - * @param parentFirst true if this loader should delagate to its parent - * loader - */ - public AntClassLoader(Project project, Path classpath, - boolean parentFirst) { - this(project, classpath); - this.parentFirst = parentFirst; - } - - /** - * Constructor for the AntClassLoader object - * - * @param parent the parent classloader - * @param project Project instance this loader is associated with - * @param classpath the classpath to use in searching for classes - * @param parentFirst true if this loader should delagate to its parent - * loader - */ - public AntClassLoader(ClassLoader parent, Project project, Path classpath, - boolean parentFirst) { - super(new URL[0], parent); - addPath(classpath); - this.parentFirst = parentFirst; - } - - /** - * Initialize the given class - * - * @param theClass the class to be initialised - */ - public static void initializeClass(Class theClass) { - // do nothing in Ant2 - } - - /** - * Set this classloader to operate in isolated mode - * - * @param isolated true if this loader should isolate it from other - * classes in the VM - */ - public void setIsolated(boolean isolated) { - } - - /** - * Set the current thread's context loader to this classloader, storing - * the current loader value for later resetting - */ - public void setThreadContextLoader() { - if (isContextLoaderSaved) { - throw new BuildException("Context loader has not been reset"); - } - Thread currentThread = Thread.currentThread(); - savedContextLoader = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(this); - isContextLoaderSaved = true; - } - - /** - * sets this loader to debug mode - * - * @param debug true if loads should be debugged - */ - public void setDebug(boolean debug) { - this.debug = debug; - dumpURLs(); - } - - /** - * Sets the debugLabel of the AntClassLoader - * - * @param debugLabel the label to use in debug statements - */ - public void setDebugLabel(String debugLabel) { - this.debugLabel = debugLabel; - } - - /** Cleanup this loader */ - public void cleanup() { - } - - /** - * Force a class to be loaded by this loader - * - * @param classname the name of the class to be loaded - * @return an instance of the requested class - * @exception ClassNotFoundException if the class cannot be found - */ - public Class forceLoadClass(String classname) - throws ClassNotFoundException { - return super.loadClass(classname); - } - - /** Reset the thread's class loader to its original value */ - public void resetThreadContextLoader() { - if (!isContextLoaderSaved) { - throw new BuildException("Context loader is not currently set"); - } - Thread currentThread = Thread.currentThread(); - currentThread.setContextClassLoader(savedContextLoader); - isContextLoaderSaved = false; - } - - /** - * build started event - * - * @param event build started event - */ - public void buildStarted(BuildEvent event) { - } - - /** - * build finished event - * - * @param event build finished event - */ - public void buildFinished(BuildEvent event) { - cleanup(); - } - - /** - * target started event. - * - * @param event target started event. - */ - public void targetStarted(BuildEvent event) { - } - - /** - * target finished event - * - * @param event target finished event - */ - public void targetFinished(BuildEvent event) { - } - - /** - * task started event - * - * @param event task started event - */ - public void taskStarted(BuildEvent event) { - } - - /** - * task finished event - * - * @param event task finished event - */ - public void taskFinished(BuildEvent event) { - } - - /** - * message logged event - * - * @param event message logged event - */ - public void messageLogged(BuildEvent event) { - } - - /** - * Add a path to this loader - * - * @param path the path to be added to this loader - */ - private void addPath(Path path) { - try { - String[] pathElements = path.list(); - for (int i = 0; i < pathElements.length; ++i) { - File elementFile = new File(pathElements[i]); - URL elementURL = InitUtils.getFileURL(elementFile); - addURL(elementURL); - } - } catch (MalformedURLException e) { - throw new BuildException(e); - } - } - - /** Dump the URLs being used for this loader */ - private void dumpURLs() { - if (debug && debugLabel != null) { - System.out.println(debugLabel + ": loader URLs"); - URL[] urls = getURLs(); - for (int i = 0; i < urls.length; ++i) { - System.out.println(debugLabel + ": URL: " + urls[i]); - } - } - } - - /* - protected Class loadClass(String name, boolean resolve) - throws ClassNotFoundException { - if (debug && debugLabel != null) { - System.out.println(debugLabel + ": Trying to load class " + name); - } - Class c = findLoadedClass(name); - if (c == null) { - try { - c = findClass(name); - if (debug && debugLabel != null) { - System.out.println(debugLabel + ": Found class " - + name + " in this loader"); - } - } catch (ClassNotFoundException e) { - c = super.loadClass(name, resolve); - if (debug && debugLabel != null) { - System.out.println(debugLabel + ": Found class " - + name + " in parent loader"); - } - return c; - } - } - if (resolve) { - resolveClass(c); - } - return c; - } -*/ -} - 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 2f991d4f4..01c2ad5d6 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 @@ -60,7 +60,10 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.Properties; +import java.util.Stack; +import java.util.Vector; import org.apache.ant.common.antlib.AntContext; +import org.apache.ant.common.service.ComponentService; import org.apache.ant.common.service.DataService; import org.apache.ant.common.service.FileService; import org.apache.ant.common.util.ExecutionException; @@ -76,7 +79,7 @@ import org.apache.tools.ant.util.FileUtils; * @author Conor MacNeill * @created 30 January 2002 */ -public class Project { +public class Project implements org.apache.ant.common.event.BuildListener { /** String which indicates Java version 1.0 */ public final static String JAVA_1_0 = "1.0"; @@ -133,12 +136,21 @@ public class Project { /** The core's DataService instance */ private DataService dataService; - /** Ant1 FileUtils instance fro manipulating files */ + /** The core's Component Service instance */ + private ComponentService componentService; + + /** Ant1 FileUtils instance for manipulating files */ private FileUtils fileUtils; /** The collection of global filters */ private FilterSetCollection globalFilters = new FilterSetCollection(globalFilterSet); + /** This project's listeners */ + private Vector listeners = new Vector(); + + /** the target's we have seen */ + private Stack targetStack = new Stack(); + static { // Determine the Java version by looking at available classes @@ -272,6 +284,15 @@ public class Project { } } + /** + * Gets the buildListeners of the Project + * + * @return A Vector of BuildListener instances + */ + public Vector getBuildListeners() { + return listeners; + } + /** * Gets the AntContext of the Project * @@ -409,6 +430,91 @@ public class Project { return result; } + /** + * build started event + * + * @param event build started event + */ + public void buildStarted(org.apache.ant.common.event.BuildEvent event) { + fireBuildStarted(); + } + + /** + * build finished event + * + * @param event build finished event + */ + public void buildFinished(org.apache.ant.common.event.BuildEvent event) { + fireBuildFinished(event.getCause()); + } + + /** + * target started event. + * + * @param event target started event. + */ + public void targetStarted(org.apache.ant.common.event.BuildEvent event) { + Target newTarget = new Target(this); + org.apache.ant.common.model.Target realTarget = + (org.apache.ant.common.model.Target)event.getModelElement(); + newTarget.setName(realTarget.getName()); + targetStack.push(newTarget); + fireTargetStarted(newTarget); + } + + /** + * target finished event + * + * @param event target finished event + */ + public void targetFinished(org.apache.ant.common.event.BuildEvent event) { + Target currentTarget = (Target)targetStack.pop(); + fireTargetFinished(currentTarget, event.getCause()); + currentTarget = null; + } + + /** + * task started event + * + * @param event task started event + */ + public void taskStarted(org.apache.ant.common.event.BuildEvent event) { + } + + /** + * task finished event + * + * @param event task finished event + */ + public void taskFinished(org.apache.ant.common.event.BuildEvent event) { + } + + /** + * message logged event + * + * @param event message logged event + */ + public void messageLogged(org.apache.ant.common.event.BuildEvent event) { + } + + /** + * add a build listener to this project + * + * @param listener the listener to be added to the project + */ + public void addBuildListener(BuildListener listener) { + listeners.addElement(listener); + } + + /** + * remove a build listener from this project + * + * @param listener the listener to be removed + */ + public void removeBuildListener(BuildListener listener) { + listeners.removeElement(listener); + } + /** * Add a reference to an object. NOte that in Ant2 objects and * properties occupy the same namespace. @@ -577,6 +683,8 @@ public class Project { this.context = context; fileService = (FileService)context.getCoreService(FileService.class); dataService = (DataService)context.getCoreService(DataService.class); + componentService + = (ComponentService)context.getCoreService(ComponentService.class); String defs = "/org/apache/tools/ant/taskdefs/defaults.properties"; @@ -701,12 +809,35 @@ public class Project { } /** - * add a build listener to this project + * define a new task * - * @param listener the listener to be added to the project + * @param taskName the anme of the task in build files + * @param taskClass the class that implements the task + * @exception BuildException if the task cannot be defined */ - public void addBuildListener(BuildListener listener) { - // XXX do nothing for now + public void addTaskDefinition(String taskName, Class taskClass) + throws BuildException { + try { + componentService.taskdef(taskName, taskClass); + taskClassDefinitions.put(taskName, taskClass); + } catch (ExecutionException e) { + throw new BuildException(e); + } + } + + /** + * Add a new type definition + * + * @param typeName the name of the type + * @param typeClass the class which implements the type + */ + public void addDataTypeDefinition(String typeName, Class typeClass) { + try { + componentService.typedef(typeName, typeClass); + dataClassDefinitions.put(typeName, typeClass); + } catch (ExecutionException e) { + throw new BuildException(e); + } } /** @@ -719,12 +850,12 @@ public class Project { public Task createTask(String taskType) { // we piggy back the task onto the current context Task task = null; - Class c = (Class) taskClassDefinitions.get(taskType); + Class c = (Class)taskClassDefinitions.get(taskType); if (c == null) { return null; } - + try { task = (Task)c.newInstance(); task.setProject(this); @@ -734,5 +865,145 @@ public class Project { throw new BuildException(e); } } + + /** send build started event to the listeners */ + protected void fireBuildStarted() { + BuildEvent event = new BuildEvent(this); + for (int i = 0; i < listeners.size(); i++) { + BuildListener listener = (BuildListener)listeners.elementAt(i); + listener.buildStarted(event); + } + } + + /** + * send build finished event to the listeners + * + * @param exception exception which indicates failure if not null + */ + protected void fireBuildFinished(Throwable exception) { + BuildEvent event = new BuildEvent(this); + event.setException(exception); + for (int i = 0; i < listeners.size(); i++) { + BuildListener listener = (BuildListener)listeners.elementAt(i); + listener.buildFinished(event); + } + } + + + /** + * send target started event to the listeners + * + * @param target the target which has started + */ + protected void fireTargetStarted(Target target) { + BuildEvent event = new BuildEvent(target); + for (int i = 0; i < listeners.size(); i++) { + BuildListener listener = (BuildListener)listeners.elementAt(i); + listener.targetStarted(event); + } + } + + /** + * send build finished event to the listeners + * + * @param exception exception which indicates failure if not null + * @param target the target which is just finished + */ + protected void fireTargetFinished(Target target, Throwable exception) { + BuildEvent event = new BuildEvent(target); + event.setException(exception); + for (int i = 0; i < listeners.size(); i++) { + BuildListener listener = (BuildListener)listeners.elementAt(i); + listener.targetFinished(event); + } + } + + /** + * fire a task started event + * + * @param task the task which has started + */ + protected void fireTaskStarted(Task task) { + // register this as the current task on the current thread. + // threadTasks.put(Thread.currentThread(), task); + BuildEvent event = new BuildEvent(task); + for (int i = 0; i < listeners.size(); i++) { + BuildListener listener = (BuildListener)listeners.elementAt(i); + listener.taskStarted(event); + } + } + + /** + * Fire a task finished event + * + * @param task the task which has finsihed + * @param exception the exception associated with the task + */ + protected void fireTaskFinished(Task task, Throwable exception) { + // threadTasks.remove(Thread.currentThread()); + //System.out.flush(); + // System.err.flush(); + BuildEvent event = new BuildEvent(task); + event.setException(exception); + for (int i = 0; i < listeners.size(); i++) { + BuildListener listener = (BuildListener)listeners.elementAt(i); + listener.taskFinished(event); + } + } + + /** + * Fire a message event from the project + * + * @param project the project sending the event + * @param message the message + * @param priority the messsage priority + */ + protected void fireMessageLogged(Project project, String message, + int priority) { + BuildEvent event = new BuildEvent(project); + fireMessageLoggedEvent(event, message, priority); + } + + /** + * Fire a message event from the project + * + * @param message the message + * @param priority the messsage priority + * @param target the target sending the message + */ + protected void fireMessageLogged(Target target, String message, + int priority) { + BuildEvent event = new BuildEvent(target); + fireMessageLoggedEvent(event, message, priority); + } + + /** + * Fire a message event from the project + * + * @param message the message + * @param priority the messsage priority + * @param task the task sending the message + */ + protected void fireMessageLogged(Task task, String message, + int priority) { + BuildEvent event = new BuildEvent(task); + fireMessageLoggedEvent(event, message, priority); + } + + /** + * Fire a message event from the project + * + * @param message the message + * @param priority the messsage priority + * @param event the message event + */ + private void fireMessageLoggedEvent(BuildEvent event, String message, + int priority) { + event.setMessage(message, priority); + for (int i = 0; i < listeners.size(); i++) { + BuildListener listener = (BuildListener)listeners.elementAt(i); + listener.messageLogged(event); + } + } } diff --git a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Target.java b/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Target.java index 26fa2f595..a54249db7 100644 --- a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Target.java +++ b/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Target.java @@ -60,5 +60,47 @@ package org.apache.tools.ant; * @created 31 January 2002 */ public class Target { + /** The project to which this target belongs */ + private Project project; + + /** The name of this target */ + private String name; + + /** + * Construct a Target that is part of the project + * + * @param project the target's project + */ + public Target(Project project) { + this.project = project; + } + + /** + * set the name of the target + * + * @param name the new name value + */ + public void setName(String name) { + this.name = name; + } + + /** + * get the project to which this target belongs + * + * @return the target's project. + */ + public Project getProject() { + return project; + } + + /** + * Gets the name of the Target + * + * @return the target's name + */ + public String getName() { + return name; + } + } diff --git a/proposal/mutant/src/java/antlibs/system/antlib.xml b/proposal/mutant/src/java/antlibs/system/antlib.xml index a26812c14..e4f1892ec 100644 --- a/proposal/mutant/src/java/antlibs/system/antlib.xml +++ b/proposal/mutant/src/java/antlibs/system/antlib.xml @@ -3,8 +3,6 @@ - - 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 4bb4816ff..65747163c 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 @@ -116,5 +116,26 @@ public interface ComponentService { */ 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 + * @exception ExecutionException if the type cannot be defined + */ + void typedef(String typeName, Class typeClass) + 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 + * @exception ExecutionException if the task cannot be defined + */ + void taskdef(String taskName, Class taskClass) + throws ExecutionException; + } diff --git a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/BuildEvent.java b/proposal/mutant/src/java/common/org/apache/ant/common/service/EventService.java similarity index 76% rename from proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/BuildEvent.java rename to proposal/mutant/src/java/common/org/apache/ant/common/service/EventService.java index 745ab6bc2..ff26e5cf5 100644 --- a/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/BuildEvent.java +++ b/proposal/mutant/src/java/common/org/apache/ant/common/service/EventService.java @@ -51,22 +51,31 @@ * information on the Apache Software Foundation, please see * . */ -package org.apache.tools.ant; +package org.apache.ant.common.service; +import org.apache.ant.common.event.BuildListener; +import org.apache.ant.common.util.ExecutionException; /** - * BuildEvent facade + * Core service to manage receiving of events by components within Ant. * * @author Conor MacNeill - * @created 31 January 2002 + * @created 7 February 2002 */ -public class BuildEvent extends org.apache.ant.common.event.BuildEvent { +public interface EventService { /** - * Construct a BuildEvent for a task level event + * Add a build listener to the current frame * - * @param task the task that emitted the event. + * @param listener the lister which will receive build events + * @exception ExecutionException if the listener cannot be added */ - public BuildEvent(Task task) { - super(task.getContext().getModelElement(), MESSAGE); - } + void addBuildListener(BuildListener listener) throws ExecutionException; + + /** + * Remove a listener from the current frame + * + * @param listener the listener to be removed + * @exception ExecutionException if the listener could not be removed + */ + void removeBuildListener(BuildListener listener) throws ExecutionException; }