ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@gmail.com>
Subject Re: Custom task to force build success
Date Wed, 18 May 2011 15:26:57 GMT
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


Mime
View raw message