Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276096 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 21 years ago
parent
commit
1f6115c62f
3 changed files with 23 additions and 9 deletions
  1. +6
    -1
      WHATSNEW
  2. +2
    -8
      src/main/org/apache/tools/ant/taskdefs/Redirector.java
  3. +15
    -0
      src/main/org/apache/tools/ant/util/LazyFileOutputStream.java

+ 6
- 1
WHATSNEW View File

@@ -12,6 +12,11 @@ Fixed bugs:


* <whichresource> failed to load classes correctly. * <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: Other changes:
-------------- --------------


@@ -2668,4 +2673,4 @@ cases.


* The packagelistloc attribute of <javadoc>'s <link> child will be * The packagelistloc attribute of <javadoc>'s <link> child will be
resolved as a file (i.e. it is either absolute or relative to resolved as a file (i.e. it is either absolute or relative to
basedir).
basedir).

+ 2
- 8
src/main/org/apache/tools/ant/taskdefs/Redirector.java View File

@@ -232,7 +232,7 @@ public class Redirector {
errorStream = new LogOutputStream(managingTask, Project.MSG_WARN); errorStream = new LogOutputStream(managingTask, Project.MSG_WARN);
} else { } else {
if (out != null) { if (out != null) {
outputStream = new LazyFileOutputStream(out, append);
outputStream = new LazyFileOutputStream(out, append, true);
managingTask.log("Output redirected to " + out, managingTask.log("Output redirected to " + out,
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
} }
@@ -258,7 +258,7 @@ public class Redirector {
} }


if (error != null) { if (error != null) {
errorStream = new LazyFileOutputStream(error, append);
errorStream = new LazyFileOutputStream(error, append, true);
managingTask.log("Error redirected to " + error, managingTask.log("Error redirected to " + error,
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
} }
@@ -422,15 +422,9 @@ public class Redirector {
inputStream.close(); inputStream.close();
} }


if (outputStream instanceof LazyFileOutputStream) {
((LazyFileOutputStream) outputStream).open();
}
outputStream.close(); outputStream.close();


if (errorStream != outputStream) { if (errorStream != outputStream) {
if (errorStream instanceof LazyFileOutputStream) {
((LazyFileOutputStream) errorStream).open();
}
errorStream.close(); errorStream.close();
} }




+ 15
- 0
src/main/org/apache/tools/ant/util/LazyFileOutputStream.java View File

@@ -33,6 +33,7 @@ public class LazyFileOutputStream extends OutputStream {
private FileOutputStream fos; private FileOutputStream fos;
private File file; private File file;
private boolean append; private boolean append;
private boolean alwaysCreate;
private boolean opened = false; private boolean opened = false;
private boolean closed = false; private boolean closed = false;


@@ -67,8 +68,19 @@ public class LazyFileOutputStream extends OutputStream {
* it. * it.
*/ */
public LazyFileOutputStream(File file, boolean append) { 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.file = file;
this.append = append; this.append = append;
this.alwaysCreate = alwaysCreate;
} }


/** /**
@@ -81,6 +93,9 @@ public class LazyFileOutputStream extends OutputStream {
} }


public synchronized void close() throws IOException { public synchronized void close() throws IOException {
if (alwaysCreate) {
ensureOpened();
}
if (opened) { if (opened) {
fos.close(); fos.close();
} }


Loading…
Cancel
Save