Skip to content

Instantly share code, notes, and snippets.

@Gazer
Created August 25, 2015 15:02
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 Gazer/defeab06646fefc48033 to your computer and use it in GitHub Desktop.
Save Gazer/defeab06646fefc48033 to your computer and use it in GitHub Desktop.
// Creates a copy of the git tree into target directory to be included on the final EAR
// Use zipfileset(dir: "${warDest}/src", prefix: 'src') on your ant.ear task.
target(generateSourceCode: "Generates a src copy") {
depends(defineContextRoot)
ProcessBuilder ps=new ProcessBuilder("/usr/bin/git", "ls-tree", "--name-only", "-r", "HEAD");
def dir = "${projectTargetDir}/src"
new File(dir).mkdirs();
ps.redirectErrorStream(true);
Process pr = ps.start();
def reader = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
File source = new File(line)
File destination = new File("${dir}/${line}")
destination.parentFile.mkdirs()
source?.withInputStream {
destination << it
}
}
pr.waitFor();
reader.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment