Easy way to modify content of zip file inside scripts. Using Gradle/Groovy
short example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
classpath 'org.zeroturnaround:zt-zip:1.8' | |
classpath 'org.apache.commons:commons-io:1.3.2' | |
} | |
// ---------------------------- | |
import org.apache.commons.io.FileUtils | |
import org.zeroturnaround.zip.ZipUtil | |
/** | |
* | |
* Extract zipFile into directory in temp, then call closure and give this directory as parameter to closure | |
* (closure update this directory), then pack this directory back into ZipFile | |
* Nice method :) */ | |
private void extractZipAndThenPackItBack(File zipFile, Closure closure) { | |
def extractedDirectory | |
try { | |
//Extract | |
extractedDirectory = getTempDir() | |
ZipUtil.unpack(zipFile, extractedDirectory); | |
//Call closure | |
closure.call(extractedDirectory) | |
//Pack result back | |
zipFile.delete() | |
ZipUtil.pack(extractedDirectory, zipFile); | |
} finally { | |
FileUtils.deleteDirectory(extractedDirectory) | |
} | |
} | |
//Sample usage: | |
extractZipAndThenPackItBack(zipFile) { File directoryWhereZipWasExtracted -> | |
//update directory where zip was extracted | |
} |
And here is full sample project: https://bitbucket.org/bugs_/samples/src/default/ZipUpdaterGroovyGradleClosure/