You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Maxime FAZENTIEUX <m....@epro.fr> on 2005/03/01 11:46:35 UTC
loop with ant
Hi,
I want to execute ant tasks in a loop :
The Java class :
public class TacheEssai extends Task{
public void execute() throws BuildException{
Project projet = this.getProject();
for(int i=0;i<5;i++){
projet.setUserProperty("num_tmp",""+i);
projet.executeTarget("ecrit");
}
}
}
File build.xml :
<taskdef name="boucle" classname="tache.ant.TacheEssai" classpath="${path_tache}" />
<target name="ecrit">
<property name="${num_test}" value="${num_tmp}"/>
<echo message="num_test = ${num_test}"/>
</target>
<target name="debut">
<boucle/>
</target>
<target name="test" depends="debut">
<echo message="Fin exécution"/>
</target>
PROBLEM : The property num_tmp is always to 0 !
How do I can do to change the num_tmp ?
Thanks
Re: loop with ant
Posted by James Fuller <ji...@ruminate.co.uk>.
Maxime FAZENTIEUX wrote:
>Hi,
>
>I want to execute ant tasks in a loop :
>
>The Java class :
>
>public class TacheEssai extends Task{
> public void execute() throws BuildException{
> Project projet = this.getProject();
> for(int i=0;i<5;i++){
> projet.setUserProperty("num_tmp",""+i);
> projet.executeTarget("ecrit");
> }
> }
>}
>
>
>File build.xml :
>
><taskdef name="boucle" classname="tache.ant.TacheEssai" classpath="${path_tache}" />
>
><target name="ecrit">
> <property name="${num_test}" value="${num_tmp}"/>
> <echo message="num_test = ${num_test}"/>
></target>
>
><target name="debut">
> <boucle/>
></target>
>
><target name="test" depends="debut">
> <echo message="Fin exécution"/>
></target>
>
>
>PROBLEM : The property num_tmp is always to 0 !
>
>How do I can do to change the num_tmp ?
>
>
with such a procedural approach...why not just use Ant-Contrib's <for/>
or <foreach/> along with their <variable/> ? also no need for a custom
java task...you could easily script this using <script/> with
javascript, and if it must be in taskform use <scriptdef/>
HTH, Jim Fuller
btw: I think .setNewProperty or .setProperty methods on project object
is more appropriate....
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: loop with ant
Posted by Yves Martin <yv...@elca.ch>.
"Maxime FAZENTIEUX" <m....@epro.fr> writes:
> PROBLEM : The property num_tmp is always to 0 !
>
> How do I can do to change the num_tmp ?
Properties in Ant are immutable (in normal usage)
You can use 'Project.setProperty' instead of 'Project.setUserProperty' as a
work-around.
Maybe the use of Ant Contrib loop/for task may help you.
Regards
--
Yves Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org