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);
}
}
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();
}
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())));
}
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();
}
Aggregations