You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Kevin Riff <ke...@earthling.net> on 2000/04/04 00:58:36 UTC

How to make the build fail when exec encounters non-zero exit code?

I have a build.xml file which uses the Java task with fork="yes" to
execute JavaCC in an external process. It works great except that if
there's a problem with the grammar files, then Ant reports the exit code
(1, I think) but continues to process the next target. How can I cause
Ant to stop the build process immediately when it encounters a non-zero
exit code?


Re: How to make the build fail when exec encounters non-zero exit code?

Posted by Thomas Haas <th...@softwired-inc.com>.
Hi Kevin

Hack the Java/Exec task. I am having the same problem and addedsome code to
Exec:
Change the execute method to

    public void execute() throws BuildException {
        if (run(command) != 0) {
            throw new BuildException("Exec failed.");
        }
    }

I do not feel ready to contribute this patch, because I feel Java/Exec
should be improved beyond exit on errors:

  1. Use String[] as commandline instead of a String, as the String gets
     parsed Runtime.exec and it would be easier to specify arguments
     containing spaces.
  2. Get rid of antRun on Unix - is there a real need for this?
  3. Move the functionality from Exec to a seperate class to allow tasks not
     inheriting from Exec to spawn processes (like Javadoc and Jikes).
  4. Many more feature like tunable output and a watchdog to kill hanging
     processes.

(I am working on some of the above)

- tom


Kevin Riff wrote:

> I have a build.xml file which uses the Java task with fork="yes" to
> execute JavaCC in an external process. It works great except that if
> there's a problem with the grammar files, then Ant reports the exit code
> (1, I think) but continues to process the next target. How can I cause
> Ant to stop the build process immediately when it encounters a non-zero
> exit code?

--
* Thomas Haas                    <ma...@softwired-inc.com>
* SoftWired AG                   <http://www.softwired-inc.com/>
* Technoparkstr. 1  ***  CH-8005 Zurich  ***  +41-1-4452370