ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: Getting task info in build listener
Date Thu, 29 Apr 2004 13:09:36 GMT
Johan Vromans CPWR wrote:

> While playing with build listeners, I noticed that in the taskStarted 
> method I can query event.getTask(), but it will always return an 
> UnknownElement class. What is the appropriate way to get a the real task?

It cannot be done too easily at the moment.
The taskStarted method is called indirectly from Task.perform(), before the
unknown element task gets "configured". "configured" means that
the implemention object associated with the unknown element gets created
and initialized.

One can work around this by doing:

    public void taskStarted(BuildEvent event) {
        Task t = event.getTask();
        if (t instanceof UnknownElement) {
            UnknownElement u = (UnknownElement) t;
            u.maybeConfigure();
            Task n = u.getTask();
            if (n != null) {
                t = n;
            }
        }
        System.out.println("TASK " + t.getTaskName() + " STARTED");
        // This will always print UnknownElement.
        System.out.println("TASK CLASS " + t.getClass().getName());
    }

but this does have the side-effect of "configuring" the object twice.
This has bad consequences.

Peter

>
> E.g.,
>
>   public void taskStarted(BuildEvent event) {
>     Task t = event.getTask();
>     printMessage("TASK " + t.getTaskName() + " STARTED", ...);
>     // This will always print UnknownElement.
>     printMessage("TASK CLASS " + t.getClass().getName(), ...);
>     // So this fails...
>     if ( t instanceof SomeSpecialTask ) ...
>   }
>
> Thanks,
>     Johan
>
> ---------------------------------------------------------------------
> 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