You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Johan Vromans CPWR <jo...@nl.compuware.com> on 2004/04/28 12:11:31 UTC

Getting task info in build listener

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?

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


RE: How to set ant debugging on from java api call?

Posted by sudip barat <sb...@cisco.com>.
Hi Matt,
          thanks for the pointer ! BuidListener works great with
event.getPriority() . I am able to output debug info now 


-----Original Message-----
From: Matt Benson [mailto:gudnabrsam@yahoo.com] 
Sent: Thursday, April 29, 2004 11:56 AM
To: Ant Users List
Subject: Re: How to set ant debugging on from java api call?


--- sudip barat <sb...@cisco.com> wrote:
> 
> Hi
> I am invoking ant from my java program and writing
> the output in a file . I
> want to know which property I need to set in project
> or which api call I
> need to make  to turn on the debug (equivalent to
> running  ant -debug from
> command prompt )? Or is there a project level
> property I can set in my
> build.xml  to make it that way ?

The debuglevel is set per listener rather than on the
whole Project... so you would attach a BuildListener
set up as you need it.  You should be able to
configure an oata.DefaultLogger for your purposes.

-Matt


	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

---------------------------------------------------------------------
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


Re: How to set ant debugging on from java api call?

Posted by Matt Benson <gu...@yahoo.com>.
--- sudip barat <sb...@cisco.com> wrote:
> 
> Hi 
> I am invoking ant from my java program and writing
> the output in a file . I
> want to know which property I need to set in project
> or which api call I
> need to make  to turn on the debug (equivalent to
> running  ant -debug from
> command prompt )? Or is there a project level
> property I can set in my
> build.xml  to make it that way ?

The debuglevel is set per listener rather than on the
whole Project... so you would attach a BuildListener
set up as you need it.  You should be able to
configure an oata.DefaultLogger for your purposes.

-Matt


	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

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


How to set ant debugging on from java api call?

Posted by sudip barat <sb...@cisco.com>.
Hi 
I am invoking ant from my java program and writing the output in a file . I
want to know which property I need to set in project or which api call I
need to make  to turn on the debug (equivalent to running  ant -debug from
command prompt )? Or is there a project level property I can set in my
build.xml  to make it that way ?

Thx
       sb


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


Re: Getting task info in build listener

Posted by Peter Reilly <pe...@corvil.com>.
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