Search in sources :

Example 1 with ErrorOutputStream

use of org.robovm.compiler.log.ErrorOutputStream in project robovm by robovm.

the class Executor method initExecutor.

private <T extends org.apache.commons.exec.Executor> T initExecutor(T executor) {
    if (streamHandler == null) {
        OutputStream pumpOut = null;
        OutputStream pumpErr = null;
        InputStream pumpIn = null;
        if (out != null) {
            pumpOut = out;
        } else {
            pumpOut = new InfoOutputStream(logger);
        }
        if (err != null) {
            pumpErr = err;
        } else {
            pumpErr = new ErrorOutputStream(logger);
        }
        if (in != null) {
            pumpIn = in;
        }
        if (pumpOut == System.out) {
            pumpOut = new NeverCloseOutputStream(pumpOut);
        }
        if (pumpErr == System.err) {
            pumpErr = new NeverCloseOutputStream(pumpErr);
        }
        executor.setStreamHandler(new PumpStreamHandler(pumpOut, pumpErr, pumpIn) {

            @Override
            protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted) {
                return super.createPump(is, os, closeOutputStreams ? true : closeWhenExhausted);
            }
        });
    } else {
        executor.setStreamHandler(streamHandler);
    }
    if (wd != null) {
        executor.setWorkingDirectory(wd);
    }
    executor.setExitValue(0);
    return executor;
}
Also used : PumpStreamHandler(org.apache.commons.exec.PumpStreamHandler) ErrorOutputStream(org.robovm.compiler.log.ErrorOutputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NeverCloseOutputStream(org.robovm.compiler.util.io.NeverCloseOutputStream) InfoOutputStream(org.robovm.compiler.log.InfoOutputStream) ErrorOutputStream(org.robovm.compiler.log.ErrorOutputStream) NeverCloseOutputStream(org.robovm.compiler.util.io.NeverCloseOutputStream) InfoOutputStream(org.robovm.compiler.log.InfoOutputStream)

Example 2 with ErrorOutputStream

use of org.robovm.compiler.log.ErrorOutputStream in project robovm by robovm.

the class AppLauncherProcess method execAsync.

@Override
public Process execAsync() throws IOException {
    launcher.install();
    this.launcherThread = new Thread("AppLauncherThread-" + threadCounter.getAndIncrement()) {

        @Override
        public void run() {
            try {
                exitCode = launcher.launch();
            } catch (Throwable t) {
                log.error("AppLauncher failed with an exception:", t.getMessage());
                t.printStackTrace(new PrintStream(new ErrorOutputStream(log), true));
            } finally {
                IOUtils.closeQuietly(errStream);
                finished = true;
                countDownLatch.countDown();
            }
        }
    };
    this.launcherThread.start();
    return this;
}
Also used : PrintStream(java.io.PrintStream) ErrorOutputStream(org.robovm.compiler.log.ErrorOutputStream)

Aggregations

ErrorOutputStream (org.robovm.compiler.log.ErrorOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)1 InfoOutputStream (org.robovm.compiler.log.InfoOutputStream)1 NeverCloseOutputStream (org.robovm.compiler.util.io.NeverCloseOutputStream)1