mbenson 2004/02/16 11:33:34
Modified: . WHATSNEW
src/main/org/apache/tools/ant/util LazyFileOutputStream.java
src/main/org/apache/tools/ant/taskdefs Redirector.java
Log:
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.
Revision Changes Path
1.544 +6 -1 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.543
retrieving revision 1.544
diff -u -r1.543 -r1.544
--- WHATSNEW 16 Feb 2004 08:36:38 -0000 1.543
+++ WHATSNEW 16 Feb 2004 19:33:33 -0000 1.544
@@ -12,6 +12,11 @@
* <whichresource> 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 @@
* The packagelistloc attribute of <javadoc>'s <link> child will be
resolved as a file (i.e. it is either absolute or relative to
- basedir).
\ No newline at end of file
+ basedir).
1.5 +15 -0
ant/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java
Index: LazyFileOutputStream.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LazyFileOutputStream.java 9 Feb 2004 21:05:38 -0000 1.4
+++ LazyFileOutputStream.java 16 Feb 2004 19:33:34 -0000 1.5
@@ -33,6 +33,7 @@
private FileOutputStream fos;
private File file;
private boolean append;
+ private boolean alwaysCreate;
private boolean opened = false;
private boolean closed = false;
@@ -67,8 +68,19 @@
* 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 synchronized void close() throws IOException {
+ if (alwaysCreate) {
+ ensureOpened();
+ }
if (opened) {
fos.close();
}
1.15 +2 -8
ant/src/main/org/apache/tools/ant/taskdefs/Redirector.java
Index: Redirector.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Redirector.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Redirector.java 9 Feb 2004 21:05:20 -0000 1.14
+++ Redirector.java 16 Feb 2004 19:33:34 -0000 1.15
@@ -232,7 +232,7 @@
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 @@
}
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 @@
inputStream.close();
}
- if (outputStream instanceof LazyFileOutputStream) {
- ((LazyFileOutputStream) outputStream).open();
- }
outputStream.close();
if (errorStream != outputStream) {
- if (errorStream instanceof LazyFileOutputStream) {
- ((LazyFileOutputStream) errorStream).open();
- }
errorStream.close();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]