ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpfoe...@ThoughtWorks.com
Subject Re: [RFE] Default Help target on error ?
Date Sat, 29 Jul 2000 02:02:39 GMT

Right now the only System.exit() calls are in main():

    public static void main(String[] args) {
        try {
            new Main(args).runBuild();
            System.exit(0);
        }
        catch(Throwable exc) {
            System.exit(1);
        }
    }

The alternative to this is to not catch the exception at all, which means
you'll get a stack trace for every error, which can be annoying. Or we can
catch the exception and ignore it, which means that ant will always return
an error code of zero, and external scripts won't be able to tell if the
build succeeded or not. (Does anyone know why sun didn't have main() simply
return an int?)

To call Ant from another program you should be able to just call new
Main(args).runBuild(), but right now the constructor for Main is protected.

As for JShell, I thought it implemented its own security manager to trap
calls to System.exit() and handle them. Which version are you using?

Matt Foemmel
ThoughtWorks, Inc.


                                                                                         
                                                    
                    "James Duncan                                                        
                                                    
                    Davidson"            To:     <ant-dev@jakarta.apache.org>      
                                                          
                    <duncan@x180.        cc:                                          
                                                       
                    com>                 Subject:     Re: [RFE] Default Help target on
error ?                                                
                                                                                         
                                                    
                    07/28/00                                                             
                                                    
                    01:42 PM                                                             
                                                    
                    Please                                                               
                                                    
                    respond to                                                           
                                                    
                    ant-dev                                                              
                                                    
                                                                                         
                                                    
                                                                                         
                                                    




on 7/28/00 11:02 AM, Jesse Glick at Jesse.Glick@netbeans.com wrote:

> Stefan Bodewig wrote:
>> <target name="check">
>> <available name="java1.2" classname="java.lang.ThreadLocal" />
>> </target>
>>
>> <target name="dieIfCheckFailed" unless="java1.2">
>> <die message="Need JDK >= 1.2 to work" />
>> </target>

So, I don't see the rest of the xml file here, but I assume that
dieifCheckFailed is on the dependency list somewhere for the main target?

> I like this style...if a command I need for a build to finish simply
> isn't there, I want to build to stop, immediately, with non-zero exit
> status. A <die> task would be trivial to write and I would use it at
> least.

Just don't use System.exit please. Use an AntException or some such that
will rip up the build stack to the start and have the Main catch the
exception, print out the reason, then return.

One of the things on my perpetual "if I had time" list is to go through and
hunt down all the System.exit calls and replace them with non destructive
bail outs. The reason is that why you use Ant inside some other Java
program, it really isn't nice for the System to get yanked out from under
the parent program (as it was the other day when I was playing with
JShell).

.duncan





Mime
View raw message