add support for loggers
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2876 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
e3546de635
commit
91d48ef389
|
@ -12,6 +12,7 @@ package com.ibm.wala.dynamic;
|
|||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
|
@ -22,8 +23,8 @@ public class BasicLauncher extends Launcher {
|
|||
|
||||
protected String cmd;
|
||||
|
||||
public BasicLauncher(boolean captureOutput, boolean captureErr) {
|
||||
super(captureOutput, captureErr);
|
||||
public BasicLauncher(boolean captureOutput, boolean captureErr, Logger logger) {
|
||||
super(captureOutput, captureErr, logger);
|
||||
}
|
||||
|
||||
public String getCmd() {
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A Java process launcher
|
||||
|
@ -31,8 +32,8 @@ public class JavaLauncher extends Launcher {
|
|||
* @param classpathEntries
|
||||
* Paths that will be added to the default classpath
|
||||
*/
|
||||
public static JavaLauncher make(String programArgs, String mainClass, List<String> classpathEntries) {
|
||||
return new JavaLauncher(programArgs, mainClass, true, classpathEntries, false, false);
|
||||
public static JavaLauncher make(String programArgs, String mainClass, List<String> classpathEntries, Logger logger) {
|
||||
return new JavaLauncher(programArgs, mainClass, true, classpathEntries, false, false, logger);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,8 +52,8 @@ public class JavaLauncher extends Launcher {
|
|||
* should the launcher capture the stderr from the subprocess?
|
||||
*/
|
||||
public static JavaLauncher make(String programArgs, String mainClass, boolean inheritClasspath, List<String> classpathEntries,
|
||||
boolean captureOutput, boolean captureErr) {
|
||||
return new JavaLauncher(programArgs, mainClass, inheritClasspath, classpathEntries, captureOutput, captureErr);
|
||||
boolean captureOutput, boolean captureErr, Logger logger) {
|
||||
return new JavaLauncher(programArgs, mainClass, inheritClasspath, classpathEntries, captureOutput, captureErr, logger);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,8 +93,8 @@ public class JavaLauncher extends Launcher {
|
|||
private Thread stdErrDrain;
|
||||
|
||||
private JavaLauncher(String programArgs, String mainClass, boolean inheritClasspath, List<String> xtraClasspath,
|
||||
boolean captureOutput, boolean captureErr) {
|
||||
super(captureOutput, captureErr);
|
||||
boolean captureOutput, boolean captureErr, Logger logger) {
|
||||
super(captureOutput, captureErr, logger);
|
||||
this.programArgs = programArgs;
|
||||
this.mainClass = mainClass;
|
||||
this.inheritClasspath = inheritClasspath;
|
||||
|
@ -146,8 +147,6 @@ public class JavaLauncher extends Launcher {
|
|||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public Process start() throws IllegalArgumentException, IOException {
|
||||
System.err.println(System.getProperty("user.dir"));
|
||||
|
||||
String cp = makeClasspath();
|
||||
|
||||
String heap = " -Xmx800M ";
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||
import java.io.PrintStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
|
@ -45,16 +46,20 @@ public abstract class Launcher {
|
|||
*/
|
||||
private final boolean captureErr;
|
||||
|
||||
protected Launcher() {
|
||||
private final Logger logger;
|
||||
|
||||
protected Launcher(Logger logger) {
|
||||
super();
|
||||
this.captureOutput = false;
|
||||
this.captureErr = false;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
protected Launcher(boolean captureOutput, boolean captureErr) {
|
||||
protected Launcher(boolean captureOutput, boolean captureErr, Logger logger) {
|
||||
super();
|
||||
this.captureOutput = captureOutput;
|
||||
this.captureErr = true;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public File getWorkingDir() {
|
||||
|
@ -96,7 +101,9 @@ public abstract class Launcher {
|
|||
if (cmd == null) {
|
||||
throw new IllegalArgumentException("cmd cannot be null");
|
||||
}
|
||||
System.out.println("spawning process " + cmd);
|
||||
if (logger != null) {
|
||||
logger.fine("spawning process " + cmd);
|
||||
}
|
||||
String[] ev = getEnv() == null ? null : buildEnv(getEnv());
|
||||
Process p = Runtime.getRuntime().exec(cmd, ev, getWorkingDir());
|
||||
return p;
|
||||
|
@ -196,7 +203,9 @@ public abstract class Launcher {
|
|||
// if we get here, the process has terminated
|
||||
repeat = false;
|
||||
drain();
|
||||
System.out.println("process terminated with exit code " + p.exitValue());
|
||||
if (logger != null) {
|
||||
logger.fine("process terminated with exit code " + p.exitValue());
|
||||
}
|
||||
} catch (IllegalThreadStateException e) {
|
||||
// this means the process has not yet terminated.
|
||||
repeat = true;
|
||||
|
|
Loading…
Reference in New Issue