On 12/01/10 1:26 PM, René Gröschke wrote:
Hi there,
I know there was a discussion going on to improve the file handling of
gradle including archive extracting stuff. Is there already an easy
built-in way to extract a tar.gz and/or a "normal" zip file? This is
an exercise for the copyspec isn't it? Unfortunately I'm not familiar
with this copyspec stuff yet.
You can use the zipFile() and tarFile() methods. These return FileTree
impls which will iterate over the contents of a ZIP or TAR file,
respectively.
Then, depending on what you want to do, you can:
- Use the FileTree API to, for example, iterate over each file in the
ZIP/TAR:
zipFile('someFile.zip').each { file -> println "doing something with
$file" }
zipFile('someFile.zip').visit { fte -> println "visiting entry $fte.name" }
- Pass the tree to the Copy task or method to extract the ZIP/TAR into a
directory:
copy {
from zipFile('someFile.zip')
into 'some-dir'
}
- Pass the tree to any task which accepts a
FileTree/FileCollection/Iterable<File>:
compile {
source zipFile('someFile.zip')
}
jar {
from zipFile('someFile.zip')
}
There's some material on this stuff in the user guide in trunk. I would
link to it, but the nightly build broke last night, so the latest user
guide isn't up available at the moment.
Finally, you should note, that the tarFile() method doesn't deal with
compressed tar files (ie .tar.gz) at the moment. It will be able to
before the 0.9 release.
--
Adam Murdoch
Gradle Developer
http://www.gradle.org
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email