Anyhow, I found out about using Groovy Antbuilder tasks, and have been using them to manage zipping / unzipping file sets:
def ant = new AntBuilder(); // create an antbuilder
ant.unzip( src: planZipFile, dest:workingDirName, overwrite:"true")
Then I found I wanted to flatten the output (ie don't reproduce the directory structure). The Apache Ant documentation for the unzip task shows the Ant XML:
<unzip src="apache-ant-bin.zip" dest="${tools.home}">
<patternset>
<include name="apache-ant/lib/ant.jar"/>
</patternset>
<mapper type="flatten"/>
</unzip>
How to add the mapper element?
Well, lots of googling later, I couldn't find an example but I did see the patternset being used. So thanks to that, I found that the Groovy way of expressing the mapper part of this is to add a closure after the call:
def ant = new AntBuilder();
ant.unzip( src: planZipFile, dest:workingDirName, overwrite:"true"){ mapper(type:"flatten")};
So I hope someone finds that useful.
2 comments:
For pattern set please find the example
ant.unzip(src : jarFile, dest: privateClasspath) {
patternset() {
exclude(name: "**/org/eclipse/jetty/continuation/Jetty6Continuation.class")
}
}
Thanks for the post!
If you need to use one of the mappers which doesn't have a <mapper type>, such as <cutdirsmapper dirs="1"/>, you can use something like this:
ant.untar(src: f, dest: target,
compression: 'gzip', failOnEmptyArchive: true, overwrite: true) {cutdirsmapper(dirs: 1)}
Post a Comment