目前我正在使用shell脚本执行以下操作:
cd myproject1/
ant
cd ..
if grep 'sucessful' myproject/buil.log then move myproject ../backup/today/
等myproject2,myproject3。
如果发生某些错误,项目将保留在当前目录中进行重新处理,但整个过程仍在继续。
我想将此过程迁移到ant构建脚本,但我不知道如何执行此操作。
我看过蚂蚁和次要任务。 Ant看起来更适合这项工作,但我找不到使用ant和move task togheter遍历目录列表的方法,检查ant任务是否完成。
谢谢。
答案 0 :(得分:2)
查看此答案:
running specific target in different ant scripts in different directories
我建议您的子模块构建应该抛出错误,而不是尝试复制日志解析逻辑。
如果这是为了支持部署,也许你应该考虑一个groovy脚本? 更好地支持异常条件:
def ant = new AntBuilder()
scanner = ant.fileScanner {
fileset(dir:".", includes:"test*/build.xml")
}
scanner.each { f ->
try {
ant.ant(antfile:f)
}
catch (e) {
ant.mkdir(dir:"backup")
ant.move(todir:"backup", file:f.parent)
}
}
Groovy具有出色的ANT集成,并且还可以嵌入到您的ANT构建中:
<target name="run">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="buildFiles" dir="." includes="test*/build.xml"/>
<groovy>
project.references.buildFiles.each {
def f = new File(it.toString())
try {
ant.ant(antfile:f)
}
catch(e) {
ant.mkdir(dir:"backup")
ant.move(todir:"backup", file:f.parent)
}
}
</groovy>
</target>
答案 1 :(得分:0)
这些内容可能是您正在寻找的东西:
<target name="compile" >
<javac srcdir="${src.dir}" destdir="${class.dir}" />
</target >
<target name="copy" depends="compile" >
<mkdir dir="${dest.dir}" />
<copy todir="${dest.dir}" overwrite="true">
<fileset dir="${class.dir}" includes="**" />
<fileset dir="${src.dir}" includes="**" />
...
</copy>
</target>