Skip to content

Instantly share code, notes, and snippets.

@simonharrer
Created June 20, 2012 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonharrer/2959490 to your computer and use it in GitHub Desktop.
Save simonharrer/2959490 to your computer and use it in GitHub Desktop.
Extracts zip files recursively to enable deep comparison of zips within zip files.
/**
* Extracts zip files recursively (zips within zip files too).
*/
class RecursiveUnzipper {
public static void main(String[] args) {
if(args != 3){
println "Usage: TARGET LEFT RIGHT"
}
String left = args[1]
String right = args[2]
String target = args[0]
new RecursiveUnzipper().extractZipsForComparison(target, left, right)
}
final AntBuilder ant = new AntBuilder()
void extractZipsForComparison(String target, String left, String right) {
String targetLeft = "$target/left"
String targetRight = "$target/right"
ant.delete dir: target
ant.mkdir dir: target
ant.mkdir dir: targetLeft
ant.mkdir dir: targetRight
ant.copy file: left, todir: targetLeft
ant.copy file: right, todir: targetRight
extractRecursively(targetLeft)
extractRecursively(targetRight)
}
void extractRecursively(String path) {
File file = new File(path)
file.eachFileRecurse { currentFile ->
if(currentFile.isDirectory()) {
extractRecursively(currentFile.absolutePath)
} else if(currentFile.absolutePath.endsWith(".zip") || currentFile.absolutePath.endsWith(".jar")){
String targetPath = currentFile.parent + "/" + currentFile.name + ".dir/"
ant.mkdir dir: targetPath
ant.unzip(src: currentFile, dest: targetPath)
ant.delete(file: currentFile)
extractRecursively(targetPath)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment