You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by cowwoc <co...@bbs.darktech.org> on 2008/08/19 14:56:19 UTC

Initializing Task variables at taskdef time?

Hi,

This seems like such an obvious use-case but from what I read in this forum
there doesn't seem to be a way to do it... is there a way for me to pass
parameters to my custom task at taskdef (initialization time)?

One obvious use-case is grabbing the classpath used in the taskdef during
the task execution time, but this could pretty much apply to any variable I
want to initialize *once* and reuse anytime the task is invoked. Is this
possible in Ant 1.7?

Thank you,
Gili
-- 
View this message in context: http://www.nabble.com/Initializing-Task-variables-at-taskdef-time--tp19048295p19048295.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Initializing Task variables at taskdef time?

Posted by cowwoc <co...@bbs.darktech.org>.
I think that when I originally posted the question I misunderstood how custom
tasks work. I didn't realize they were re-instantiated multiple times per
build file.

I wanted to add a "forked" attribute to my task (or to any task really) to
enable it to either run inside the same JVM or inside a new JVM. I'm no
longer sure that is worth the headache though so I guess for now I will
simply leave this attribute out.

Gili


evgeny.zislis@gmail.com wrote:
> 
> You can use something like a "presetdef" to set default values for your
> task, and then use the presetdef when calling the task instead of the
> original one. Is this what you want?
> 
> On Tue, Aug 19, 2008 at 3:56 PM, cowwoc <co...@bbs.darktech.org> wrote:
> 
>>
>> Hi,
>>
>> This seems like such an obvious use-case but from what I read in this
>> forum
>> there doesn't seem to be a way to do it... is there a way for me to pass
>> parameters to my custom task at taskdef (initialization time)?
>>
>> One obvious use-case is grabbing the classpath used in the taskdef during
>> the task execution time, but this could pretty much apply to any variable
>> I
>> want to initialize *once* and reuse anytime the task is invoked. Is this
>> possible in Ant 1.7?
>>
>> Thank you,
>> Gili
>> --
>> View this message in context:
>> http://www.nabble.com/Initializing-Task-variables-at-taskdef-time--tp19048295p19048295.html
>> Sent from the Ant - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Initializing-Task-variables-at-taskdef-time--tp19048295p19051702.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Initializing Task variables at taskdef time?

Posted by Evgeny <ev...@gmail.com>.
You can use something like a "presetdef" to set default values for your
task, and then use the presetdef when calling the task instead of the
original one. Is this what you want?

On Tue, Aug 19, 2008 at 3:56 PM, cowwoc <co...@bbs.darktech.org> wrote:

>
> Hi,
>
> This seems like such an obvious use-case but from what I read in this forum
> there doesn't seem to be a way to do it... is there a way for me to pass
> parameters to my custom task at taskdef (initialization time)?
>
> One obvious use-case is grabbing the classpath used in the taskdef during
> the task execution time, but this could pretty much apply to any variable I
> want to initialize *once* and reuse anytime the task is invoked. Is this
> possible in Ant 1.7?
>
> Thank you,
> Gili
> --
> View this message in context:
> http://www.nabble.com/Initializing-Task-variables-at-taskdef-time--tp19048295p19048295.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Re: Initializing Task variables at taskdef time?

Posted by Dominique Devienne <dd...@gmail.com>.
On Tue, Aug 19, 2008 at 7:56 AM, cowwoc <co...@bbs.darktech.org> wrote:
> This seems like such an obvious use-case but from what I read in this forum
> there doesn't seem to be a way to do it... is there a way for me to pass
> parameters to my custom task at taskdef (initialization time)?
>
> One obvious use-case is grabbing the classpath used in the taskdef during
> the task execution time, but this could pretty much apply to any variable I
> want to initialize *once* and reuse anytime the task is invoked. Is this
> possible in Ant 1.7?

No. taskdef only loads the class for the task, and doesn't instantiate
it. Plus every time you execute a task, you are typically running it
using a new instance of the task class every time, so no state carries
over from one invocation to the next, unless you explicitly using
statics. If you need cross-invocation state, put it in a datatype that
you pass by reference to all your task's invocations. --DD

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