使用condition來決定是否執行復制目標。
<project name="demo" default="copy">
<fileset id="failures" dir="target/reports" includes="**/*FAILED.txt"/>
<condition property="failures.found">
<resourcecount refid="failures" when="greater" count="0" />
</condition>
<target name="copy" if="failures.found">
<copy todir="target/failures" overwrite="true">
<fileset id="failures" dir="target/reports"/>
</copy>
</target>
</project>
更新
一個更強大和靈活的解決方案採用了groovy ANT task:
<project name="demo" default="copy">
<path id="build.path">
<pathelement location="/path/to/task/jars/groovy-all-2.1.1.jar"/>
</path>
<target name="copy">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="failures" dir="target/reports" includes="**/*FAILED.txt"/>
<groovy>
project.references.failures.each {
def failFile = new File(it.toString())
def failFolder = new File(failFile.parent)
ant.copy(todir:"target/failures/${failFolder.name}", overwrite:true) {
fileset(dir:failFolder)
}
}
</groovy>
</target>
</project>
這將複製的一切,我已經添加信息爲我的問題結構。給我一個開始的地方,考慮編寫一些代碼來處理它在現有的實用程序... – 2013-03-05 19:53:03
@SteveMiskiewicz我已經更新了我的答案與嵌入式groovy腳本 – 2013-03-05 20:28:41