You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Rebhan, Gilbert" <Gi...@huk-coburg.de> on 2005/08/30 15:18:05 UTC
Probs with property expansion in loops
Hi,
i have a problem with properties in <for>
scenario =
Three lists :
- list with all environments that should be served
(loaded outside all loops)
- list with all servers of one environment
(loaded in loop 2)
- list of files to be deleted on those servers
- list of files to be copied to those servers
(generated in the outer loop 1 by a java class,
loaded in loop 3 and loop 4)
Buildfile structure :
...
<!-- property = list with all environments -->
<loadfile property="Lums" srcFile="K:\r1p1l01a1\luminfo.txt" />
<target name="main" depends="doall" />
<target name="doall">
<!-- // start loop 1 // -->
<for list="${Lums}" param="Lum">
<sequential>
<untar src="K:\r1p1l01a1/@{Lum}/transfer/tarfile_@{Lum}.tar"
dest="K:\r1p1l01a1/@{Lum}/serverdata"
overwrite="true" />
<loadfile property="server" srcFile="K:\r1p1l01a1\server_@{Lum}"
/>
<java classname="de. ... .ParseCCLogs" failonerror="true">
<arg value="K:\r1p1l01a1/@{Lum}/transfer" />
<arg value="K:\r1p1l01a1/@{Lum}/temp/updated.txt" />
<arg value="K:\r1p1l01a1/@{Lum}/temp/deleted.txt" />
...
</java>
<!-- files to be deleted on all servers-->
<loadfile property="updatelist"
srcFile="K:\r1p1l01a1/@{Lum}/temp/updated.txt" />
<!-- files to be copied to all servers-->
<loadfile property="deletelist"
srcFile="K:\r1p1l01a1/@{Lum}/temp/deleted.txt" />
<!-- // start loop 2 // -->
<for list="${server}" param="server">
<sequential>
<!-- // start loop 3 // -->
<for list="${deletelist}" param="delfile">
<sequential>
<echo message="Delete file -> @{delfile}" />
</sequential>
</for> <!-- // end loop 3 // -->
<!-- // start loop 4 // -->
<for list="${updatelist}" param="copyfile">
<sequential>
<echo message="Copy file -> @{copyfile}" />
</sequential>
</for> <!-- // end loop 4 // -->
</sequential>
</for> <!-- // end Loop 2 // -->
</sequential>
</for><!-- // end Loop 1 // -->
Problem =
Once the first time the updatelist and deletelist are loaded for the
first environment = @{Lum} it cannot be overwrited for the next
environment in the list ${Lums}.
debugmode says :
Override ignored for property updatelist
Override ignored for property deletelist
when getting into the loop for the second @{Lum}
Question =
How to make that loops work with a list of input properties,
properties expanded correct ?
If for loops are the wrong way, what should i do instead ?
I wanted to avoid several foreach loops.
Any hints ?
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Probs with property expansion in loops
Posted by Dominique Devienne <dd...@gmail.com>.
> From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
> i have a problem with properties in <for>
> <snip/>
> Once the first time the updatelist and deletelist are loaded for the
> first environment = @{Lum} it cannot be overwrited for the next
> environment in the list ${Lums}.
> <snip/>
> How to make that loops work with a list of input properties,
> properties expanded correct ?
> <snip/>
> Any hints ?
This is a recognized problem Gilbert. There has been discussions on how to
address it using property scopes, temp name generator, etc...
Currently, the 'canonical' work around is to use a property name which uses
in part a macro param (a for param in your case) to make the name unique.
This translate into roughly the following code:
<for list="${Lums}" param="Lum">
<sequential>
..
<loadfile property="server-@{Lum}"
srcFile="K:\r1p1l01a1\server_@{Lum}" />
<loadfile property="updatelist-@{Lum}"
srcFile="K:\r1p1l01a1/@{Lum}/temp/deleted.txt" />
...
<for list="${server-@{Lum}}" param="server">
<sequential>
<for list="${deletelist-@{Lum}}" param="delfile">
...
The property name is defined in terms of @{Lum} to make it unique, and
referenced as usual, even though it looks a bit weird, as ${foo-@{Lum}}.
We're hoping to have a better solution for Ant 1.7. --DD
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org