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-ffa450edef68master
| @@ -54,11 +54,13 @@ | |||||
| package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import java.io.OutputStream; | import java.io.OutputStream; | ||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.io.IOException; | |||||
| /** | /** | ||||
| * Logs standard output and error of a subprocess to the log system of ant. | * 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)); | new LogOutputStream(task, errlevel)); | ||||
| } | } | ||||
| public void stop() { | |||||
| super.stop(); | |||||
| try { | |||||
| getErr().close(); | |||||
| getOut().close(); | |||||
| } catch (IOException e) { | |||||
| // plain impossible | |||||
| throw new BuildException(e); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -113,6 +113,20 @@ public class PumpStreamHandler implements ExecuteStreamHandler { | |||||
| try { | try { | ||||
| errorThread.join(); | errorThread.join(); | ||||
| } catch(InterruptedException e) {} | } 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) { | protected void createProcessOutputPump(InputStream is, OutputStream os) { | ||||
| @@ -79,10 +79,10 @@ public class Javac12 extends DefaultCompilerAdapter { | |||||
| attributes.log("Using classic compiler", Project.MSG_VERBOSE); | attributes.log("Using classic compiler", Project.MSG_VERBOSE); | ||||
| Commandline cmd = setupJavacCommand(); | Commandline cmd = setupJavacCommand(); | ||||
| OutputStream logstr = new LogOutputStream(attributes, Project.MSG_WARN); | |||||
| try { | try { | ||||
| // Create an instance of the compiler, redirecting output to | // Create an instance of the compiler, redirecting output to | ||||
| // the project log | // the project log | ||||
| OutputStream logstr = new LogOutputStream(attributes, Project.MSG_WARN); | |||||
| Class c = Class.forName("sun.tools.javac.Main"); | Class c = Class.forName("sun.tools.javac.Main"); | ||||
| Constructor cons = c.getConstructor(new Class[] { OutputStream.class, String.class }); | Constructor cons = c.getConstructor(new Class[] { OutputStream.class, String.class }); | ||||
| Object compiler = cons.newInstance(new Object[] { logstr, "javac" }); | Object compiler = cons.newInstance(new Object[] { logstr, "javac" }); | ||||
| @@ -103,6 +103,13 @@ public class Javac12 extends DefaultCompilerAdapter { | |||||
| } else { | } else { | ||||
| throw new BuildException("Error starting classic compiler: ", ex, location); | throw new BuildException("Error starting classic compiler: ", ex, location); | ||||
| } | } | ||||
| } finally { | |||||
| try { | |||||
| logstr.close(); | |||||
| } catch (IOException e) { | |||||
| // plain impossible | |||||
| throw new BuildException(e); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -86,10 +86,10 @@ public class Javac13 extends DefaultCompilerAdapter { | |||||
| PrintStream err = System.err; | PrintStream err = System.err; | ||||
| PrintStream out = System.out; | 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: | // Use reflection to be able to build on all JDKs >= 1.1: | ||||
| try { | try { | ||||
| PrintStream logstr = | |||||
| new PrintStream(new LogOutputStream(attributes, Project.MSG_WARN)); | |||||
| System.setOut(logstr); | System.setOut(logstr); | ||||
| System.setErr(logstr); | System.setErr(logstr); | ||||
| Class c = Class.forName ("com.sun.tools.javac.Main"); | Class c = Class.forName ("com.sun.tools.javac.Main"); | ||||
| @@ -108,6 +108,7 @@ public class Javac13 extends DefaultCompilerAdapter { | |||||
| } finally { | } finally { | ||||
| System.setErr(err); | System.setErr(err); | ||||
| System.setOut(out); | System.setOut(out); | ||||
| logstr.close(); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -311,14 +311,14 @@ public class Javah extends Task { | |||||
| PrintStream err = System.err; | PrintStream err = System.err; | ||||
| PrintStream out = System.out; | PrintStream out = System.out; | ||||
| PrintStream logstr = | |||||
| new PrintStream(new LogOutputStream(this, Project.MSG_WARN)); | |||||
| try { | try { | ||||
| // Javac uses logstr to change the output stream and calls | // Javac uses logstr to change the output stream and calls | ||||
| // the constructor's invoke method to create a compiler instance | // the constructor's invoke method to create a compiler instance | ||||
| // dynamically. However, javah has a different interface and this | // dynamically. However, javah has a different interface and this | ||||
| // makes it harder, so here's a simple alternative. | // makes it harder, so here's a simple alternative. | ||||
| //------------------------------------------------------------------ | //------------------------------------------------------------------ | ||||
| PrintStream logstr = | |||||
| new PrintStream(new LogOutputStream(this, Project.MSG_WARN)); | |||||
| System.setOut(logstr); | System.setOut(logstr); | ||||
| System.setErr(logstr); | System.setErr(logstr); | ||||
| com.sun.tools.javah.Main main = new com.sun.tools.javah.Main( cmd.getArguments() ); | com.sun.tools.javah.Main main = new com.sun.tools.javah.Main( cmd.getArguments() ); | ||||
| @@ -338,6 +338,7 @@ public class Javah extends Task { | |||||
| } finally { | } finally { | ||||
| System.setErr(err); | System.setErr(err); | ||||
| System.setOut(out); | System.setOut(out); | ||||
| logstr.close(); | |||||
| } | } | ||||
| } | } | ||||