I have this list of file changes between two git revisions in a variable rolloutChanges
-
<exec command="git diff -–name-only ${box.git_version} ${target.git_version}" outputProperty="rolloutChanges" dir="${dir.scratchpad}" />
I am not sure how this variable should ideally be iterated, may be by preparing it in some other standard format recognizable by phing.
I saw this answer which involves foreach with target - https://stackoverflow.com/a/4459526/351903, but did not get a hold of what is happening there. I could not even run the solution in my setup.
I checked the documentation for fileset but don't see any way in which variables are supported. Also checked this Copy a whole directory with phing
Updates
I understood the usage of foreach and target, and put it in my code, after the exec command -
<exec command="git diff --name-only ${box.git_version} ${target.git_version}" outputProperty="rolloutChanges" dir="${dir.scratchpad}/${dir.subdir}" />
<foreach list="${rolloutChanges}" param="eachFileToRollout" target="buildlang" />
And I have the following task -
<target name="buildlang">
<echo>Overwriting ${eachFileToRollout} </echo>
</target>
Now, the rolloutChanges variable contains a string, something like this (taken from console) -
app/webroot/openx/www/delivery/file1.php
app/webroot/openx/www/delivery/file2.php
So, the output of the target block is this (Notice that there is only one element in the list, Overwriting gets printed only once) -
Overwriting app/webroot/openx/www/delivery/file1.php
app/webroot/openx/www/delivery/file2.php
Is there a native phing way of putting the output of the exec into a list, such that as many elements are created as there are files in the output?
To make your foreach solution work, you need to specify the delimiter, which is a newline in your case.
ForeachTask provides a delimiter
attribute (default value: ,
). Set it to
in order to separate the string at Unix-style newlines. The platform-independent value would be ${line.separator}
.