You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2003/07/16 16:14:48 UTC

cvs commit: ant/docs/manual running.html

peterreilly    2003/07/16 07:14:48

  Modified:    src/main/org/apache/tools/ant Project.java Main.java
               src/main/org/apache/tools/ant/taskdefs SubAnt.java
               docs/manual running.html
  Log:
  Add make's keep-going feature into ANT.
  PR: 21144
  Obtained from: Alexey Solofnenko
  
  Revision  Changes    Path
  1.145     +93 -8     ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.144
  retrieving revision 1.145
  diff -u -r1.144 -r1.145
  --- Project.java	8 Jul 2003 00:26:38 -0000	1.144
  +++ Project.java	16 Jul 2003 14:13:53 -0000	1.145
  @@ -65,6 +65,8 @@
   import java.util.Properties;
   import java.util.Stack;
   import java.util.Vector;
  +import java.util.Set;
  +import java.util.HashSet;
   import org.apache.tools.ant.input.DefaultInputHandler;
   import org.apache.tools.ant.input.InputHandler;
   import org.apache.tools.ant.types.FilterSet;
  @@ -208,6 +210,11 @@
       private InputStream defaultInputStream = null;
   
       /**
  +     * Keep going flag
  +     */
  +    private boolean keepGoingMode = false;
  +
  +    /**
        * Sets the input handler
        *
        * @param handler the InputHandler instance to use for gathering input.
  @@ -272,6 +279,7 @@
       public void initSubProject(Project subProject) {
           ComponentHelper.getComponentHelper(subProject)
               .initSubProject(ComponentHelper.getComponentHelper(this));
  +        subProject.setKeepGoingMode(this.isKeepGoingMode());
       }
   
       /**
  @@ -779,6 +787,26 @@
       }
   
       /**
  +     * Sets "keep-going" mode. In this mode ANT will try to execute
  +     * as many targets as possible. All targets that do not depend
  +     * on failed target(s) will be executed.
  +     * @param keepGoingMode "keep-going" mode
  +     * @since Ant 1.6
  +     */
  +    public void setKeepGoingMode(boolean keepGoingMode) {
  +        this.keepGoingMode = keepGoingMode;
  +    }
  +
  +    /**
  +     * Returns the keep-going mode.
  +     * @return "keep-going" mode
  +     * @since Ant 1.6
  +     */
  +    public boolean isKeepGoingMode() {
  +        return this.keepGoingMode;
  +    }
  +
  +    /**
        * Returns the version of Java this class is running under.
        * @return the version of Java as a String, e.g. "1.1"
        * @see org.apache.tools.ant.util.JavaEnvUtils#getJavaVersion
  @@ -1174,13 +1202,70 @@
           // graph.
           Vector sortedTargets = topoSort(targetName, targets);
   
  -        int curidx = 0;
  -        Target curtarget;
  -
  -        do {
  -            curtarget = (Target) sortedTargets.elementAt(curidx++);
  -            curtarget.performTasks();
  -        } while (!curtarget.getName().equals(targetName));
  +        Set succeededTargets = new HashSet();
  +        BuildException buildException = null; // first build exception
  +        for (Enumeration iter = sortedTargets.elements();
  +             iter.hasMoreElements();) {
  +            Target curtarget = (Target) iter.nextElement();
  +            boolean canExecute = true;
  +            for (Enumeration depIter = curtarget.getDependencies();
  +                 depIter.hasMoreElements();) {
  +                String dependencyName = ((String) depIter.nextElement());
  +                if (!succeededTargets.contains(dependencyName)) {
  +                    canExecute = false;
  +                    log(curtarget,
  +                        "Cannot execute '" + curtarget.getName() + "' - '"
  +                        + dependencyName + "' failed or was not executed.",
  +                        MSG_ERR);
  +                    break;
  +                }
  +            }
  +            if (canExecute) {
  +                Throwable thrownException = null;
  +                try {
  +                    curtarget.performTasks();
  +                    succeededTargets.add(curtarget.getName());
  +                } catch (RuntimeException ex) {
  +                    if (!(keepGoingMode)) {
  +                        throw ex; // throw further
  +                    }
  +                    thrownException = ex;
  +                } catch (Throwable ex) {
  +                    if (!(keepGoingMode)) {
  +                        throw new BuildException(ex);
  +                    }
  +                    thrownException = ex;
  +                }
  +                if (thrownException != null) {
  +                    if (thrownException instanceof BuildException) {
  +                        log(curtarget,
  +                            "Target '" + curtarget.getName()
  +                            + "' failed with message '"
  +                            + thrownException.getMessage() + "'.", MSG_ERR);
  +                        // only the first build exception is reported
  +                        if (buildException == null) {
  +                            buildException = (BuildException) thrownException;
  +                        }
  +                    } else {
  +                        log(curtarget,
  +                            "Target '" + curtarget.getName()
  +                            + "' failed with message '"
  +                            + thrownException.getMessage() + "'.", MSG_ERR);
  +                        thrownException.printStackTrace(System.err);
  +                        if (buildException == null) {
  +                            buildException =
  +                                new BuildException(thrownException);
  +                        }
  +                    }
  +                }
  +            }
  +            if (curtarget.getName().equals(targetName)) { // old exit condition
  +                break;
  +            }
  +        }
  +        if (buildException != null) {
  +            throw buildException;
  +        }
       }
   
       /**
  
  
  
  1.87      +9 -0      ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- Main.java	14 Jul 2003 02:53:52 -0000	1.86
  +++ Main.java	16 Jul 2003 14:13:58 -0000	1.87
  @@ -113,6 +113,9 @@
       /** Indicates whether this build is to support interactive input */
       private boolean allowInput = true;
   
  +    /** keep going mode */
  +    private boolean keepGoingMode = false;
  +
       /**
        * The Ant logger class. There may be only one logger. It will have
        * the right to use the 'out' PrintStream. The class must implements the
  @@ -422,6 +425,8 @@
                           "using the -propertyfile argument";
                       throw new BuildException(msg);
                   }
  +            } else if (arg.equals("-k") || arg.equals("-keep-going")) {
  +                keepGoingMode = true;
               } else if (arg.startsWith("-")) {
                   // we don't have any more args to recognize!
                   String msg = "Unknown argument: " + arg;
  @@ -634,6 +639,8 @@
                   project.setUserProperty("ant.file",
                                           buildFile.getAbsolutePath());
   
  +                project.setKeepGoingMode(keepGoingMode);
  +
                   ProjectHelper.configureProject(project, buildFile);
   
                   if (projectHelp) {
  @@ -800,6 +807,8 @@
           msg.append("    -file    <file>              ''" + lSep);
           msg.append("    -f       <file>              ''" + lSep);
           msg.append("  -D<property>=<value>   use value for given property" + lSep);
  +        msg.append("  -keep-going, -k        execute all targets that do not depend" + lSep);
  +        msg.append("                         on failed target(s)" + lSep);
           msg.append("  -propertyfile <name>   load all properties from file with -D" + lSep);
           msg.append("                         properties taking precedence" + lSep);
           msg.append("  -inputhandler <class>  the class which will handle input requests" + lSep);
  
  
  
  1.8       +47 -8     ant/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
  
  Index: SubAnt.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/SubAnt.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SubAnt.java	15 Jul 2003 16:44:27 -0000	1.7
  +++ SubAnt.java	16 Jul 2003 14:14:20 -0000	1.8
  @@ -134,18 +134,57 @@
               target = getOwningTarget().getName();
           }
   */
  +        BuildException buildException = null;
           for (int i = 0; i < count; ++i) {
  -            File directory = null;
  -            File file = new File(filenames[i]);
  -            if (file.isDirectory()) {
  -                if (genericantfile != null) {
  -                    directory = file;
  -                    file = genericantfile;
  +            File file = null;
  +            Throwable thrownException = null;
  +            try {
  +                File directory = null;
  +                file = new File(filenames[i]);
  +                if (file.isDirectory()) {
  +                    if (genericantfile != null) {
  +                        directory = file;
  +                        file = genericantfile;
  +                    } else {
  +                        file = new File(file, antfile);
  +                    }
  +                }
  +                execute(file, directory);
  +            } catch (RuntimeException ex) {
  +                if (!(getProject().isKeepGoingMode())) {
  +                    throw ex; // throw further
  +                }
  +                thrownException = ex;
  +            } catch (Throwable ex) {
  +                if (!(getProject().isKeepGoingMode())) {
  +                    throw new BuildException(ex);
  +                }
  +                thrownException = ex;
  +            }
  +            if (thrownException != null) {
  +                if (thrownException instanceof BuildException) {
  +                    log("File '" + file
  +                        + "' failed with message '"
  +                        + thrownException.getMessage() + "'.", Project.MSG_ERR);
  +                    // only the first build exception is reported
  +                    if (buildException == null) {
  +                        buildException = (BuildException) thrownException;
  +                    }
                   } else {
  -                    file = new File(file, antfile);
  +                    log("Target '" + file
  +                        + "' failed with message '"
  +                        + thrownException.getMessage() + "'.", Project.MSG_ERR);
  +                    thrownException.printStackTrace(System.err);
  +                    if (buildException == null) {
  +                        buildException =
  +                            new BuildException(thrownException);
  +                    }
                   }
               }
  -            execute(file, directory);
  +        }
  +        // check if one of the builds failed in keep going mode
  +        if (buildException != null) {
  +            throw buildException;
           }
       }
   
  
  
  
  1.21      +2 -0      ant/docs/manual/running.html
  
  Index: running.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/running.html,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- running.html	23 Apr 2003 15:57:43 -0000	1.20
  +++ running.html	16 Jul 2003 14:14:38 -0000	1.21
  @@ -95,6 +95,8 @@
       -file    &lt;file&gt;              ''
       -f       &lt;file&gt;              ''
     -D&lt;property&gt;=&lt;value&gt;   use value for given property
  +  -keep-going, -k        execute all targets that do not depend
  +                         on failed target(s)
     -propertyfile &lt;name&gt;   load all properties from file with -D
                            properties taking precedence
     -inputhandler &lt;class&gt;  the class which will handle input requests
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org