Preserve Original Filenames in Groovy Ant Task

人走茶凉 提交于 2019-12-13 06:27:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15511382/preserve-original-filenames-in-groovy-ant-task

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