ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vimil Saju <vimils...@yahoo.com>
Subject Re: Custom task to force build success
Date Wed, 18 May 2011 18:22:15 GMT
I am not sure if its a good idea to do System.exit(0), as that will terminate the JVM. 

With ant it is possible to invoke nested builds using the subant task. 

In case of nested builds we may want one of the nested builds to succeed immediately and proceed
with rest of tasks in the outer build.

Using System.exit(0) will terminate both the nested build and the outer build.

--- On Wed, 5/18/11, Carlton Brown <cblistserv@gmail.com> wrote:

> From: Carlton Brown <cblistserv@gmail.com>
> Subject: Re: Custom task to force build success
> To: "Ant Users List" <user@ant.apache.org>
> Date: Wednesday, May 18, 2011, 9:19 AM
> Thanks for the help, guys... Shawn's
> approach gets me closest to where I
> want to be (just need to work on the condition nesting
> now).
> 
> On Wed, May 18, 2011 at 11:29 AM, Shawn Castrianni <
> Shawn.Castrianni@halliburton.com>
> wrote:
> 
> > I didn't have to use a custom logger.  Instead,
> my custom EndTask is this:
> >
> > package com.lgc.btlite;
> >
> > import org.apache.tools.ant.Project;
> > import org.apache.tools.ant.Task;
> >
> > public class EndTask extends Task {
> >  protected String _message = null;
> >
> >  public void execute()
> >  {
> >    if((_message != null) &&
> (_message.length() > 0))
> >      log("\n" +
> _message,Project.MSG_INFO);
> >    getProject().fireBuildFinished(null);
> >    System.exit(0);
> >  }
> >
> >  public void setMessage(String message)
> >  {
> >    _message = message;
> >  }
> > }
> >
> > ---
> > Shawn Castrianni
> >
> > -----Original Message-----
> > From: Matt Benson [mailto:gudnabrsam@gmail.com]
> > Sent: Wednesday, May 18, 2011 10:27 AM
> > To: Ant Users List
> > Subject: Re: Custom task to force build success
> >
> > On Wed, May 18, 2011 at 10:07 AM, Carlton Brown <cblistserv@gmail.com>
> > wrote:
> > > I'm struggling to write a custom task that is
> essentially the opposite
> > > of "fail".   I've seen it
> mentioned on this list before, but never
> > > found a conclusive answer.
> > >
> > > To be successful, a task expressed like this:
> > > <my:win message="You win!" if="${winning}"
> unless="${failing}">
> > >  <!-- ideally, a nested condition would
> be permitted here, if it's
> > > easy to implement --> </my:win>
> > >
> > > The task would halt the build, and I would see
> the following output:
> > > You win!
> > > BUILD SUCCESSFUL
> > > Total time: 2 seconds
> > >
> > > and the exit code would be zero.
> > >
> > > The closest I got was to print the exit message
> and set the exit
> > > status to zero, but I still get this frustrating
> "BUILD FAILED"
> > > message, which is incompatible with the aesthetic
> of winning.
> > >
> > > Help?
> > >
> >
> > Hi, Carlton.  I think that you're going to need
> to provide a custom logger.
> >  I would try:
> >
> > public class FalseFailureSuppressingLogger extends
> > org.apache.tools.ant.DefaultLogger {
> >    public void buildFinished(BuildEvent
> event) {
> >        Throwable error =
> event.getException();
> >        if (error instanceof
> ExitStatusException &&
> > ((ExitStatusException) error).getStatus() == 0) {
> >           
> event.setException(null);
> >        }
> >        try {
> >           
> super.buildFinished(event);
> >        } finally {
> >           
> event.setException(error);
> >        }
> >    }
> >
> > }
> >
> > Then simply use <fail message="You win!" status="0"
> /> in your buildfile.
> >
> > HTH,
> > Matt
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional
> > commands, e-mail: user-help@ant.apache.org
> >
> >
> ----------------------------------------------------------------------
> > This e-mail, including any attached files, may contain
> confidential and
> > privileged information for the sole use of the
> intended recipient.  Any
> > review, use, distribution, or disclosure by others is
> strictly prohibited.
> >  If you are not the intended recipient (or
> authorized to receive information
> > for the intended recipient), please contact the sender
> by reply e-mail and
> > delete all copies of this message.
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
> 

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


Mime
View raw message