Search in sources :

Example 1 with ExecHandle

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()));
}
Also used : ConnectionAcceptor(org.gradle.internal.remote.ConnectionAcceptor) Address(org.gradle.internal.remote.Address) JavaExecHandleBuilder(org.gradle.process.internal.JavaExecHandleBuilder) ObjectConnection(org.gradle.internal.remote.ObjectConnection) ExecHandle(org.gradle.process.internal.ExecHandle)

Example 2 with ExecHandle

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;
}
Also used : IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) ExecHandle(org.gradle.process.internal.ExecHandle) ExecResult(org.gradle.process.ExecResult)

Example 3 with ExecHandle

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);
}
Also used : ForkOptions(org.gradle.api.tasks.compile.ForkOptions) SimpleWorkResult(org.gradle.api.internal.tasks.SimpleWorkResult) ExecHandle(org.gradle.process.internal.ExecHandle)

Example 4 with ExecHandle

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();
}
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 5 with ExecHandle

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);
        }
    });
}
Also used : ExecHandleListener(org.gradle.process.internal.ExecHandleListener) ExecHandle(org.gradle.process.internal.ExecHandle) ExecResult(org.gradle.process.ExecResult)

Aggregations

ExecHandle (org.gradle.process.internal.ExecHandle)6 ExecResult (org.gradle.process.ExecResult)3 IOException (java.io.IOException)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 GradleException (org.gradle.api.GradleException)1 SimpleWorkResult (org.gradle.api.internal.tasks.SimpleWorkResult)1 ForkOptions (org.gradle.api.tasks.compile.ForkOptions)1 Address (org.gradle.internal.remote.Address)1 ConnectionAcceptor (org.gradle.internal.remote.ConnectionAcceptor)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 Timer (org.gradle.internal.time.Timer)1 DaemonExecHandleBuilder (org.gradle.launcher.daemon.DaemonExecHandleBuilder)1 DaemonOutputConsumer (org.gradle.launcher.daemon.bootstrap.DaemonOutputConsumer)1 DefaultExecHandleBuilder (org.gradle.process.internal.DefaultExecHandleBuilder)1 ExecHandleBuilder (org.gradle.process.internal.ExecHandleBuilder)1 ExecHandleListener (org.gradle.process.internal.ExecHandleListener)1 JavaExecHandleBuilder (org.gradle.process.internal.JavaExecHandleBuilder)1