Move a ant dir project after the ant or subant task completes

送分小仙女□ 提交于 2019-12-08 10:11:54

问题


Currently i'm using a shell script to do the following:

cd myproject1/
ant
cd ..
if grep 'sucessful' myproject/buil.log then move myproject ../backup/today/

And so on for myproject2, myproject3.

If some error happens, the project stay in the current dir to be reprocessed but the whole process continues.

I want to migrate this process to an ant build script but i have no clue on how to do this.

I have looked at ant and subant tasks. Ant looks more suitable to the job but i can't find a way to loop through a directory list using ant and move task togheter, checking if the ant task completes or not.

Thank you.


回答1:


Checkout this answer:

running specific target in different ant scripts in different directories

I recommend that your submodule builds should throw an error rather than try and duplicate the log parsing logic.

Update

If this is designed to support deployment, perhaps you should consider a groovy script? Would better support exception conditions:

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 has excellent ANT integration and can also be embedded within your ANT build:

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



回答2:


Something along these lines may be what you're looking for :

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


来源:https://stackoverflow.com/questions/10507626/move-a-ant-dir-project-after-the-ant-or-subant-task-completes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!