Search in sources :

Example 6 with ExecResult

use of org.gradle.process.ExecResult in project gradle by gradle.

the class DefaultWorkerProcess method setExecHandle.

public void setExecHandle(ExecHandle execHandle) {
    this.execHandle = execHandle;
    execHandle.addListener(new ExecHandleListener() {

        public void executionStarted(ExecHandle execHandle) {
        }

        public void executionFinished(ExecHandle execHandle, ExecResult execResult) {
            onProcessStop(execResult);
        }
    });
}
Also used : ExecHandleListener(org.gradle.process.internal.ExecHandleListener) ExecHandle(org.gradle.process.internal.ExecHandle) ExecResult(org.gradle.process.ExecResult)

Example 7 with ExecResult

use of org.gradle.process.ExecResult in project gradle by gradle.

the class DefaultExecAction method execute.

public ExecResult execute() {
    ExecHandle execHandle = build();
    ExecResult execResult = execHandle.start().waitForFinish();
    if (!isIgnoreExitValue()) {
        execResult.assertNormalExitValue();
    }
    return execResult;
}
Also used : ExecResult(org.gradle.process.ExecResult)

Example 8 with ExecResult

use of org.gradle.process.ExecResult in project gradle by gradle.

the class DefaultJavaExecAction method execute.

public ExecResult execute() {
    ExecHandle execHandle = build();
    ExecResult execResult = execHandle.start().waitForFinish();
    if (!isIgnoreExitValue()) {
        execResult.assertNormalExitValue();
    }
    return execResult;
}
Also used : ExecResult(org.gradle.process.ExecResult)

Example 9 with ExecResult

use of org.gradle.process.ExecResult in project gradle by gradle.

the class ProcessLauncherServer method launchExternalProcess.

/**
     * This launches an external process in a thread and waits for it to exit.
     */
private void launchExternalProcess() {
    Thread thread = new Thread(new Runnable() {

        public void run() {
            ExecutionInfo executionInfo = null;
            ExecHandle execHandle = null;
            ByteArrayOutputStream output = null;
            try {
                executionInfo = protocol.getExecutionInfo(getPort());
                ExecHandleBuilder builder = new DefaultExecHandleBuilder();
                builder.workingDir(executionInfo.getWorkingDirectory());
                builder.commandLine((Object[]) executionInfo.getCommandLineArguments());
                builder.environment(executionInfo.getEnvironmentVariables());
                output = new ByteArrayOutputStream();
                builder.setStandardOutput(output);
                builder.setErrorOutput(output);
                execHandle = builder.build();
                setExternalProcess(execHandle);
                execHandle.start();
            } catch (Throwable e) {
                LOGGER.error("Starting external process", e);
                notifyClientExited(-1, e.getMessage());
                setExternalProcess(null);
                return;
            }
            ExecResult result = execHandle.waitForFinish();
            LOGGER.debug("External process completed with exit code {}", result.getExitValue());
            //clear our external process member variable (we're using our local variable below). This is so we know the process has already stopped.
            setExternalProcess(null);
            executionInfo.processExecutionComplete();
            notifyClientExited(result.getExitValue(), output.toString());
        }
    });
    thread.start();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultExecHandleBuilder(org.gradle.process.internal.DefaultExecHandleBuilder) DefaultExecHandleBuilder(org.gradle.process.internal.DefaultExecHandleBuilder) ExecHandleBuilder(org.gradle.process.internal.ExecHandleBuilder) ExecHandle(org.gradle.process.internal.ExecHandle) ExecResult(org.gradle.process.ExecResult)

Example 10 with ExecResult

use of org.gradle.process.ExecResult in project gradle by gradle.

the class CommandLineToolVersionLocator method getVswhereOutput.

private String getVswhereOutput(File vswhereBinary, List<String> args) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.args(args);
    exec.executable(vswhereBinary.getAbsolutePath());
    exec.setWorkingDir(vswhereBinary.getParentFile());
    StreamByteBuffer buffer = new StreamByteBuffer();
    exec.setStandardOutput(buffer.getOutputStream());
    exec.setErrorOutput(NullOutputStream.INSTANCE);
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();
    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return buffer.readAsString("UTF-8");
    } else {
        LOGGER.debug("vswhere.exe returned a non-zero exit value ({}) - ignoring", result.getExitValue());
        return null;
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ExecResult(org.gradle.process.ExecResult)

Aggregations

ExecResult (org.gradle.process.ExecResult)10 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)3 ExecAction (org.gradle.process.internal.ExecAction)3 ExecHandle (org.gradle.process.internal.ExecHandle)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 GradleException (org.gradle.api.GradleException)1 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)1 DefaultExecHandleBuilder (org.gradle.process.internal.DefaultExecHandleBuilder)1 ExecException (org.gradle.process.internal.ExecException)1 ExecHandleBuilder (org.gradle.process.internal.ExecHandleBuilder)1 ExecHandleListener (org.gradle.process.internal.ExecHandleListener)1 JavaExecAction (org.gradle.process.internal.JavaExecAction)1