use of org.gradle.process.internal.ExecHandle in project gradle by gradle.
the class DefaultWorkerProcessBuilder method build.
@Override
public WorkerProcess build() {
final WorkerJvmMemoryStatus memoryStatus = shouldPublishJvmMemoryInfo ? new WorkerJvmMemoryStatus() : null;
final DefaultWorkerProcess workerProcess = new DefaultWorkerProcess(connectTimeoutSeconds, TimeUnit.SECONDS, memoryStatus);
ConnectionAcceptor acceptor = server.accept(new Action<ObjectConnection>() {
public void execute(final ObjectConnection connection) {
workerProcess.onConnect(connection, new Runnable() {
@Override
public void run() {
DefaultWorkerLoggingProtocol defaultWorkerLoggingProtocol = new DefaultWorkerLoggingProtocol(outputEventListener);
connection.useParameterSerializers(WorkerLoggingSerializer.create());
connection.addIncoming(WorkerLoggingProtocol.class, defaultWorkerLoggingProtocol);
if (shouldPublishJvmMemoryInfo) {
connection.useParameterSerializers(WorkerJvmMemoryInfoSerializer.create());
connection.addIncoming(WorkerJvmMemoryInfoProtocol.class, memoryStatus);
}
}
});
}
});
workerProcess.startAccepting(acceptor);
Address localAddress = acceptor.getAddress();
// Build configuration for GradleWorkerMain
Object id = idGenerator.generateId();
String displayName = getBaseName() + " " + id;
LOGGER.debug("Creating {}", displayName);
LOGGER.debug("Using application classpath {}", applicationClasspath);
LOGGER.debug("Using implementation classpath {}", implementationClassPath);
JavaExecHandleBuilder javaCommand = getJavaCommand();
javaCommand.setDisplayName(displayName);
workerImplementationFactory.prepareJavaCommand(id, displayName, this, implementationClassPath, localAddress, javaCommand, shouldPublishJvmMemoryInfo);
javaCommand.args("'" + displayName + "'");
ExecHandle execHandle = javaCommand.build();
workerProcess.setExecHandle(execHandle);
return new MemoryRequestingWorkerProcess(workerProcess, memoryManager, MemoryAmount.parseNotation(javaCommand.getMinHeapSize()));
}
use of org.gradle.process.internal.ExecHandle in project gradle by gradle.
the class ForkingGradleHandle method waitForStop.
protected ExecutionResult waitForStop(boolean expectFailure) {
ExecHandle execHandle = getExecHandle();
ExecResult execResult = execHandle.waitForFinish();
if (durationMeasurement != null) {
durationMeasurement.stop();
}
// nop if all ok
execResult.rethrowFailure();
String output = getStandardOutput();
String error = getErrorOutput();
boolean didFail = execResult.getExitValue() != 0;
ExecutionResult executionResult = expectFailure ? toExecutionFailure(output, error) : toExecutionResult(output, error);
if (didFail != expectFailure) {
String message = String.format("Gradle execution %s in %s with: %s %s%nOutput:%n%s%n-----%nError:%n%s%n-----%nExecution result:%n%s%n-----%n", expectFailure ? "did not fail" : "failed", execHandle.getDirectory(), execHandle.getCommand(), execHandle.getArguments(), output, error, execResult.toString());
Exception exception = executionResult instanceof OutputScrapingExecutionFailure ? ((OutputScrapingExecutionFailure) executionResult).getException() : null;
throw exception == null ? new UnexpectedBuildFailure(message) : new UnexpectedBuildFailure(message, exception);
}
resultAssertion.execute(executionResult);
return executionResult;
}
use of org.gradle.process.internal.ExecHandle in project gradle by gradle.
the class CommandLineJavaCompiler method execute.
@Override
public WorkResult execute(JavaCompileSpec spec) {
final ForkOptions forkOptions = spec.getCompileOptions().getForkOptions();
String executable = forkOptions.getJavaHome() != null ? Jvm.forHome(forkOptions.getJavaHome()).getJavacExecutable().getAbsolutePath() : getExecutable(forkOptions);
LOGGER.info("Compiling with Java command line compiler '{}'.", executable);
ExecHandle handle = createCompilerHandle(executable, spec);
executeCompiler(handle);
return new SimpleWorkResult(true);
}
use of org.gradle.process.internal.ExecHandle 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();
}
use of org.gradle.process.internal.ExecHandle 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);
}
});
}
Aggregations