must be supplied");
+ }
+ }
+ }
+
+ /** The name of the target to be evaluated in the sub-build */
+ private String targetName;
+
+ /** flag which indicates if all current properties should be passed to the subbuild */
+ private boolean inheritAll = true;
+
+ /** flag which indicates if all current references should be passed to the subbuild */
+ private boolean inheritRefs = false;
+
+ /** The properties which will be passed to the sub-build */
+ private Map properties = new HashMap();
+
+ /** The core's data service for manipulating the properties */
+ private DataService dataService;
+
+ /**
+ * Sets the target to be executed in the subbuild
+ *
+ * @param targetName the name of the target to build
+ */
+ public void setTarget(String targetName) {
+ this.targetName = targetName;
+ }
+
+ /**
+ * Indicate if all properties should be passed
+ *
+ * @param inheritAll true if all properties should be passed
+ */
+ public void setInheritAll(boolean inheritAll) {
+ this.inheritAll = inheritAll;
+ }
+
+ /**
+ * Indicate if all references are to be passed to the subbuild
+ *
+ * @param inheritRefs true if the sub-build should be given all the current references
+ */
+ public void setInheritRefs(boolean inheritRefs) {
+ this.inheritRefs = inheritRefs;
+ }
+
+ /**
+ * Initialise this task
+ *
+ * @param context core's context
+ * @exception ExecutionException if we can't access the data service
+ */
+ public void init(AntContext context) throws ExecutionException {
+ super.init(context);
+ dataService = (DataService)getCoreService(DataService.class);
+ }
+
+ /**
+ * Add a property to be passed to the subbuild
+ *
+ * @param property descriptor for the property to be passed
+ */
+ public void addProperty(Property property) {
+ properties.put(property.getName(), property.getValue());
+ }
+
+ /**
+ * Add a reference to be passed
+ *
+ * @param reference the descriptor of the reference to be passed
+ * @exception ExecutionException if the reference does not reference a valid object
+ */
+ public void addReference(Reference reference) throws ExecutionException {
+ String refId = reference.getRefId();
+ if (!dataService.isDataValueSet(refId)) {
+ throw new ExecutionException("RefId \"" + refId + "\" is not set");
+ }
+ Object value = dataService.getDataValue(refId);
+ String toId = reference.getToId();
+ if (toId == null) {
+ toId = refId;
+ }
+
+ properties.put(toId, value);
+ }
+
+ /**
+ * Get the list of targets to be executed
+ *
+ * @return A List of string target names.
+ */
+ protected List getTargets() {
+ List targets = new ArrayList();
+ if (targetName != null) {
+ targets.add(targetName);
+ }
+ return targets;
+ }
+
+ /**
+ * Get the properties to be used with the sub-build
+ *
+ * @return the properties the sub-build will start with
+ */
+ protected Map getProperties() {
+ return properties;
+ }
+
+}
+
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
new file mode 100644
index 000000000..0df3fbd29
--- /dev/null
+++ b/proposal/mutant/src/java/antlibs/system/code/org/apache/ant/antlib/system/AntCall.java
@@ -0,0 +1,87 @@
+/*
+ * 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.antlib.system;
+import org.apache.ant.common.service.ComponentService;
+import org.apache.ant.common.util.ExecutionException;
+
+/**
+ * The Ant task - used to execute a different build file
+ *
+ * @author Conor MacNeill
+ * @created 4 February 2002
+ */
+public class AntCall extends AntBase {
+ /**
+ * Execute the sub-build
+ *
+ * @exception ExecutionException if the build fails
+ */
+ public void execute() throws ExecutionException {
+ ComponentService componentService
+ = (ComponentService)getCoreService(ComponentService.class);
+
+ componentService.callTarget(getProperties(), getTargets());
+ }
+
+ /**
+ * Alias to add a property to the sub-build
+ *
+ * @param param descriptor for the property to be passed
+ */
+ public void addParam(Property param) {
+ super.addProperty(param);
+ }
+
+}
+
diff --git a/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java b/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java
index 6f762e350..c77291c24 100755
--- a/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java
+++ b/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java
@@ -60,18 +60,20 @@ import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.ant.antcore.config.AntConfig;
import org.apache.ant.antcore.config.AntConfigHandler;
import org.apache.ant.antcore.execution.ExecutionManager;
-import org.apache.ant.antcore.model.Project;
-import org.apache.ant.antcore.model.xmlparser.XMLProjectParser;
-import org.apache.ant.antcore.util.ConfigException;
+import org.apache.ant.antcore.modelparser.XMLProjectParser;
import org.apache.ant.antcore.xml.ParseContext;
import org.apache.ant.antcore.xml.XMLParseException;
import org.apache.ant.common.event.BuildListener;
+import org.apache.ant.common.model.Project;
import org.apache.ant.common.util.AntException;
+import org.apache.ant.common.util.ConfigException;
import org.apache.ant.common.util.Location;
import org.apache.ant.common.util.MessageLevel;
import org.apache.ant.init.InitConfig;
@@ -87,6 +89,9 @@ public class Commandline {
/** The default build file name */
public final static String DEFAULT_BUILD_FILENAME = "build.ant";
+ /** The default build file name */
+ public final static String DEFAULT_ANT1_FILENAME = "build.xml";
+
/** The initialisation configuration for Ant */
private InitConfig config;
@@ -102,6 +107,9 @@ public class Commandline {
/** The list of targets to be evaluated in this invocation */
private List targets = new ArrayList(4);
+ /** The command line properties */
+ private Map definedProperties = new HashMap();
+
/**
* This is the build file to run. By default it is a file: type URL but
* other URL protocols can be used.
@@ -237,7 +245,7 @@ public class Commandline {
ExecutionManager executionManager
= new ExecutionManager(initConfig, config);
addBuildListeners(executionManager);
- executionManager.runBuild(project, targets);
+ executionManager.runBuild(project, targets, definedProperties);
} catch (Throwable t) {
if (t instanceof AntException) {
AntException e = (AntException)t;
@@ -329,6 +337,9 @@ public class Commandline {
} else if (arg.equals("-verbose") || arg.equals("-v")) {
// printVersion();
messageOutputLevel = MessageLevel.MSG_VERBOSE;
+ } else if (arg.equals("-debug")) {
+ // printVersion();
+ messageOutputLevel = MessageLevel.MSG_DEBUG;
} else if (arg.equals("-listener")) {
try {
listeners.add(args[i++]);
@@ -350,6 +361,17 @@ public class Commandline {
"using the -logger argument");
return;
}
+ } else if (arg.startsWith("-D")) {
+ String name = arg.substring(2, arg.length());
+ String value = null;
+ int posEq = name.indexOf("=");
+ if (posEq > 0) {
+ value = name.substring(posEq + 1);
+ name = name.substring(0, posEq);
+ } else if (i < args.length - 1) {
+ value = args[++i];
+ }
+ definedProperties.put(name, value);
} else if (arg.startsWith("-")) {
// we don't have any more args to recognize!
System.out.println("Unknown option: " + arg);
@@ -362,6 +384,12 @@ public class Commandline {
if (buildFileURL == null) {
File defaultBuildFile = new File(DEFAULT_BUILD_FILENAME);
+ if (!defaultBuildFile.exists()) {
+ File ant1BuildFile = new File(DEFAULT_ANT1_FILENAME);
+ if (ant1BuildFile.exists()) {
+ defaultBuildFile = ant1BuildFile;
+ }
+ }
try {
buildFileURL = InitUtils.getFileURL(defaultBuildFile);
} catch (MalformedURLException e) {
diff --git a/proposal/mutant/src/java/cli/org/apache/ant/cli/DefaultLogger.java b/proposal/mutant/src/java/cli/org/apache/ant/cli/DefaultLogger.java
index c3bc61f8f..31ab9c56b 100755
--- a/proposal/mutant/src/java/cli/org/apache/ant/cli/DefaultLogger.java
+++ b/proposal/mutant/src/java/cli/org/apache/ant/cli/DefaultLogger.java
@@ -1,125 +1,103 @@
/*
- * The Apache Software License, Version 1.1
+ * The Apache Software License, Version 1.1
*
- * Copyright (c) 2002 The Apache Software Foundation. All rights
- * reserved.
+ * 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:
+ * 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.
+ * 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.
+ * 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.
+ * 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.
+ * 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.
+ * 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 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
- * .
+ * 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.cli;
import java.io.PrintStream;
+import org.apache.ant.common.model.BuildElement;
+import org.apache.ant.common.model.Target;
+import org.apache.ant.common.event.BuildEvent;
import org.apache.ant.common.util.AntException;
import org.apache.ant.common.util.Location;
import org.apache.ant.common.util.MessageLevel;
-import org.apache.ant.common.event.BuildEvent;
-import org.apache.ant.antcore.model.BuildElement;
-import org.apache.ant.antcore.model.Target;
/**
- * Writes build event to a PrintStream. Currently, it only writes which
- * targets are being executed, and any messages that get logged.
+ * Writes build event to a PrintStream. Currently, it only writes which
+ * targets are being executed, and any messages that get logged.
*
- * @author Conor MacNeill
- * @created 15 January 2002
+ * @author Conor MacNeill
+ * @created 15 January 2002
*/
public class DefaultLogger implements BuildLogger {
- /** Standard field separator */
- private static String lSep = System.getProperty("line.separator");
- /** spacing to allow for task tags */
- private final static int LEFT_COLUMN_SIZE = 12;
-
- /** The stream where output should be written */
+ /** The stream where output should be written */
private PrintStream out;
- /** The stream to where errors should be written */
+ /** The stream to where errors should be written */
private PrintStream err;
- /** The level of messages which should be let through */
+ /** The level of messages which should be let through */
private int messageOutputLevel = MessageLevel.MSG_ERR;
- /** Controls whether adornments are added */
+ /** Controls whether adornments are added */
private boolean emacsMode = false;
- /** The time at which the build started */
+ /** The time at which the build started */
private long startTime = System.currentTimeMillis();
- /**
- * Format the time into something readable
- *
- * @param millis Java millis value
- * @return the formatted time
- */
- protected static String formatTime(long millis) {
- long seconds = millis / 1000;
- long minutes = seconds / 60;
-
- if (minutes > 0) {
- return Long.toString(minutes) + " minute"
- + (minutes == 1 ? " " : "s ")
- + Long.toString(seconds % 60) + " second"
- + (seconds % 60 == 1 ? "" : "s");
- } else {
- return Long.toString(seconds) + " second"
- + (seconds % 60 == 1 ? "" : "s");
- }
-
- }
+ /** Standard field separator */
+ private static String lSep = System.getProperty("line.separator");
+ /** spacing to allow for task tags */
+ private final static int LEFT_COLUMN_SIZE = 12;
/**
- * Set the messageOutputLevel this logger is to respond to. Only
- * messages with a message level lower than or equal to the given level
- * are output to the log.
+ * Set the messageOutputLevel this logger is to respond to. Only
+ * messages with a message level lower than or equal to the given level
+ * are output to the log.
*
- * Constants for the message levels are in Project.java. The order of
- * the levels, from least to most verbose, is MSG_ERR, MSG_WARN,
- * MSG_INFO, MSG_VERBOSE, MSG_DEBUG. The default message level for
- * DefaultLogger is Project.MSG_ERR.
+ * Constants for the message levels are in Project.java. The order of
+ * the levels, from least to most verbose, is MSG_ERR, MSG_WARN,
+ * MSG_INFO, MSG_VERBOSE, MSG_DEBUG. The default message level for
+ * DefaultLogger is Project.MSG_ERR.
*
- * @param level the logging level for the logger.
+ * @param level the logging level for the logger.
*/
public void setMessageOutputLevel(int level) {
this.messageOutputLevel = level;
@@ -127,27 +105,28 @@ public class DefaultLogger implements BuildLogger {
/**
- * Set the output stream to which this logger is to send its output.
+ * Set the output stream to which this logger is to send its output.
*
- * @param output the output stream for the logger.
+ * @param output the output stream for the logger.
*/
public void setOutputPrintStream(PrintStream output) {
this.out = output;
}
/**
- * Set the output stream to which this logger is to send error messages.
+ * Set the output stream to which this logger is to send error
+ * messages.
*
- * @param err the error stream for the logger.
+ * @param err the error stream for the logger.
*/
public void setErrorPrintStream(PrintStream err) {
this.err = err;
}
/**
- * Set this logger to produce emacs (and other editor) friendly output.
+ * Set this logger to produce emacs (and other editor) friendly output.
*
- * @param emacsMode true if output is to be unadorned so that emacs and
+ * @param emacsMode true if output is to be unadorned so that emacs and
* other editors can parse files names, etc.
*/
public void setEmacsMode(boolean emacsMode) {
@@ -155,9 +134,9 @@ public class DefaultLogger implements BuildLogger {
}
/**
- * Report an exception
+ * Report an exception
*
- * @param t The exception to be reported.
+ * @param t The exception to be reported.
*/
public void reportException(Throwable t) {
if (t instanceof AntException) {
@@ -182,72 +161,121 @@ public class DefaultLogger implements BuildLogger {
}
/**
- * Process an incoming build event
+ * Description of the Method
*
- * @param event the build event to be processed
+ * @param event Description of Parameter
*/
- public void processBuildEvent(BuildEvent event) {
- switch (event.getEventType()) {
- case BuildEvent.BUILD_STARTED:
- startTime = System.currentTimeMillis();
- break;
- case BuildEvent.BUILD_FINISHED:
- Throwable cause = event.getCause();
-
- if (cause == null) {
- out.println(lSep + "BUILD SUCCESSFUL");
- } else {
- err.println(lSep + "BUILD FAILED" + lSep);
-
- reportException(cause);
- }
+ public void buildStarted(BuildEvent event) {
+ startTime = System.currentTimeMillis();
+ }
- out.println(lSep + "Total time: "
- + formatTime(System.currentTimeMillis() - startTime));
- break;
- case BuildEvent.TARGET_STARTED:
- if (MessageLevel.MSG_INFO <= messageOutputLevel) {
- Target target = (Target)event.getSource();
- out.println(lSep + target.getName() + ":");
- }
- break;
- case BuildEvent.TARGET_FINISHED:
- break;
- case BuildEvent.TASK_STARTED:
- break;
- case BuildEvent.TASK_FINISHED:
- break;
- case BuildEvent.MESSAGE:
- PrintStream logTo
- = event.getPriority() == MessageLevel.MSG_ERR ? err : out;
-
- // Filter out messages based on priority
- if (event.getPriority() <= messageOutputLevel
- && event.getSource() instanceof BuildElement) {
- // Print out the name of the task if we're in one
- BuildElement buildElement
- = (BuildElement)event.getSource();
- String name = buildElement.getType();
-
- if (!emacsMode) {
- String msg = "[" + name + "] ";
- int indentSize = LEFT_COLUMN_SIZE - msg.length();
- for (int i = 0; i < indentSize; i++) {
- logTo.print(" ");
- }
- logTo.print(msg);
- }
-
- // Print the message
- logTo.println(event.getMessage());
+ /**
+ * Description of the Method
+ *
+ * @param event Description of Parameter
+ */
+ public void buildFinished(BuildEvent event) {
+ Throwable cause = event.getCause();
+
+ if (cause == null) {
+ out.println(lSep + "BUILD SUCCESSFUL");
+ } else {
+ err.println(lSep + "BUILD FAILED" + lSep);
+
+ reportException(cause);
+ }
+
+ out.println(lSep + "Total time: "
+ + formatTime(System.currentTimeMillis() - startTime));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param event Description of Parameter
+ */
+ public void targetStarted(BuildEvent event) {
+ if (MessageLevel.MSG_INFO <= messageOutputLevel) {
+ Target target = (Target)event.getSource();
+ out.println(lSep + target.getName() + ":");
+ }
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param event Description of Parameter
+ */
+ public void targetFinished(BuildEvent event) {
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param event Description of Parameter
+ */
+ public void taskStarted(BuildEvent event) {
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param event Description of Parameter
+ */
+ public void taskFinished(BuildEvent event) {
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param event Description of Parameter
+ */
+ public void messageLogged(BuildEvent event) {
+ PrintStream logTo
+ = event.getPriority() == MessageLevel.MSG_ERR ? err : out;
+
+ // Filter out messages based on priority
+ if (event.getPriority() <= messageOutputLevel
+ && event.getModelElement() instanceof BuildElement) {
+ // Print out the name of the task if we're in one
+ BuildElement buildElement
+ = (BuildElement)event.getModelElement();
+ String name = buildElement.getType();
+
+ if (!emacsMode) {
+ String msg = "[" + name + "] ";
+ int indentSize = LEFT_COLUMN_SIZE - msg.length();
+ for (int i = 0; i < indentSize; i++) {
+ logTo.print(" ");
}
- break;
- default:
- err.println("Unrecognized event type = " +
- event.getEventType());
- break;
+ logTo.print(msg);
+ }
+
+ // Print the message
+ logTo.println(event.getMessage());
}
}
+ /**
+ * Format the time into something readable
+ *
+ * @param millis Java millis value
+ * @return the formatted time
+ */
+ protected static String formatTime(long millis) {
+ long seconds = millis / 1000;
+ long minutes = seconds / 60;
+
+ if (minutes > 0) {
+ return Long.toString(minutes) + " minute"
+ + (minutes == 1 ? " " : "s ")
+ + Long.toString(seconds % 60) + " second"
+ + (seconds % 60 == 1 ? "" : "s");
+ } else {
+ return Long.toString(seconds) + " second"
+ + (seconds % 60 == 1 ? "" : "s");
+ }
+
+ }
}
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractComponent.java b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractComponent.java
new file mode 100644
index 000000000..ecb390833
--- /dev/null
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractComponent.java
@@ -0,0 +1,122 @@
+/*
+ * 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.antlib;
+
+import org.apache.ant.common.util.ExecutionException;
+
+/**
+ * Abstract implementation of the ExecutionComponent
+ *
+ * @author Conor MacNeill
+ * @created 5 February 2002
+ */
+public abstract class AbstractComponent implements ExecutionComponent {
+ /** The components's context */
+ private AntContext context;
+
+ /**
+ * Initialise the component. The component may use the AntContext to
+ * request services from the Ant core.
+ *
+ * @param context the component's context
+ * @exception ExecutionException if initialisation fails
+ */
+ public void init(AntContext context) throws ExecutionException {
+ this.context = context;
+ }
+
+ /**
+ * Validate the component. This is called after the element has been
+ * configured from its build model. The element may perform validation
+ * of its configuration
+
+ *
+ * @exception ExecutionException if validation fails
+ */
+ public void validateComponent() throws ExecutionException {
+ // no validation by default
+ }
+
+ /**
+ * Get this component's context
+ *
+ * @return the component context
+ */
+ protected AntContext getContext() {
+ return context;
+ }
+
+ /**
+ * Short cut to get a core service instance
+ *
+ * @param serviceClass the required interface of which an instance is required
+ * @return the core's instance of the requested service
+ * @exception ExecutionException if the core does not support the requested service
+ */
+ protected Object getCoreService(Class serviceClass)
+ throws ExecutionException {
+ return context.getCoreService(serviceClass);
+ }
+
+ /**
+ * Log a message as a build event
+ *
+ * @param message the message to be logged
+ * @param level the priority level of the message
+ */
+ protected void log(String message, int level) {
+ context.log(message, level);
+ }
+}
+
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractTask.java b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractTask.java
index 6c8e705a3..eb1449f21 100644
--- a/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractTask.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractTask.java
@@ -59,42 +59,10 @@ package org.apache.ant.common.antlib;
* @author Conor MacNeill
* @created 16 January 2002
*/
-public abstract class AbstractTask implements Task {
- /** The task's context */
- private AntContext context;
-
- /**
- * Initialise the task. The task may use the AntContext to request
- * services from the Ant core.
- *
- * @param context the Task's context
- */
- public void init(AntContext context) {
- this.context = context;
- }
-
+public abstract class AbstractTask extends AbstractComponent implements Task {
/** Task is about to be cleaned up */
public void destroy() {
// do nothing here
}
-
- /**
- * Get this task's context
- *
- * @return the task context
- */
- protected AntContext getContext() {
- return context;
- }
-
- /**
- * Log a message as a build event
- *
- * @param message the message to be logged
- * @param level the priority level of the message
- */
- protected void log(String message, int level) {
- context.log(message, level);
- }
}
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java
index 67d475c81..b16f36e1b 100644
--- a/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java
@@ -53,9 +53,9 @@
*/
package org.apache.ant.common.antlib;
import java.io.File;
+import org.apache.ant.common.model.ModelElement;
import org.apache.ant.common.util.ExecutionException;
-import org.apache.ant.common.util.Location;
/**
* The AntContext is the interface through which the Ant container and the
@@ -88,17 +88,17 @@ public interface AntContext {
throws ExecutionException;
/**
- * Get the build file location with which this context is associated.
+ * Get the basedir for the current execution
*
- * @return the associated build file location
+ * @return the base directory for this execution of Ant
*/
- Location getLocation();
+ File getBaseDir();
/**
- * Get the basedir for the current execution
+ * Get the model element associated with this context
*
- * @return the base directory for this execution of Ant
+ * @return the modelElement associated with this context
*/
- File getBaseDir();
+ ModelElement getModelElement();
}
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/antlib/ExecutionComponent.java b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/ExecutionComponent.java
index e80392f52..ba524a23d 100644
--- a/proposal/mutant/src/java/common/org/apache/ant/common/antlib/ExecutionComponent.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/antlib/ExecutionComponent.java
@@ -55,8 +55,8 @@ package org.apache.ant.common.antlib;
import org.apache.ant.common.util.ExecutionException;
/**
- * An execution component is a component from an AntLibrary which is used in the
- * execution of an Ant build. A component can have a context.
+ * An execution component is a component from an AntLibrary which is used in
+ * the execution of an Ant build. A component can have a context.
*
* @author Conor MacNeill
* @created 1 February 2002
@@ -70,5 +70,14 @@ public interface ExecutionComponent {
* @exception ExecutionException if the component cannot be initialised
*/
void init(AntContext context) throws ExecutionException;
+
+ /**
+ * Validate the component. This is called after the element has been
+ * configured from its build model. The element may perform validation
+ * of its configuration
+ *
+ * @exception ExecutionException if the component is not validly configured
+ */
+ void validateComponent() throws ExecutionException;
}
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 281deead3..33864a414 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
@@ -54,6 +54,7 @@
package org.apache.ant.common.event;
import java.util.EventObject;
+import org.apache.ant.common.model.ModelElement;
/**
* A BuildEvent indicates the occurence of a significant event in the build.
@@ -96,7 +97,7 @@ public class BuildEvent extends EventObject {
* @param eventType the type of the buildEvent.
* @param source the element with which this event is associated
*/
- public BuildEvent(Object source, int eventType) {
+ public BuildEvent(ModelElement source, int eventType) {
super(source);
this.eventType = eventType;
}
@@ -108,7 +109,7 @@ public class BuildEvent extends EventObject {
* @param cause An exception if associated with the event
* @param source the object with which this event is associated
*/
- public BuildEvent(Object source, int eventType,
+ public BuildEvent(ModelElement source, int eventType,
Throwable cause) {
this(source, eventType);
this.cause = cause;
@@ -117,12 +118,11 @@ public class BuildEvent extends EventObject {
/**
* Create a build event for a message
*
- * @param source the object with which the event is
- * associated.
+ * @param source the object with which the event is associated.
* @param message the message associated with this event
* @param priority the message priority
*/
- public BuildEvent(Object source, String message,
+ public BuildEvent(ModelElement source, String message,
int priority) {
this(source, MESSAGE);
this.message = message;
@@ -168,5 +168,14 @@ public class BuildEvent extends EventObject {
public Throwable getCause() {
return cause;
}
+
+ /**
+ * Gets the modelElement of the BuildEvent
+ *
+ * @return the model element this event is associated with
+ */
+ public ModelElement getModelElement() {
+ return (ModelElement)getSource();
+ }
}
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildListener.java b/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildListener.java
index 86d830f85..781ac89e0 100644
--- a/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildListener.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildListener.java
@@ -65,10 +65,55 @@ import java.util.EventListener;
*/
public interface BuildListener extends EventListener {
/**
- * Process an incoming build event
+ * Fired before any targets are started.
*
- * @param event the event to be processed.
+ * @param event the build event for this notification
*/
- void processBuildEvent(BuildEvent event);
+ void buildStarted(BuildEvent event);
+
+ /**
+ * Fired after the last target has finished. This event will still be
+ * thrown if an error occured during the build.
+ *
+ * @param event the build event for this notification
+ */
+ void buildFinished(BuildEvent event);
+
+ /**
+ * Fired when a target is started.
+ *
+ * @param event the build event for this notification
+ */
+ void targetStarted(BuildEvent event);
+
+ /**
+ * Fired when a target has finished. This event will still be thrown if
+ * an error occured during the build.
+ *
+ * @param event the build event for this notification
+ */
+ void targetFinished(BuildEvent event);
+
+ /**
+ * Fired when a task is started.
+ *
+ * @param event the build event for this notification
+ */
+ void taskStarted(BuildEvent event);
+
+ /**
+ * Fired when a task has finished. This event will still be throw if an
+ * error occured during the build.
+ *
+ * @param event the build event for this notification
+ */
+ void taskFinished(BuildEvent event);
+
+ /**
+ * Fired whenever a message is logged.
+ *
+ * @param event the build event for this notification
+ */
+ void messageLogged(BuildEvent event);
}
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/BuildElement.java b/proposal/mutant/src/java/common/org/apache/ant/common/model/BuildElement.java
old mode 100755
new mode 100644
similarity index 99%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/BuildElement.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/model/BuildElement.java
index 442e73bad..ee88b7d7a
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/BuildElement.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/model/BuildElement.java
@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.model;
+package org.apache.ant.common.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/ModelElement.java b/proposal/mutant/src/java/common/org/apache/ant/common/model/ModelElement.java
old mode 100755
new mode 100644
similarity index 99%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/ModelElement.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/model/ModelElement.java
index a8845e17d..71a4fdc76
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/ModelElement.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/model/ModelElement.java
@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.model;
+package org.apache.ant.common.model;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/ModelException.java b/proposal/mutant/src/java/common/org/apache/ant/common/model/ModelException.java
old mode 100755
new mode 100644
similarity index 99%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/ModelException.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/model/ModelException.java
index 924aaa6b3..f676897cb
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/ModelException.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/model/ModelException.java
@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.model;
+package org.apache.ant.common.model;
import org.apache.ant.common.util.AntException;
import org.apache.ant.common.util.Location;
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/Project.java b/proposal/mutant/src/java/common/org/apache/ant/common/model/Project.java
old mode 100755
new mode 100644
similarity index 96%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/Project.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/model/Project.java
index 1516384be..c09715994
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/Project.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/model/Project.java
@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.model;
+package org.apache.ant.common.model;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -61,10 +61,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
+import org.apache.ant.common.util.CircularDependencyChecker;
+import org.apache.ant.common.util.CircularDependencyException;
+import org.apache.ant.common.util.ConfigException;
import org.apache.ant.common.util.Location;
-import org.apache.ant.antcore.util.CircularDependencyChecker;
-import org.apache.ant.antcore.util.CircularDependencyException;
-import org.apache.ant.antcore.util.ConfigException;
/**
* A project is a collection of targets and global tasks. A project may
@@ -366,42 +366,12 @@ public class Project extends ModelElement {
}
/**
- * Validate that this build element is configured correctly
+ * Validate this project
*
- * @param globalName The name of this project in the reference name
- * space
- * @exception ModelException if the element is invalid
+ * @exception ModelException if the project is not valid
*/
- public void validate(String globalName) throws ModelException {
- Set keys = referencedProjects.keySet();
- for (Iterator i = keys.iterator(); i.hasNext(); ) {
- String refName = (String)i.next();
- Project referencedProject
- = (Project)referencedProjects.get(refName);
- String refGlobalName = refName;
- if (globalName != null) {
- refGlobalName = globalName + REF_DELIMITER + refName;
- }
- referencedProject.validate(refGlobalName);
- }
-
- // we now check whether all of dependencies for our targets
- // exist in the model
-
- // visited contains the targets we have already visited and verified
- Set visited = new HashSet();
- // checker records the targets we are currently visiting
- CircularDependencyChecker checker
- = new CircularDependencyChecker("checking target dependencies");
- // dependency order is purely recorded for debug purposes
- List dependencyOrder = new ArrayList();
-
- for (Iterator i = getTargets(); i.hasNext(); ) {
- Target target = (Target)i.next();
- target.validate();
- fillinDependencyOrder(globalName, target, dependencyOrder,
- visited, checker);
- }
+ public void validate() throws ModelException {
+ validate(null);
}
/**
@@ -466,8 +436,47 @@ public class Project extends ModelElement {
}
/**
- * Given a fully qualified target name, this method simply returns the
- * fully qualified name of the project
+ * Validate that this build element is configured correctly
+ *
+ * @param globalName The name of this project in the reference name
+ * space
+ * @exception ModelException if the element is invalid
+ */
+ protected void validate(String globalName) throws ModelException {
+ Set keys = referencedProjects.keySet();
+ for (Iterator i = keys.iterator(); i.hasNext(); ) {
+ String refName = (String)i.next();
+ Project referencedProject
+ = (Project)referencedProjects.get(refName);
+ String refGlobalName = refName;
+ if (globalName != null) {
+ refGlobalName = globalName + REF_DELIMITER + refName;
+ }
+ referencedProject.validate(refGlobalName);
+ }
+
+ // we now check whether all of dependencies for our targets
+ // exist in the model
+
+ // visited contains the targets we have already visited and verified
+ Set visited = new HashSet();
+ // checker records the targets we are currently visiting
+ CircularDependencyChecker checker
+ = new CircularDependencyChecker("checking target dependencies");
+ // dependency order is purely recorded for debug purposes
+ List dependencyOrder = new ArrayList();
+
+ for (Iterator i = getTargets(); i.hasNext(); ) {
+ Target target = (Target)i.next();
+ target.validate();
+ fillinDependencyOrder(globalName, target, dependencyOrder,
+ visited, checker);
+ }
+ }
+
+ /**
+ * Given a fully qualified target name, this method returns the fully
+ * qualified name of the project
*
* @param fullTargetName the full qualified target name
* @return the full name of the containing project
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/Target.java b/proposal/mutant/src/java/common/org/apache/ant/common/model/Target.java
old mode 100755
new mode 100644
similarity index 99%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/Target.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/model/Target.java
index 0386a0af6..11347cd8f
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/model/Target.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/model/Target.java
@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.model;
+package org.apache.ant.common.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
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 8599b12c8..4bb4816ff 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,6 +52,10 @@
* .
*/
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;
/**
@@ -80,5 +84,37 @@ 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;
}
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/service/DataService.java b/proposal/mutant/src/java/common/org/apache/ant/common/service/DataService.java
index 681031702..47e778398 100644
--- a/proposal/mutant/src/java/common/org/apache/ant/common/service/DataService.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/service/DataService.java
@@ -133,9 +133,10 @@ public interface DataService {
* is an expensive operation since it must clone all of the property
* stores in all frames
*
- * @return a Map containing the frames properties indexed by their full name.
+ * @return a Map containing the frames properties indexed by their full
+ * name.
*/
- Map getAllProperties();
-
+ Map getAllProperties();
+
}
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/util/AntException.java b/proposal/mutant/src/java/common/org/apache/ant/common/util/AntException.java
index bd5f3610d..11964d6bc 100755
--- a/proposal/mutant/src/java/common/org/apache/ant/common/util/AntException.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/util/AntException.java
@@ -105,7 +105,7 @@ public abstract class AntException extends Exception {
*/
public AntException(String msg, Throwable cause, Location location) {
this(msg, cause);
- setLocation(location);
+ setLocation(location, true);
}
/**
@@ -127,7 +127,7 @@ public abstract class AntException extends Exception {
*/
public AntException(String msg, Location location) {
super(msg);
- setLocation(location);
+ setLocation(location, true);
}
/**
@@ -139,19 +139,22 @@ public abstract class AntException extends Exception {
*/
public AntException(Throwable cause, Location location) {
this(cause);
- setLocation(location);
+ setLocation(location, true);
}
/**
* Sets the file location where the error occured.
*
- * @param location the new location value
+ * @param newLocation the new location value
+ * @param override true if the location should override any currently set location
*/
- public void setLocation(Location location) {
- if (location == null) {
- this.location = Location.UNKNOWN_LOCATION;
- } else {
- this.location = location;
+ public void setLocation(Location newLocation, boolean override) {
+ if (override || location == Location.UNKNOWN_LOCATION) {
+ if (newLocation == null) {
+ this.location = Location.UNKNOWN_LOCATION;
+ } else {
+ this.location = newLocation;
+ }
}
}
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/CircularDependencyChecker.java b/proposal/mutant/src/java/common/org/apache/ant/common/util/CircularDependencyChecker.java
old mode 100755
new mode 100644
similarity index 99%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/CircularDependencyChecker.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/util/CircularDependencyChecker.java
index bdea4889c..826282620
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/CircularDependencyChecker.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/util/CircularDependencyChecker.java
@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.util;
+package org.apache.ant.common.util;
import java.util.Stack;
/**
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/CircularDependencyException.java b/proposal/mutant/src/java/common/org/apache/ant/common/util/CircularDependencyException.java
old mode 100755
new mode 100644
similarity index 97%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/CircularDependencyException.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/util/CircularDependencyException.java
index af96186bc..e6d3a2576
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/CircularDependencyException.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/util/CircularDependencyException.java
@@ -51,10 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.util;
-
-import org.apache.ant.common.util.AntException;
-import org.apache.ant.common.util.Location;
+package org.apache.ant.common.util;
/**
* A CircularDependencyException indicates that a circular dependency has
diff --git a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/ConfigException.java b/proposal/mutant/src/java/common/org/apache/ant/common/util/ConfigException.java
old mode 100755
new mode 100644
similarity index 97%
rename from proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/ConfigException.java
rename to proposal/mutant/src/java/common/org/apache/ant/common/util/ConfigException.java
index fd26d211e..adc4413c6
--- a/proposal/mutant/src/java/antcore/org/apache/ant/antcore/util/ConfigException.java
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/util/ConfigException.java
@@ -51,10 +51,7 @@
* information on the Apache Software Foundation, please see
* .
*/
-package org.apache.ant.antcore.util;
-
-import org.apache.ant.common.util.AntException;
-import org.apache.ant.common.util.Location;
+package org.apache.ant.common.util;
/**
* A ConfigException indicates a problem with Ant's configuration or the
diff --git a/proposal/mutant/src/java/common/org/apache/ant/common/util/StringUtils.java b/proposal/mutant/src/java/common/org/apache/ant/common/util/StringUtils.java
new file mode 100644
index 000000000..f04d6c503
--- /dev/null
+++ b/proposal/mutant/src/java/common/org/apache/ant/common/util/StringUtils.java
@@ -0,0 +1,140 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 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.util;
+import java.io.PrintWriter;
+
+import java.io.StringWriter;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * A set of helper methods related to string manipulation.
+ *
+ * @author Stephane Bailliez
+ */
+public final class StringUtils {
+
+ /** the line separator for this OS */
+ public final static String LINE_SEP = System.getProperty("line.separator");
+
+ /**
+ * Convenient method to retrieve the full stacktrace from a given
+ * exception.
+ *
+ * @param t the exception to get the stacktrace from.
+ * @return the stacktrace from the given exception.
+ */
+ public static String getStackTrace(Throwable t) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ t.printStackTrace(pw);
+ pw.flush();
+ pw.close();
+ return sw.toString();
+ }
+
+ /**
+ * Splits up a string into a list of lines. It is equivalent to
+ * split(data, '\n') .
+ *
+ * @param data the string to split up into lines.
+ * @return the list of lines available in the string.
+ */
+ public static List lineSplit(String data) {
+ return split(data, '\n');
+ }
+
+ /**
+ * Splits up a string where elements are separated by a specific
+ * character and return all elements.
+ *
+ * @param data the string to split up.
+ * @param ch the separator character.
+ * @return the list of elements.
+ */
+ public static List split(String data, int ch) {
+ List elems = new ArrayList();
+ int pos = -1;
+ int i = 0;
+ while ((pos = data.indexOf(ch, i)) != -1) {
+ String elem = data.substring(i, pos);
+ elems.add(elem);
+ i = pos + 1;
+ }
+ elems.add(data.substring(i));
+ return elems;
+ }
+
+ /**
+ * Replace occurrences into a string.
+ *
+ * @param data the string to replace occurrences into
+ * @param from the occurrence to replace.
+ * @param to the occurrence to be used as a replacement.
+ * @return the new string with replaced occurrences.
+ */
+ public static String replace(String data, String from, String to) {
+ StringBuffer buf = new StringBuffer(data.length());
+ int pos = -1;
+ int i = 0;
+ while ((pos = data.indexOf(from, i)) != -1) {
+ buf.append(data.substring(i, pos)).append(to);
+ i = pos + from.length();
+ }
+ buf.append(data.substring(i));
+ return buf.toString();
+ }
+
+}
+