aboutsummaryrefslogtreecommitdiffstats
path: root/util/src
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-05-07 10:21:04 +0000
committerwisberg <wisberg>2003-05-07 10:21:04 +0000
commitd1eab260304ac2487799a75a3c77e29967e6e1b7 (patch)
tree4d703f84514e730bd06434d92705526e48e1c029 /util/src
parentcf457e5880c719638b556cb5c1975b8edaea2d87 (diff)
downloadaspectj-d1eab260304ac2487799a75a3c77e29967e6e1b7.tar.gz
aspectj-d1eab260304ac2487799a75a3c77e29967e6e1b7.zip
envp and snooping error stream in process controller
Diffstat (limited to 'util/src')
-rw-r--r--util/src/org/aspectj/util/FileUtil.java14
-rw-r--r--util/src/org/aspectj/util/LangUtil.java28
2 files changed, 35 insertions, 7 deletions
diff --git a/util/src/org/aspectj/util/FileUtil.java b/util/src/org/aspectj/util/FileUtil.java
index 1cdfc5e0e..89ed1fe4a 100644
--- a/util/src/org/aspectj/util/FileUtil.java
+++ b/util/src/org/aspectj/util/FileUtil.java
@@ -1224,8 +1224,9 @@ public class FileUtil {
*/
public static class Pipe implements Runnable {
private final InputStream in;
- private final OutputStream out;
+ private final OutputStream out;
private final long sleep;
+ private ByteArrayOutputStream snoop;
private long totalWritten;
private Throwable thrown;
private boolean halt;
@@ -1274,7 +1275,11 @@ public class FileUtil {
this.closeOutput = closeOutput;
this.sleep = Math.min(0l, Math.max(60l*1000l, sleep));
}
-
+
+ public void setSnoop(ByteArrayOutputStream snoop) {
+ this.snoop = snoop;
+ }
+
/**
* Run the pipe.
* This halts on the first Throwable thrown or when a read returns
@@ -1289,9 +1294,14 @@ public class FileUtil {
final int MAX = 4096;
byte[] buf = new byte[MAX];
int count = in.read(buf, 0, MAX);
+ ByteArrayOutputStream mySnoop;
while ((halt && finishStream && (0 < count))
|| (!halt && (-1 != count))) {
out.write(buf, 0, count);
+ mySnoop = snoop;
+ if (null != mySnoop) {
+ mySnoop.write(buf, 0, count);
+ }
totalWritten += count;
if (halt && !finishStream) {
break;
diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java
index 56ce9b510..5d8de7f7b 100644
--- a/util/src/org/aspectj/util/LangUtil.java
+++ b/util/src/org/aspectj/util/LangUtil.java
@@ -14,6 +14,7 @@
package org.aspectj.util;
+import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@@ -1020,6 +1021,7 @@ public class LangUtil {
* ...
*/
private String[] command;
+ private String[] envp;
private String label;
private boolean init;
@@ -1032,6 +1034,7 @@ public class LangUtil {
private FileUtil.Pipe errStream;
private FileUtil.Pipe outStream;
private FileUtil.Pipe inStream;
+ private ByteArrayOutputStream errSnoop;
private int result;
private Thrown thrown;
@@ -1091,17 +1094,29 @@ public class LangUtil {
}
public final void init(String[] command, String label) {
- LangUtil.throwIaxIfNotAssignable(command, String.class, "command");
- if (1 > command.length) {
+ this.command = (String[]) LangUtil.safeCopy(command, new String[0]);
+ if (1 > this.command.length) {
throw new IllegalArgumentException("empty command");
}
- this.command = new String[command.length];
- System.arraycopy(command, 0, this.command, 0, command.length);
this.label = LangUtil.isEmpty(label) ? command[0] : label;
this.init = true;
reinit();
}
+ public final void setEnvp(String[] envp) {
+ this.envp = (String[]) LangUtil.safeCopy(envp, new String[0]);
+ if (1 > this.envp.length) {
+ throw new IllegalArgumentException("empty envp");
+ }
+ }
+
+ public final void setErrSnoop(ByteArrayOutputStream snoop) {
+ errSnoop = snoop;
+ if (null != errStream) {
+ errStream.setSnoop(errSnoop);
+ }
+ }
+
/**
* Start running the process and pipes asynchronously.
* @return Thread started or null if unable to start thread
@@ -1124,6 +1139,9 @@ public class LangUtil {
return null;
}
errStream = new FileUtil.Pipe(process.getErrorStream(), System.err);
+ if (null != errSnoop) {
+ errStream.setSnoop(errSnoop);
+ }
outStream = new FileUtil.Pipe(process.getInputStream(), System.out);
inStream = new FileUtil.Pipe(System.in, process.getOutputStream());
// start 4 threads, process & pipes for in, err, out
@@ -1242,7 +1260,7 @@ public class LangUtil {
process.destroy();
}
if (null != inStream) {
- inStream.halt(true,true);
+ inStream.halt(false, true); // this will block if waiting
inStream = null;
}
if (null != outStream) {