Browse Source

Make sure streams get flushed and closed - otherwise we may be losing

messages sent to the logging system, especially on platforms where
line ends are neither \r nor \n - for example OS/390.

Reported by:	Myron Uecker <uecker@us.ibm.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269339 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
d3ef19b3ff
5 changed files with 40 additions and 5 deletions
  1. +12
    -0
      src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java
  2. +14
    -0
      src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java
  3. +8
    -1
      src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java
  4. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java
  5. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/Javah.java

+ 12
- 0
src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java View File

@@ -54,11 +54,13 @@

package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;

import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;

/**
* Logs standard output and error of a subprocess to the log system of ant.
@@ -79,4 +81,14 @@ public class LogStreamHandler extends PumpStreamHandler {
new LogOutputStream(task, errlevel));
}

public void stop() {
super.stop();
try {
getErr().close();
getOut().close();
} catch (IOException e) {
// plain impossible
throw new BuildException(e);
}
}
}

+ 14
- 0
src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java View File

@@ -113,6 +113,20 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
try {
errorThread.join();
} catch(InterruptedException e) {}
try {
err.flush();
} catch (IOException e) {}
try {
out.flush();
} catch (IOException e) {}
}

protected OutputStream getErr() {
return err;
}

protected OutputStream getOut() {
return out;
}

protected void createProcessOutputPump(InputStream is, OutputStream os) {


+ 8
- 1
src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java View File

@@ -79,10 +79,10 @@ public class Javac12 extends DefaultCompilerAdapter {
attributes.log("Using classic compiler", Project.MSG_VERBOSE);
Commandline cmd = setupJavacCommand();

OutputStream logstr = new LogOutputStream(attributes, Project.MSG_WARN);
try {
// Create an instance of the compiler, redirecting output to
// the project log
OutputStream logstr = new LogOutputStream(attributes, Project.MSG_WARN);
Class c = Class.forName("sun.tools.javac.Main");
Constructor cons = c.getConstructor(new Class[] { OutputStream.class, String.class });
Object compiler = cons.newInstance(new Object[] { logstr, "javac" });
@@ -103,6 +103,13 @@ public class Javac12 extends DefaultCompilerAdapter {
} else {
throw new BuildException("Error starting classic compiler: ", ex, location);
}
} finally {
try {
logstr.close();
} catch (IOException e) {
// plain impossible
throw new BuildException(e);
}
}
}
}

+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java View File

@@ -86,10 +86,10 @@ public class Javac13 extends DefaultCompilerAdapter {
PrintStream err = System.err;
PrintStream out = System.out;

PrintStream logstr =
new PrintStream(new LogOutputStream(attributes, Project.MSG_WARN));
// Use reflection to be able to build on all JDKs >= 1.1:
try {
PrintStream logstr =
new PrintStream(new LogOutputStream(attributes, Project.MSG_WARN));
System.setOut(logstr);
System.setErr(logstr);
Class c = Class.forName ("com.sun.tools.javac.Main");
@@ -108,6 +108,7 @@ public class Javac13 extends DefaultCompilerAdapter {
} finally {
System.setErr(err);
System.setOut(out);
logstr.close();
}
}
}

+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/optional/Javah.java View File

@@ -311,14 +311,14 @@ public class Javah extends Task {
PrintStream err = System.err;
PrintStream out = System.out;

PrintStream logstr =
new PrintStream(new LogOutputStream(this, Project.MSG_WARN));
try {
// Javac uses logstr to change the output stream and calls
// the constructor's invoke method to create a compiler instance
// dynamically. However, javah has a different interface and this
// makes it harder, so here's a simple alternative.
//------------------------------------------------------------------
PrintStream logstr =
new PrintStream(new LogOutputStream(this, Project.MSG_WARN));
System.setOut(logstr);
System.setErr(logstr);
com.sun.tools.javah.Main main = new com.sun.tools.javah.Main( cmd.getArguments() );
@@ -338,6 +338,7 @@ public class Javah extends Task {
} finally {
System.setErr(err);
System.setOut(out);
logstr.close();
}
}



Loading…
Cancel
Save