Search in sources :

Example 1 with ExecHandleBuilder

use of org.gradle.process.internal.ExecHandleBuilder in project gradle by gradle.

the class OsXInstalledJvmLocator method findJvms.

public Collection<JvmInstallation> findJvms() {
    try {
        ExecHandleBuilder execHandleBuilder = execHandleFactory.newExec();
        execHandleBuilder.workingDir(new File(".").getAbsoluteFile());
        execHandleBuilder.commandLine("/usr/libexec/java_home", "-V");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // verbose output is written to stderr for some reason
        execHandleBuilder.setErrorOutput(outputStream);
        execHandleBuilder.setStandardOutput(new ByteArrayOutputStream());
        execHandleBuilder.build().start().waitForFinish().assertNormalExitValue();
        return new OsXJavaHomeParser().parse(new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray())));
    } catch (Exception e) {
        throw new GradleException("Could not locate installed JVMs.", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) GradleException(org.gradle.api.GradleException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecHandleBuilder(org.gradle.process.internal.ExecHandleBuilder) File(java.io.File) GradleException(org.gradle.api.GradleException)

Example 2 with ExecHandleBuilder

use of org.gradle.process.internal.ExecHandleBuilder in project gradle by gradle.

the class CommandLineJavaCompiler method createCompilerHandle.

private ExecHandle createCompilerHandle(String executable, JavaCompileSpec spec) {
    ExecHandleBuilder builder = new DefaultExecHandleBuilder();
    builder.setWorkingDir(spec.getWorkingDir());
    builder.setExecutable(executable);
    argumentsGenerator.collectArguments(spec, new ExecSpecBackedArgCollector(builder));
    builder.setIgnoreExitValue(true);
    return builder.build();
}
Also used : DefaultExecHandleBuilder(org.gradle.process.internal.DefaultExecHandleBuilder) DefaultExecHandleBuilder(org.gradle.process.internal.DefaultExecHandleBuilder) ExecHandleBuilder(org.gradle.process.internal.ExecHandleBuilder)

Example 3 with ExecHandleBuilder

use of org.gradle.process.internal.ExecHandleBuilder in project gradle by gradle.

the class DefaultJvmVersionDetector method getJavaVersion.

@Override
public JavaVersion getJavaVersion(String javaCommand) {
    StreamByteBuffer buffer = new StreamByteBuffer();
    ExecHandleBuilder builder = execHandleFactory.newExec();
    builder.setWorkingDir(new File(".").getAbsolutePath());
    builder.setCommandLine(javaCommand, "-version");
    builder.setStandardOutput(NullOutputStream.INSTANCE);
    builder.setErrorOutput(buffer.getOutputStream());
    builder.build().start().waitForFinish().assertNormalExitValue();
    return parseJavaVersionCommandOutput(javaCommand, new BufferedReader(new InputStreamReader(buffer.getInputStream())));
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ExecHandleBuilder(org.gradle.process.internal.ExecHandleBuilder) File(java.io.File)

Example 4 with ExecHandleBuilder

use of org.gradle.process.internal.ExecHandleBuilder 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)

Aggregations

ExecHandleBuilder (org.gradle.process.internal.ExecHandleBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 DefaultExecHandleBuilder (org.gradle.process.internal.DefaultExecHandleBuilder)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 GradleException (org.gradle.api.GradleException)1 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)1 ExecResult (org.gradle.process.ExecResult)1 ExecHandle (org.gradle.process.internal.ExecHandle)1