diff --git a/WHATSNEW b/WHATSNEW index d5e0bfc4a..0dc3f876a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -12,6 +12,11 @@ Fixed bugs: * failed to load classes correctly. +* Redirector exhibited inconsistent behavior with regard to split + output. When sent to file only, files would be created in all + cases; when split file-property, files were only created if + writes were performed. + Other changes: -------------- @@ -2668,4 +2673,4 @@ cases. * The packagelistloc attribute of 's child will be resolved as a file (i.e. it is either absolute or relative to - basedir). \ No newline at end of file + basedir). diff --git a/src/main/org/apache/tools/ant/taskdefs/Redirector.java b/src/main/org/apache/tools/ant/taskdefs/Redirector.java index ed0d1c886..d53e7dc68 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Redirector.java +++ b/src/main/org/apache/tools/ant/taskdefs/Redirector.java @@ -232,7 +232,7 @@ public class Redirector { errorStream = new LogOutputStream(managingTask, Project.MSG_WARN); } else { if (out != null) { - outputStream = new LazyFileOutputStream(out, append); + outputStream = new LazyFileOutputStream(out, append, true); managingTask.log("Output redirected to " + out, Project.MSG_VERBOSE); } @@ -258,7 +258,7 @@ public class Redirector { } if (error != null) { - errorStream = new LazyFileOutputStream(error, append); + errorStream = new LazyFileOutputStream(error, append, true); managingTask.log("Error redirected to " + error, Project.MSG_VERBOSE); } @@ -422,15 +422,9 @@ public class Redirector { inputStream.close(); } - if (outputStream instanceof LazyFileOutputStream) { - ((LazyFileOutputStream) outputStream).open(); - } outputStream.close(); if (errorStream != outputStream) { - if (errorStream instanceof LazyFileOutputStream) { - ((LazyFileOutputStream) errorStream).open(); - } errorStream.close(); } diff --git a/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java b/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java index 200a81afb..e3887b2ee 100644 --- a/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java +++ b/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java @@ -33,6 +33,7 @@ public class LazyFileOutputStream extends OutputStream { private FileOutputStream fos; private File file; private boolean append; + private boolean alwaysCreate; private boolean opened = false; private boolean closed = false; @@ -67,8 +68,19 @@ public class LazyFileOutputStream extends OutputStream { * it. */ public LazyFileOutputStream(File file, boolean append) { + this(file, append, false); + } + + /** + * Creates a stream that will eventually write to the file with + * the given name, optionally append to instead of replacing + * it, and optionally always create a file (even if zero length). + */ + public LazyFileOutputStream(File file, boolean append, + boolean alwaysCreate) { this.file = file; this.append = append; + this.alwaysCreate = alwaysCreate; } /** @@ -81,6 +93,9 @@ public class LazyFileOutputStream extends OutputStream { } public synchronized void close() throws IOException { + if (alwaysCreate) { + ensureOpened(); + } if (opened) { fos.close(); }