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: How to set new property in custom task to be available to the nexted tasks inside it?
Date Fri, 02 Jul 2004 12:09:31 GMT
You need to upgrade to ant 1.6.* for your example to
work correctly.

Also note that you will need to use Project#setProperty for
your example to iterator over the different values of
the property as setNewProperty enforces the property
is imutable feature of ant.

You should look at the <foreach> or (for ant 1.6.*) <for> tasks
from ant-contrib. The for task in particular does exactly what
you want your task to do (using macrodef style attributes instead
of properties).

<target name="token" xmlns:ac="antlib:net.sf.antcontrib">
    <ac:for list="sharad,rajesh,praveen" param="token">
       <ac:sequential>
         <echo message="token is @{token}"/>
      </ac:sequential>
   </ac:for>
<target>

Peter

Sharad wrote:

>Hi,
>
>I want to create a custom task which would execute the tasks inside it
>iteratively. For example I want a custom task "tokenizer" as follows :
>
><tokenizer delemeter="," inputstring="sharad,rajesh,praveen">
>	<echo message="${tokenextracted}"/>
></tokenizer>
>
>This tokenizer task should tokenize the inputstring using the specified
>delemeter and should execute the tasks inside it with each time value of
>property "tokenextracted" set to the token (i.e. sharad and rajesh and then
>praveen). Irrespective of what are the nested tasks inside the tokenizer
>task, all the tasks should be executed first time with the property
>"tokenextracted" set to the token 'sharad', then all the tasks are executed
>again with the value set to 'rajesh' and so on.
>
>Attached is the custom task I tried. In the custom task, I tried to add/set
>the property ${testing} in the execute method, so that this property can be
>used in the nested tasks inside the tokenizer task. But it didn't work.
>Following is my contents in one of the target of build.xml file using my
>custom task "tokenizer":
>
><typedef name="mytask" classname="tokenizer" classpath="mylib"
>loaderref="classes"/>
><mytask>
>	<echo message="Value inside = ${testing}"/>
></mytask>
><echo message="Value outside = ${testing}"/>
>
>
>
>The output I got is as follows :
>
>Value inside = {testing}
>Value outside = mytestingvalue
>
>
>When I did a setNewProperty("testing","mytestingvalue") in the execute()
>method of the custom task, the property is available to the tasks after this
>but not to the tasks nested inside this task.
>
>Can anyone please help me how to set the new property in my custom task so
>that it should be available to the tasks inside my task.
>
>Thanks and Regards,
>Sharad.
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>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