use of org.antlr.v4.test.runtime.StreamVacuum in project antlr4 by antlr.
the class BaseCSharpTest method runProcess.
private boolean runProcess(String[] args, String path) throws Exception {
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(new File(path));
Process process = pb.start();
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
stdoutVacuum.start();
stderrVacuum.start();
process.waitFor();
stdoutVacuum.join();
stderrVacuum.join();
boolean success = process.exitValue() == 0;
if (!success) {
this.stderrDuringParse = stderrVacuum.toString();
System.err.println("runProcess stderrVacuum: " + this.stderrDuringParse);
}
return success;
}
use of org.antlr.v4.test.runtime.StreamVacuum in project antlr4 by antlr.
the class BaseGoTest method cacheGoRuntime.
private static void cacheGoRuntime(File tmpPackageDir) throws Exception {
String goExecutable = locateGo();
ProcessBuilder pb = new ProcessBuilder(goExecutable, "install", "-x");
pb.directory(tmpPackageDir);
pb.environment().put("GOPATH", tmpGopath.getPath());
pb.redirectErrorStream(true);
Process process = pb.start();
StreamVacuum sucker = new StreamVacuum(process.getInputStream());
sucker.start();
int exit = process.waitFor();
sucker.join();
if (exit != 0) {
throw new Exception("Non-zero exit while caching go runtime, output: " + sucker.toString());
}
}
use of org.antlr.v4.test.runtime.StreamVacuum in project antlr4 by antlr.
the class BaseNodeTest method canExecute.
private boolean canExecute(String tool) {
try {
ProcessBuilder builder = new ProcessBuilder(tool, "--version");
builder.redirectErrorStream(true);
Process process = builder.start();
StreamVacuum vacuum = new StreamVacuum(process.getInputStream());
vacuum.start();
process.waitFor();
vacuum.join();
return process.exitValue() == 0;
} catch (Exception e) {
;
}
return false;
}
use of org.antlr.v4.test.runtime.StreamVacuum in project antlr4 by antlr.
the class BaseNodeTest method execModule.
public String execModule(String fileName) {
String nodejsPath = locateNodeJS();
String runtimePath = locateRuntime();
String modulePath = new File(new File(tmpdir), fileName).getAbsolutePath();
String inputPath = new File(new File(tmpdir), "input").getAbsolutePath();
try {
ProcessBuilder builder = new ProcessBuilder(nodejsPath, modulePath, inputPath);
builder.environment().put("NODE_PATH", runtimePath + File.pathSeparator + tmpdir);
builder.directory(new File(tmpdir));
Process process = builder.start();
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
stdoutVacuum.start();
stderrVacuum.start();
process.waitFor();
stdoutVacuum.join();
stderrVacuum.join();
String output = stdoutVacuum.toString();
if (output.length() == 0) {
output = null;
}
if (stderrVacuum.toString().length() > 0) {
this.stderrDuringParse = stderrVacuum.toString();
}
return output;
} catch (Exception e) {
System.err.println("can't exec recognizer");
e.printStackTrace(System.err);
}
return null;
}
use of org.antlr.v4.test.runtime.StreamVacuum in project antlr4 by antlr.
the class BaseNodeTest method execModule.
public String execModule(String fileName) {
try {
String npmPath = locateNpm();
if (!TestContext.isCI()) {
installRuntime(npmPath);
registerRuntime(npmPath);
}
String modulePath = new File(getTempTestDir(), fileName).getAbsolutePath();
linkRuntime(npmPath);
String nodejsPath = locateNodeJS();
String inputPath = new File(getTempTestDir(), "input").getAbsolutePath();
ProcessBuilder builder = new ProcessBuilder(nodejsPath, modulePath, inputPath);
builder.environment().put("NODE_PATH", getTempDirPath());
builder.directory(getTempTestDir());
Process process = builder.start();
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
stdoutVacuum.start();
stderrVacuum.start();
// TODO switch to jdk 8
process.waitFor();
// if(!process.waitFor(1L, TimeUnit.MINUTES))
// process.destroyForcibly();
stdoutVacuum.join();
stderrVacuum.join();
String output = stdoutVacuum.toString();
if (output.length() == 0) {
output = null;
}
if (stderrVacuum.toString().length() > 0) {
setParseErrors(stderrVacuum.toString());
}
return output;
} catch (Exception e) {
System.err.println("can't exec recognizer");
e.printStackTrace(System.err);
System.err.println();
return null;
}
}
Aggregations