You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "Nikhil R. Deshpande" <ni...@flashmail.com> on 2001/02/02 11:00:59 UTC

Fork implementation of task [was Re: Problem with task]

Hi,

While stepping through the code for ANTLR task, following
observation was made:

Whatever the value of fork flag, Execute.execute() is always
used to invoke antlr.Tool class.

According to my understanding, the Execute.execute() method 
invokes a external program, in this case it is the java program.
This means that the antlr.Tool class will always be run
outside of the ant VM, regardless of the fork attrib value.
Is this correct?

Is this the correct behavior for fork? (I guess not).
I guess the reason for not invoking the antlr.Tool.main method
directly through the code (i.e. using Execute even if fork is
false) is that antlr.Tool calls System.exit() at multiple places
and not just in its main().
Is this correct (or are there any other reasons?)

I suggest:
- Removing the fork attribute (as the implementation is
  inconsistent with what it promises to do, particularly
  for fork=false)
or
- At least documenting this behavior (saying forking will
  be done always).

Which patch should I provide?

One more suggestion:
To avoid the situation like this (i.e. when classes running
through ant tasks call System.exit()), why not have ant's own
security manager with the permission for exitVM disabled?
and catch the resulting SecurityException?
(What impact will this have on other tools and IDEs which
rely on or use ant?)

Comments?

With regards,
 Nikhil

PS:
1. Many tasks support fork attribute; is there a guideline
or something which says use Execute class when forking
and use xyz when not forking?
2. What are the reasons ant needs its own class loader
AntClassLoader?

----- Original Message -----
From: "Stefan Bodewig" <bo...@apache.org>
To: <an...@jakarta.apache.org>
Sent: Wednesday, January 31, 2001 8:50 PM
Subject: Re: Problem with <antlr> task


> NIkhil R. Deshpande <ni...@flashmail.com> wrote:
> 
> > Hi,
> > 
> > When I put antlr.jar in %ANT_HOME%\lib directory and run
> > ant, I get following exception:
> > 
> >     java.lang.NoClassDefFoundError: antlr/Tool
> > 
> 
> but not if you use fork="no", right?
> 
> > But if I put antlr.jar in CLASSPATH before running ant, then
> > everything works ok.
> 
> When forking of a separate VM, <antlr> doesn't specify a classpath at
> all, thus using the setting for CLASSPATH from your environment which
> is not altered by ant.bat.



Re: Fork implementation of task [was Re: Problem with task]

Posted by Jesse Glick <Je...@netbeans.com>.
"Nikhil R. Deshpande" wrote:
> [snip]
> One more suggestion:
> To avoid the situation like this (i.e. when classes running
> through ant tasks call System.exit()), why not have ant's own
> security manager with the permission for exitVM disabled?
> and catch the resulting SecurityException?
> (What impact will this have on other tools and IDEs which
> rely on or use ant?)

Can speak for NetBeans as an example: it would likely cause problems.
But if a container is permitted to substitute its own implementation,
that would be fine. E.g.:

public interface ExitTrapper {
    int FALL_THROUGH_CODE = Integer.MIN_VALUE;
    /** Run r.
      * If it calls System.exit(), trap & return code;
      * else return FALL_THROUGH_CODE */
    int run(Runnable r);
}
// ....
/** register a systemwide System.exit() trapper.
  * @throws SecurityException if double-registered */
public static registerExitTrapper(ExitTrapper t)
    throws SecurityException;
/** @see ExitTrapper.run() */
public static int runTrappingExit(Runnable r);

where Ant provides a default ExitTrapper with a custom SecurityManager
etc., and some container such as an IDE can supply a different one (e.g.
based on its own existing SecurityManager). Could also be extended to
handle redirecting System.* I/O streams while running a thunk, which is
somewhat related.

-Jesse

-- 
Jesse Glick   <ma...@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR