Created
June 20, 2012 11:43
-
-
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.
This file contains hidden or 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
/** | |
* 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