我有以下问题:1.) 我有文件12345678.xml-out和12345678.xml,我希望他们被压缩到12345.zip。问题是我有一个循环,因为在该目录中可以有多个这样的对:
<target>
<groovy>
import java.util.regex.Pattern
import java.util.regex.Matcher
(...)
f.eachFileMatch { it.split("\.")[1].length()==7 } {
(.. do something and then zip)
def ant = new AntBuilder()
ant.zip(
destfile: "C:/temp.zip",
fileset: HERE I NEED A PATTERN MATCH with the GROOVY it variable...
)
}
</groovy>
</target>
2)。一般问题:是否有可能在antBuilder对象中使用groovy变量?
这样的工作吗?
<target>
<groovy>
def ant = new AntBuilder()
def pattern = ~/([0-9]{7}).xml/
def base = new File( '.' )
base.eachFileMatch( pattern ) { f ->
def prefix = ( f.name =~ pattern )[0][1]
ant.zip(
basedir: base,
destfile: "${prefix}.zip",
includes: "${prefix}.xml,${prefix}.xml-out"
)
}
</groovy>
</target>