在 Groovy Ant 任务中保留原始文件名 [英] Preserve Original Filenames in Groovy Ant Task

查看:28
本文介绍了在 Groovy Ant 任务中保留原始文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

new AntBuilder().zip( destFile: "${file}.zip" ) {
        fileset( dir: srcDir ) {
            include( name:pattern )
        }
    }

在这个例子中,我希望 ant 创建一个与原始文件同名的 zip,但在末尾添加了 .zip. 有没有办法在不知道的情况下做到这一点在ant中提前原始文件的名称?我也希望能够对其他蚂蚁任务做同样的事情.

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.

推荐答案

类似的事情?

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

如果发现 groovy 任务能够遍历文件集或目录集,这是一个非常有用的功能.

If find the groovy task's ability to iterate thru a fileset or dirset a very useful feature.

这篇关于在 Groovy Ant 任务中保留原始文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆