Search in sources :

Example 1 with BuildActionResult

use of org.gradle.launcher.exec.BuildActionResult in project gradle by gradle.

the class InProcessGradleExecuter method executeBuild.

private BuildResult executeBuild(GradleInvocation invocation, OutputStream outputStream, OutputStream errorStream, BuildListenerImpl listener) {
    // Augment the environment for the execution
    System.setIn(connectStdIn());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : invocation.environmentVars.entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);
    // TODO: Reuse more of CommandlineActionFactory
    CommandLineParser parser = new CommandLineParser();
    FileCollectionFactory fileCollectionFactory = TestFiles.fileCollectionFactory();
    ParametersConverter parametersConverter = new ParametersConverter(new BuildLayoutFactory(), fileCollectionFactory);
    parametersConverter.configure(parser);
    Parameters parameters = parametersConverter.convert(parser.parse(getAllArgs()), getWorkingDir());
    BuildActionExecuter<BuildActionParameters, BuildRequestContext> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class);
    ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class);
    listenerManager.addListener(listener);
    try {
        // TODO: Reuse more of BuildActionsFactory
        StartParameterInternal startParameter = parameters.getStartParameter();
        BuildAction action = new ExecuteBuildAction(startParameter);
        BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter);
        BuildRequestContext buildRequestContext = createBuildRequestContext();
        LoggingManagerInternal loggingManager = createLoggingManager(startParameter, outputStream, errorStream);
        loggingManager.start();
        try {
            startMeasurement();
            try {
                BuildActionResult result = actionExecuter.execute(action, buildActionParameters, buildRequestContext);
                if (result.getException() != null) {
                    return new BuildResult(null, result.getException());
                }
                if (result.getFailure() != null) {
                    PayloadSerializer payloadSerializer = new PayloadSerializer(new TestClassLoaderRegistry());
                    return new BuildResult(null, (RuntimeException) payloadSerializer.deserialize(result.getFailure()));
                }
                return new BuildResult(null, null);
            } finally {
                stopMeasurement();
            }
        } finally {
            loggingManager.stop();
        }
    } finally {
        listenerManager.removeListener(listener);
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) Parameters(org.gradle.launcher.cli.Parameters) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ExecuteBuildAction(org.gradle.tooling.internal.provider.action.ExecuteBuildAction) Hashing.hashString(org.gradle.internal.hash.Hashing.hashString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BuildLayoutFactory(org.gradle.initialization.layout.BuildLayoutFactory) DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildRequestContext(org.gradle.initialization.BuildRequestContext) BuildResult(org.gradle.BuildResult) ParametersConverter(org.gradle.launcher.cli.ParametersConverter) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) CommandLineParser(org.gradle.cli.CommandLineParser) SerializeMap(org.gradle.tooling.internal.provider.serialization.SerializeMap) Map(java.util.Map) DeserializeMap(org.gradle.tooling.internal.provider.serialization.DeserializeMap) HashMap(java.util.HashMap) ExecuteBuildAction(org.gradle.tooling.internal.provider.action.ExecuteBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 2 with BuildActionResult

use of org.gradle.launcher.exec.BuildActionResult in project gradle by gradle.

the class ExecuteBuild method doBuild.

@Override
protected void doBuild(final DaemonCommandExecution execution, Build build) {
    LOGGER.debug(DaemonMessages.STARTED_BUILD);
    LOGGER.debug("Executing build with daemon context: {}", execution.getDaemonContext());
    runningStats.buildStarted();
    DaemonConnectionBackedEventConsumer buildEventConsumer = new DaemonConnectionBackedEventConsumer(execution);
    try {
        BuildCancellationToken cancellationToken = execution.getDaemonStateControl().getCancellationToken();
        BuildRequestContext buildRequestContext = new DefaultBuildRequestContext(build.getBuildRequestMetaData(), cancellationToken, buildEventConsumer);
        if (!build.getAction().getStartParameter().isContinuous()) {
            buildRequestContext.getCancellationToken().addCallback(new Runnable() {

                @Override
                public void run() {
                    LOGGER.info(DaemonMessages.CANCELED_BUILD);
                }
            });
        }
        BuildActionResult result = actionExecuter.execute(build.getAction(), build.getParameters(), buildRequestContext);
        execution.setResult(result);
    } finally {
        buildEventConsumer.waitForFinish();
        runningStats.buildFinished();
        LOGGER.debug(DaemonMessages.FINISHED_BUILD);
    }
    // ExecuteBuild should be the last action, but in case we want to decorate the result in the future
    execution.proceed();
}
Also used : DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildRequestContext(org.gradle.initialization.BuildRequestContext)

Example 3 with BuildActionResult

use of org.gradle.launcher.exec.BuildActionResult in project gradle by gradle.

the class DaemonClient method executeBuild.

protected BuildActionResult executeBuild(Build build, DaemonClientConnection connection, BuildCancellationToken cancellationToken, BuildEventConsumer buildEventConsumer) throws DaemonInitialConnectException {
    Object result;
    try {
        LOGGER.debug("Connected to daemon {}. Dispatching request {}.", connection.getDaemon(), build);
        connection.dispatch(build);
        result = connection.receive();
    } catch (StaleDaemonAddressException e) {
        LOGGER.debug("Connected to a stale daemon address.", e);
        // However, since we haven't yet started running the build, we can recover by just trying again.
        throw new DaemonInitialConnectException("Connected to a stale daemon address.", e);
    }
    if (result == null) {
        // If the response from the daemon is unintelligible, mark the daemon as unavailable so other
        // clients won't try to communicate with it. We'll attempt to recovery by trying again.
        connector.markDaemonAsUnavailable(connection.getDaemon());
        throw new DaemonInitialConnectException("The first result from the daemon was empty. The daemon process may have died or a non-daemon process is reusing the same port.");
    }
    LOGGER.debug("Received result {} from daemon {} (build should be starting).", result, connection.getDaemon());
    DaemonDiagnostics diagnostics = null;
    if (result instanceof BuildStarted) {
        diagnostics = ((BuildStarted) result).getDiagnostics();
        result = monitorBuild(build, diagnostics, connection, cancellationToken, buildEventConsumer);
    }
    LOGGER.debug("Received result {} from daemon {} (build should be done).", result, connection.getDaemon());
    connection.dispatch(new Finished());
    if (result instanceof Failure) {
        Throwable failure = ((Failure) result).getValue();
        if (failure instanceof DaemonStoppedException && cancellationToken.isCancellationRequested()) {
            return BuildActionResult.cancelled(new BuildCancelledException("Daemon was stopped to handle build cancel request.", failure));
        }
        throw UncheckedException.throwAsUncheckedException(failure);
    } else if (result instanceof DaemonUnavailable) {
        throw new DaemonInitialConnectException("The daemon we connected to was unavailable: " + ((DaemonUnavailable) result).getReason());
    } else if (result instanceof Result) {
        return (BuildActionResult) ((Result) result).getValue();
    } else {
        throw invalidResponse(result, build, diagnostics);
    }
}
Also used : Finished(org.gradle.launcher.daemon.protocol.Finished) DaemonUnavailable(org.gradle.launcher.daemon.protocol.DaemonUnavailable) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) Result(org.gradle.launcher.daemon.protocol.Result) DaemonStoppedException(org.gradle.launcher.daemon.server.api.DaemonStoppedException) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) BuildStarted(org.gradle.launcher.daemon.protocol.BuildStarted) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) BuildCancelledException(org.gradle.api.BuildCancelledException) Failure(org.gradle.launcher.daemon.protocol.Failure)

Example 4 with BuildActionResult

use of org.gradle.launcher.exec.BuildActionResult in project gradle by gradle.

the class ProviderConnection method run.

private Object run(BuildAction action, BuildCancellationToken cancellationToken, ProgressListenerConfiguration progressListenerConfiguration, BuildEventConsumer buildEventConsumer, ProviderOperationParameters providerParameters, Parameters parameters) {
    try {
        BuildActionExecuter<ConnectionOperationParameters, BuildRequestContext> executer = createExecuter(providerParameters, parameters);
        boolean interactive = providerParameters.getStandardInput() != null;
        BuildRequestContext buildRequestContext = new DefaultBuildRequestContext(new DefaultBuildRequestMetaData(providerParameters.getStartTime(), interactive), cancellationToken, buildEventConsumer);
        BuildActionResult result = executer.execute(action, new ConnectionOperationParameters(parameters.daemonParams, providerParameters), buildRequestContext);
        throwFailure(result);
        return payloadSerializer.deserialize(result.getResult());
    } finally {
        progressListenerConfiguration.failsafeWrapper.rethrowErrors();
    }
}
Also used : DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildRequestContext(org.gradle.initialization.BuildRequestContext)

Aggregations

BuildActionResult (org.gradle.launcher.exec.BuildActionResult)4 BuildRequestContext (org.gradle.initialization.BuildRequestContext)3 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BuildResult (org.gradle.BuildResult)1 BuildCancelledException (org.gradle.api.BuildCancelledException)1 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)1 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)1 CommandLineParser (org.gradle.cli.CommandLineParser)1 BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)1 DefaultBuildRequestMetaData (org.gradle.initialization.DefaultBuildRequestMetaData)1 BuildLayoutFactory (org.gradle.initialization.layout.BuildLayoutFactory)1 ListenerManager (org.gradle.internal.event.ListenerManager)1 Hashing.hashString (org.gradle.internal.hash.Hashing.hashString)1 BuildAction (org.gradle.internal.invocation.BuildAction)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)1 Parameters (org.gradle.launcher.cli.Parameters)1 ParametersConverter (org.gradle.launcher.cli.ParametersConverter)1 DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)1