Ant : Process the files in the subfolder using tas

2019-03-04 14:19发布

问题:

I have a folder structure as follows

+ [BASE]
+++ [DIR 1]
++++++ File.zip
+++ [DIR 2]
++++++ File.zip
....

I have a build.xml in BASE. I need to have a task where I can unzip the File.zip in each DIR* . I needed it to be such that a new DIR added also should be handled.

I tried the following, in order to get the dir names but don't know how to proceed further

<dirset id="contents" dir="." />
<property name="prop.contents" refid="contents"/>

回答1:

You could try an embedded groovy script. Something like this:

<target name="unzip">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <fileset id="zips" dir="." includes="**/*.zip"/>

    <groovy>
        project.references.zips.each { fileResource ->
            def file = new File(fileResource.toString())

            ant.unzip(src:file, dest:file.parent)
        }
    </groovy>
</target>


标签: ant