Search in sources :

Example 1 with StreamVacuum

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;
}
Also used : StreamVacuum(org.antlr.v4.test.runtime.StreamVacuum) File(java.io.File) BaseRuntimeTest.writeFile(org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile)

Example 2 with StreamVacuum

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());
    }
}
Also used : StreamVacuum(org.antlr.v4.test.runtime.StreamVacuum) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) IOException(java.io.IOException)

Example 3 with StreamVacuum

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;
}
Also used : StreamVacuum(org.antlr.v4.test.runtime.StreamVacuum)

Example 4 with StreamVacuum

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;
}
Also used : StreamVacuum(org.antlr.v4.test.runtime.StreamVacuum) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) File(java.io.File) BaseRuntimeTest.writeFile(org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile)

Example 5 with StreamVacuum

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;
    }
}
Also used : BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) BaseRuntimeTest.writeFile(org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile) File(java.io.File) IOException(java.io.IOException)

Aggregations

BaseRuntimeTest.writeFile (org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile)12 File (java.io.File)11 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)11 IOException (java.io.IOException)7 StreamVacuum (org.antlr.v4.test.runtime.StreamVacuum)5 Path (java.nio.file.Path)3 STGroupString (org.stringtemplate.v4.STGroupString)3 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URLClassLoader (java.net.URLClassLoader)1 Pair (org.antlr.v4.runtime.misc.Pair)1 BaseRuntimeTest.readFile (org.antlr.v4.test.runtime.BaseRuntimeTest.readFile)1