ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexey Solofnenko <>
Subject [Proposal] adding "keep-going" to ANT.
Date Thu, 26 Jun 2003 20:10:44 GMT

  "keep-going" feature can be very useful, especially in automatic testing.
I have experimented with Project.executeTarget() method to implement this
functionality. It seems like a simple patch. The goal of the modification is
to execute all targets that do not depend on failed targets. If you think
the approach is correct, I can submit a diff patch.

This is the build file I executed (target "b" should be executed even if
target "a" failed, "main" should not be executed):

<?xml version="1.0"?>
<project default="main" basedir=".">
  <target name="a">
    <echo message="A"/>
    <fail message="something is wrong"/>
  <target name="b">
    <echo message="B"/>
  <target name="main" depends="a,b">
    <echo message="main"/>

Build output:

Buildfile: build.xml

     [echo] A
Target 'a' failed.

     [echo] B
Cannot execute 'main' - 'a' was not executed.

D:\tools\apache-ant-1.6alpha\dist\build.xml:5: something is wrong

Total time: 0 seconds

Modified Project.executeTarget() method:
    public void executeTarget(String targetName) throws BuildException {

        // sanity check ourselves, if we've been asked to build nothing
        // then we should complain

        if (targetName == null) {
            String msg = "No target specified";
            throw new BuildException(msg);

        // Sort the dependency tree, and run everything from the
        // beginning until we hit our targetName.
        // Sorting checks if all the targets (and dependencies)
        // exist, and if there is any cycle in the dependency
        // graph.
        Vector sortedTargets = topoSort(targetName, targets);
        Set executed=new HashSet();
        BuildException buildException=null;

        for (Enumeration iter=sortedTargets.elements();
iter.hasMoreElements();) {
            Target curtarget = (Target) iter.nextElement();
            boolean canExecute=true;
            for (Enumeration dep_iter=curtarget.getDependencies();
dep_iter.hasMoreElements();) {
              String dependencyName=((String)dep_iter.nextElement());
              if (!executed.contains(dependencyName)) {
                log(curtarget, "Cannot execute '"+curtarget.getName()+"' -
'"+dependencyName+"' was not executed.", MSG_ERR);
            if (canExecute) {
              try {
              catch (BuildException ex) {
                log(curtarget, "Target '"+curtarget.getName()+"' failed.",
                if (buildException==null) {
                else {
                  log(curtarget, "Extra error: "+ex.getMessage(), MSG_ERR);
            if (curtarget.getName().equals(targetName)) // very strange exit
        if (buildException!=null)
          throw buildException;

- Alexey.

{ } Alexey N. Solofnenko
Pleasant Hill, CA (GMT-8 usually)

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message