Permalink
Browse files

FIX #1: Include in-files automatically

  • Loading branch information...
1 parent fbb79cd commit 4b37b330ffcbb2f0e6285e92624a784a7a69dbea @KnisterPeter committed Jun 12, 2012
@@ -56,14 +56,19 @@ public OutputStream zip(File base, String[] includedFiles, String processor, Str
File temp = File.createTempFile("maven-smaller", ".dir");
temp.delete();
temp.mkdirs();
- writeManifest(temp, processor, in, out);
+ Manifest manifest = writeManifest(temp, processor, in, out);
try {
for (String includedFile : includedFiles) {
logger.debug("Adding " + includedFile + " to zip");
File target = new File(temp, includedFile);
target.getParentFile().mkdirs();
FileUtils.copyFile(new File(base, includedFile), target);
}
+ for (String included : manifest.getTasks().get(0).getIn()) {
+ File target = new File(temp, included);
+ target.getParentFile().mkdirs();
+ FileUtils.copyFile(new File(base, included), target);
+ }
Zip.zip(baos, temp);
} finally {
if (!debug) {
@@ -79,9 +84,11 @@ public OutputStream zip(File base, String[] includedFiles, String processor, Str
}
}
- private void writeManifest(File temp, String processor, String in, String out) throws ExecutionException {
+ private Manifest writeManifest(File temp, String processor, String in, String out) throws ExecutionException {
try {
- new ObjectMapper().writeValue(new File(temp, "MAIN.json"), new Manifest(new Task(processor, in, out)));
+ Manifest manifest = new Manifest(new Task(processor, in, out));
+ new ObjectMapper().writeValue(new File(temp, "MAIN.json"), manifest);
+ return manifest;
} catch (IOException e) {
throw new ExecutionException("Failed to write manifest", e);
}
@@ -40,6 +40,7 @@ public void debug(String message) {
new File(tempIn, "a.test").createNewFile();
new File(tempIn, "dir/b.test").createNewFile();
new File(tempIn, "dir/dir/c.test").createNewFile();
+ new File(tempIn, "in").createNewFile();
OutputStream out = util.zip(tempIn, new String[] { "a.test", "dir/b.test", "dir/dir/c.test" }, "processor", "in", "out");
ByteArrayInputStream in = new ByteArrayInputStream(((ByteArrayOutputStream) out).toByteArray());
@@ -48,6 +49,7 @@ public void debug(String message) {
assertThat(new File(tempOut, "a.test").exists(), is(true));
assertThat(new File(tempOut, "dir/b.test").exists(), is(true));
assertThat(new File(tempOut, "dir/dir/c.test").exists(), is(true));
+ assertThat(new File(tempOut, "in").exists(), is(true));
FileUtils.deleteDirectory(tempIn);
FileUtils.deleteDirectory(tempOut);

0 comments on commit 4b37b33

Please sign in to comment.