bodewig 2004/11/02 08:22:28 Modified: src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH Recorder.java RecorderEntry.java Log: merge Revision Changes Path No revision No revision 1.16.2.6 +14 -17 ant/src/main/org/apache/tools/ant/taskdefs/Recorder.java Index: Recorder.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Recorder.java,v retrieving revision 1.16.2.5 retrieving revision 1.16.2.6 diff -u -r1.16.2.5 -r1.16.2.6 --- Recorder.java 28 Jun 2004 07:47:06 -0000 1.16.2.5 +++ Recorder.java 2 Nov 2004 16:22:28 -0000 1.16.2.6 @@ -146,7 +146,15 @@ RecorderEntry recorder = getRecorder(filename, getProject()); // set the values on the recorder recorder.setMessageOutputLevel(loglevel); - recorder.setRecordState(start); + if (start != null) { + if (start.booleanValue()) { + recorder.reopenFile(); + recorder.setRecordState(start); + } else { + recorder.setRecordState(start); + recorder.closeFile(); + } + } recorder.setEmacsMode(emacsMode); } @@ -193,23 +201,12 @@ if (o == null) { // create a recorder entry - try { - entry = new RecorderEntry(name); - - PrintStream out = null; + entry = new RecorderEntry(name); - if (append == null) { - out = new PrintStream( - new FileOutputStream(name)); - } else { - out = new PrintStream( - new FileOutputStream(name, append.booleanValue())); - } - entry.setErrorPrintStream(out); - entry.setOutputPrintStream(out); - } catch (IOException ioe) { - throw new BuildException("Problems creating a recorder entry", - ioe); + if (append == null) { + entry.openFile(false); + } else { + entry.openFile(append.booleanValue()); } entry.setProject(proj); recorderEntries.put(name, entry); 1.11.2.7 +71 -14 ant/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java Index: RecorderEntry.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java,v retrieving revision 1.11.2.6 retrieving revision 1.11.2.7 diff -u -r1.11.2.6 -r1.11.2.7 --- RecorderEntry.java 28 Jun 2004 07:47:06 -0000 1.11.2.6 +++ RecorderEntry.java 2 Nov 2004 16:22:28 -0000 1.11.2.7 @@ -16,8 +16,11 @@ */ package org.apache.tools.ant.taskdefs; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.PrintStream; import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildLogger; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; @@ -28,7 +31,6 @@ * This is a class that represents a recorder. This is the listener to the * build process. * - * @version 0.5 * @since Ant 1.4 */ public class RecorderEntry implements BuildLogger, SubBuildListener { @@ -80,6 +82,7 @@ */ public void setRecordState(Boolean state) { if (state != null) { + flush(); record = state.booleanValue(); } } @@ -93,14 +96,16 @@ public void buildFinished(BuildEvent event) { log("< BUILD FINISHED", Project.MSG_DEBUG); - Throwable error = event.getException(); + if (record && out != null) { + Throwable error = event.getException(); - if (error == null) { - out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL"); - } else { - out.println(StringUtils.LINE_SEP + "BUILD FAILED" - + StringUtils.LINE_SEP); - error.printStackTrace(out); + if (error == null) { + out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL"); + } else { + out.println(StringUtils.LINE_SEP + "BUILD FAILED" + + StringUtils.LINE_SEP); + error.printStackTrace(out); + } } cleanup(); } @@ -145,7 +150,7 @@ String time = formatTime(System.currentTimeMillis() - targetStartTime); log(event.getTarget() + ": duration " + time, Project.MSG_VERBOSE); - out.flush(); + flush(); } @@ -156,7 +161,7 @@ public void taskFinished(BuildEvent event) { log("<<< TASK FINISHED -- " + event.getTask(), Project.MSG_DEBUG); - out.flush(); + flush(); } @@ -191,10 +196,16 @@ * @param level The verbosity level of the message. */ private void log(String mesg, int level) { - if (record && (level <= loglevel)) { + if (record && (level <= loglevel) && out != null) { out.println(mesg); } } + + private void flush() { + if (record && out != null) { + out.flush(); + } + } public void setMessageOutputLevel(int level) { @@ -205,6 +216,7 @@ public void setOutputPrintStream(PrintStream output) { + closeFile(); out = output; } @@ -215,7 +227,7 @@ public void setErrorPrintStream(PrintStream err) { - out = err; + setOutputPrintStream(err); } @@ -254,12 +266,57 @@ * @since 1.6.2 */ public void cleanup() { - out.flush(); - out.close(); + closeFile(); if (project != null) { project.removeBuildListener(this); } project = null; } + + /** + * Initially opens the file associated with this recorder. + * Used by Recorder. + * @param append Indicates if output must be appended to the logfile or that + * the logfile should be overwritten. + * @throws BuildException + * @since 1.6.3 + */ + void openFile(boolean append) throws BuildException { + openFileImpl(append); + } + + /** + * Closes the file associated with this recorder. + * Used by Recorder. + * @since 1.6.3 + */ + void closeFile() { + if (out != null) { + out.close(); + out = null; + } + } + + /** + * Re-opens the file associated with this recorder. + * Used by Recorder. + * @throws BuildException + * @since 1.6.3 + */ + void reopenFile() throws BuildException { + openFileImpl(true); + } + + private void openFileImpl(boolean append) throws BuildException { + if (out == null) { + try { + out = new PrintStream(new FileOutputStream(filename, append)); + } catch (IOException ioe) { + throw new BuildException("Problems opening file using a " + + "recorder entry", ioe); + } + } + } + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]