如何使用 phing 仅将特定文件列表从一个目录复制到另一个目录?

How to copy only a specific list of files from one directory to another using phing?

我在变量 rolloutChanges -

中有两个 git 修订之间的文件更改列表
<exec command="git diff -–name-only ${box.git_version} ${target.git_version}" outputProperty="rolloutChanges" dir="${dir.scratchpad}" />

我不确定理想情况下应该如何迭代这个变量,可能是以 phing 可识别的其他标准格式准备它。

我看到这个答案涉及带有目标的 foreach - ,但没有掌握那里发生的事情。我什至无法 运行 我的设置中的解决方案。

我检查了documentation for fileset but don't see any way in which variables are supported. Also checked this Copy a whole directory with phing

更新

我理解了foreach和target的用法,并把它放在我的代码中,在exec命令之后 -

<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" />

我有以下任务 -

<target name="buildlang">
        <echo>Overwriting ${eachFileToRollout} </echo>
    </target>

现在,rolloutChanges 变量包含一个字符串,类似这样(取自控制台)-

app/webroot/openx/www/delivery/file1.php
app/webroot/openx/www/delivery/file2.php

所以,目标块的输出是这样的(注意列表中只有一个元素,Overwriting 只打印一次)-

Overwriting app/webroot/openx/www/delivery/file1.php 
app/webroot/openx/www/delivery/file2.php

是否有一种原生的 phing 方法可以将 exec 的输出放入列表中,以便创建与输出中的文件一样多的元素?

要使您的 foreach 解决方案有效,您需要指定分隔符,在您的情况下为换行符。

ForeachTask 提供了一个 delimiter 属性(默认值:,)。将它设置为 &#10; 以便在 Unix 风格的换行处分隔字符串。与平台无关的值为 ${line.separator}.