更新时间:2023-12-05 14:21:52
类似这样的事情?
< target name =zip-files>
< taskdef name =groovyclassname =org.codehaus.groovy.ant.Groovyclasspathref =build.path/>
< dirset id =dirsToZipdir =src>
< include name =dir */>
< / dirset>
< groovy>
project.references.dirsToZip.each {
ant.zip(destfile:$ {it} .zip,basedir:it)
}
< / groovy>
< / target>
如果发现groovy任务能够迭代文件集或dirset是非常有用的功能。
I have the following code:
new AntBuilder().zip( destFile: "${file}.zip" ) {
fileset( dir: srcDir ) {
include( name:pattern )
}
}
In this example I'd like ant to create a zip with the same name as the original file, but with a .zip added to the end. Is there a way to do this without knowing the original file's name ahead of time in ant? I'd like to be able to do the same thing with other ant tasks as well.
To put it another way, I'd like the filename to become whatever "pattern" resolves to for each file.
Something like this?
<target name="zip-files">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<dirset id="dirsToZip" dir="src">
<include name="dir*"/>
</dirset>
<groovy>
project.references.dirsToZip.each {
ant.zip(destfile: "${it}.zip", basedir: it)
}
</groovy>
</target>
If find the groovy task's ability to iterate thru a fileset or dirset a very useful feature.