From f1ac33a129d53a04e5198f71e2dba9585a7b829a Mon Sep 17 00:00:00 2001 From: Stefano Mazzocchi Date: Thu, 27 Jan 2000 03:57:32 +0000 Subject: [PATCH] transformed tabs into spaces... BTW, Sam, my tests show the pumping threads slow down the process to half of its original speed, we should use a better method for this... git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267575 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Exec.java | 80 +++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Exec.java b/src/main/org/apache/tools/ant/taskdefs/Exec.java index 0818e8fbe..431d52f2f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Exec.java +++ b/src/main/org/apache/tools/ant/taskdefs/Exec.java @@ -58,9 +58,10 @@ import org.apache.tools.ant.*; import java.io.*; /** - * + * Executes a given command if the os platform is appropriate. * * @author duncan@x180.com + * @author rubys@us.ibm.com */ public class Exec extends Task { @@ -80,19 +81,19 @@ public class Exec extends Task { project.log("Not found in " + os, Project.MSG_VERBOSE); return; } - + String ant = project.getProperty("ant.home"); if (ant == null) throw new BuildException("Property 'ant.home' not found"); String antRun = project.resolveFile(ant + "/bin/antRun").toString(); if (myos.toLowerCase().indexOf("windows") >= 0) antRun = antRun + ".bat"; command = antRun + " " + project.resolveFile(dir) + " " + command; - + run(command); } protected void run(String command) throws BuildException { - + try { // show the command project.log(command, "exec", Project.MSG_VERBOSE); @@ -107,11 +108,12 @@ public class Exec extends Task { } // copy input and error to the output stream - StreamPumper inputPumper = + StreamPumper inputPumper = new StreamPumper(proc.getInputStream(), "exec", project, fos); - StreamPumper errorPumper = + StreamPumper errorPumper = new StreamPumper(proc.getErrorStream(), "error", project, fos); + // starts pumping away the generated output/error inputPumper.start(); errorPumper.start(); @@ -121,7 +123,7 @@ public class Exec extends Task { errorPumper.join(); proc.destroy(); - // close the output file if required + // close the output file if required if (fos != null) fos.close(); // check its exit value @@ -131,8 +133,7 @@ public class Exec extends Task { } } catch (IOException ioe) { throw new BuildException("Error exec: " + command ); - } catch (InterruptedException ex) { - } + } catch (InterruptedException ex) {} } public void setDir(String d) { @@ -154,51 +155,48 @@ public class Exec extends Task { // Inner class for continually pumping the input stream during // Process's runtime. class StreamPumper extends Thread { - private BufferedReader din; + private BufferedReader din; private String name; - private boolean endOfStream = false; - private int SLEEP_TIME = 5; + private boolean endOfStream = false; + private int SLEEP_TIME = 5; private Project project; - private PrintWriter fos; + private PrintWriter fos; - public StreamPumper(InputStream is, String name, Project project, PrintWriter fos) { + public StreamPumper(InputStream is, String name, Project project, PrintWriter fos) { this.din = new BufferedReader(new InputStreamReader(is)); this.name = name; this.project = project; - this.fos = fos; - } - - public void pumpStream() - throws IOException - { - byte[] buf = new byte[BUFFER_SIZE]; - if (!endOfStream) { + this.fos = fos; + } + + public void pumpStream() + throws IOException + { + byte[] buf = new byte[BUFFER_SIZE]; + if (!endOfStream) { String line = din.readLine(); - if (line != null) { - if (fos==null) + if (line != null) { + if (fos == null) project.log(line, name, Project.MSG_INFO); else fos.println(line); - } else { - endOfStream=true; - } - } - } + } else { + endOfStream = true; + } + } + } - public void run() { + public void run() { try { - try { - while (!endOfStream) { - pumpStream(); - sleep(SLEEP_TIME); - } - } catch (InterruptedException ie) { - } + try { + while (!endOfStream) { + pumpStream(); + sleep(SLEEP_TIME); + } + } catch (InterruptedException ie) {} din.close(); - } catch (IOException ioe) { - } - } + } catch (IOException ioe) {} + } } - }