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

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

问题描述


$ b

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

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



换一种说法,我希望文件名成为模式解析为每个文件。

解决方案

类似这样的事情?

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

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

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