You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Alexey Solofnenko <al...@mdli.com> on 2002/05/07 02:35:43 UTC

RE: Integrating Ant into another tool - How do I get around Syste m.exit(0) call in Main.start()?

Hello,

  this is what I did to disable System.exit() in my test application:

 // just to keep track of return codes. You can use SecurityException itself
  public class ExitException extends SecurityException {
    public int rc; 
    ExitException(int rc) {
      super(EXIT_MSG);
      this.rc=rc;
    }
  }

  public static void main(String[] args) throws Throwable {
    SecurityManager oldManager=System.getSecurityManager();
    System.setSecurityManager(new SecurityManager() {
      public void checkExit(int status) { throw new ExitException(status);}
      public void checkPermission(Permission perm, Object context) {}
      public void checkPermission(Permission perm) {}
    });
    int rc=0;
    try {
      some.class.Main(args);
    }
    catch (ExitException ex) {
       if (ex.rc!=0) rc=ex.rc;
    }
    try {
      some.other.class.Main(args);
    }
    catch (ExitException ex) {
       if (ex.rc!=0) rc=ex.rc;
    }    System.setSecurityManager(oldManager);
    System.exit(rc);
  }

Sincerely,
  Alexey Solofnenko.

--
{ http://trelony.cjb.net/   } Alexey N. Solofnenko
{ http://www.inventigo.com/ } Inventigo LLC
Pleasant Hill, CA (GMT-8 usually)



-----Original Message-----
From: Mark Reid [mailto:mark.reid@proxima-tech.com]
Sent: Monday, May 06, 2002 5:28 PM
To: Ant Developers List
Subject: Integrating Ant into another tool - How do I get around
System.exit(0) call in Main.start()?


Hi,

I'm currently writing a web front end for building a product and would like
to integrate Ant into it. Everything was going along fine until I tried
calling the Main.start(...) method from inside a .jsp. When completed,
Main.start(...) calls System.exit(0), taking down Tomcat with it.

I've found references to this problem on the web
(http://www.mail-archive.com/ant-dev@jakarta.apache.org/msg10570.html) so it
looks like it's been discussed here before. That post quotes the docs
saying:

    * If you integrating Ant into some other tool, this is not the class
     * to use as an entry point. Please see the source code of this
     * class to see how it manipulates the Ant project classes.

This is what I'm doing at the moment but to save me some painful mistakes I
was wondering if anyone has done this before and would be willing to give me
some tips. It's important that I be able to hook up a listener to the
project being run.

Thanks in advance,

Mark Reid


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Integrating Ant into another tool - How do I get around System.exit(0) call in Main.start()?

Posted by Mark Reid <ma...@proxima-tech.com>.
Thanks for the tip Alexey,

At the moment I'm trying to set up my own Project instance within my
application and run it without having to reset the SecurityManager. I'll
definitely keep your suggestion in mind though.

I've took what I needed out of Main.runBuild(...) and used it in my .jsp and
tried using org.apache.tools.ant.XmlLogger as the listener. I couldn't copy
it wholesale as there was a call to Project.fireBuildStarted() which is
protected and I'm working in a different package. This meant that XmlLogger
doesn't initialize properly and throws a NullPointerException when it
receives a BuildEvent.

What is the reasoning behind the Project.fireXXX(...) methods being
protected? If they are to remain protected then I think
Project.executeTargets(...) should call it so it doesn't need to be called
outside of org.apache.tools.ant.

Any other thoughts on this?

Regards,

Mark.

> Hello,
>
>   this is what I did to disable System.exit() in my test application:

[..snipped code]

>
> Sincerely,
>   Alexey Solofnenko.
>
> --
> { http://trelony.cjb.net/   } Alexey N. Solofnenko
> { http://www.inventigo.com/ } Inventigo LLC
> Pleasant Hill, CA (GMT-8 usually)
>
> -----Original Message-----
> From: Mark Reid [mailto:mark.reid@proxima-tech.com]
> Sent: Monday, May 06, 2002 5:28 PM
> To: Ant Developers List
> Subject: Integrating Ant into another tool - How do I get around
> System.exit(0) call in Main.start()?
>
>
> Hi,
>
> I'm currently writing a web front end for building a product and would
like
> to integrate Ant into it. Everything was going along fine until I tried
> calling the Main.start(...) method from inside a .jsp. When completed,
> Main.start(...) calls System.exit(0), taking down Tomcat with it.
>
> I've found references to this problem on the web
> (http://www.mail-archive.com/ant-dev@jakarta.apache.org/msg10570.html) so
it
> looks like it's been discussed here before. That post quotes the docs
> saying:
>
>     * If you integrating Ant into some other tool, this is not the class
>      * to use as an entry point. Please see the source code of this
>      * class to see how it manipulates the Ant project classes.
>
> This is what I'm doing at the moment but to save me some painful mistakes
I
> was wondering if anyone has done this before and would be willing to give
me
> some tips. It's important that I be able to hook up a listener to the
> project being run.
>
> Thanks in advance,
>
> Mark Reid
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>