Search in sources :

Example 1 with BuildCancelledException

use of org.gradle.api.BuildCancelledException in project gradle by gradle.

the class DefaultBuildController method getModel.

public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    BuildCancellationToken cancellationToken = gradle.getServices().get(BuildCancellationToken.class);
    if (cancellationToken.isCancellationRequested()) {
        throw new BuildCancelledException(String.format("Could not build '%s' model. Build cancelled.", modelIdentifier.getName()));
    }
    ProjectInternal project = getTargetProject(target);
    ToolingModelBuilder builder = getToolingModelBuilder(project, modelIdentifier);
    Object model = builder.buildAll(modelIdentifier.getName(), project);
    return new ProviderBuildResult<Object>(model);
}
Also used : ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ProviderBuildResult(org.gradle.tooling.internal.provider.connection.ProviderBuildResult) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) ToolingModelBuilder(org.gradle.tooling.provider.model.ToolingModelBuilder) BuildCancelledException(org.gradle.api.BuildCancelledException)

Example 2 with BuildCancelledException

use of org.gradle.api.BuildCancelledException in project gradle by gradle.

the class ClientProvidedBuildActionRunner method buildResult.

private BuildActionResult buildResult(InternalBuildAction<?> clientAction, GradleInternal gradle, boolean isRunTasks) {
    if (!isRunTasks) {
        forceFullConfiguration(gradle);
    }
    InternalBuildController internalBuildController = new DefaultBuildController(gradle);
    Object model = null;
    Throwable failure = null;
    try {
        model = clientAction.execute(internalBuildController);
    } catch (BuildCancelledException e) {
        failure = new InternalBuildCancelledException(e);
    } catch (RuntimeException e) {
        failure = new InternalBuildActionFailureException(e);
    }
    PayloadSerializer payloadSerializer = getPayloadSerializer(gradle);
    if (failure != null) {
        return new BuildActionResult(null, payloadSerializer.serialize(failure));
    } else {
        return new BuildActionResult(payloadSerializer.serialize(model), null);
    }
}
Also used : InternalBuildController(org.gradle.tooling.internal.protocol.InternalBuildController) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) InternalBuildActionFailureException(org.gradle.tooling.internal.protocol.InternalBuildActionFailureException) BuildActionResult(org.gradle.tooling.internal.provider.BuildActionResult) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) BuildCancelledException(org.gradle.api.BuildCancelledException) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException)

Example 3 with BuildCancelledException

use of org.gradle.api.BuildCancelledException in project gradle by gradle.

the class ClientProvidedBuildActionRunner method forceFullConfiguration.

private void forceFullConfiguration(GradleInternal gradle) {
    try {
        gradle.getServices().get(ProjectConfigurer.class).configureHierarchyFully(gradle.getRootProject());
        for (IncludedBuild includedBuild : gradle.getIncludedBuilds()) {
            GradleInternal build = ((IncludedBuildInternal) includedBuild).getConfiguredBuild();
            forceFullConfiguration(build);
        }
    } catch (BuildCancelledException e) {
        throw new InternalBuildCancelledException(e);
    } catch (RuntimeException e) {
        throw new BuildExceptionVersion1(e);
    }
}
Also used : IncludedBuildInternal(org.gradle.composite.internal.IncludedBuildInternal) GradleInternal(org.gradle.api.internal.GradleInternal) BuildExceptionVersion1(org.gradle.tooling.internal.protocol.BuildExceptionVersion1) ProjectConfigurer(org.gradle.execution.ProjectConfigurer) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) BuildCancelledException(org.gradle.api.BuildCancelledException) IncludedBuild(org.gradle.api.initialization.IncludedBuild) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException)

Example 4 with BuildCancelledException

use of org.gradle.api.BuildCancelledException in project gradle by gradle.

the class DaemonClient method executeBuild.

protected Object executeBuild(Build build, DaemonClientConnection connection, BuildCancellationToken cancellationToken, BuildEventConsumer buildEventConsumer) throws DaemonInitialConnectException {
    Object result;
    try {
        LOGGER.info("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) {
        throw new DaemonInitialConnectException("The first result from the daemon was empty. Most likely the process died immediately after connection.");
    }
    LOGGER.info("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.info("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()) {
            LOGGER.error("Daemon was stopped to handle build cancel request.");
            throw new BuildCancelledException();
        }
        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 ((Result) result).getValue();
    } else {
        throw invalidResponse(result, build, diagnostics);
    }
}
Also used : DaemonStoppedException(org.gradle.launcher.daemon.server.api.DaemonStoppedException) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) BuildCancelledException(org.gradle.api.BuildCancelledException)

Example 5 with BuildCancelledException

use of org.gradle.api.BuildCancelledException in project gradle by gradle.

the class DaemonBuildActionExecuter method execute.

public Object execute(BuildAction action, BuildRequestContext buildRequestContext, ProviderOperationParameters parameters, ServiceRegistry contextServices) {
    boolean continuous = action.getStartParameter() != null && action.getStartParameter().isContinuous() && isNotBuildingModel(action);
    if (continuous && !doesConsumerSupportCancellation(buildRequestContext)) {
        throw new UnsupportedVersionException("Continuous build requires Tooling API client version 2.1 or later.");
    }
    ClassPath classPath = DefaultClassPath.of(parameters.getInjectedPluginClasspath(Collections.<File>emptyList()));
    BuildActionParameters actionParameters = new DefaultBuildActionParameters(daemonParameters.getEffectiveSystemProperties(), daemonParameters.getEnvironmentVariables(), SystemProperties.getInstance().getCurrentDir(), parameters.getBuildLogLevel(), daemonParameters.isEnabled(), continuous, false, classPath);
    try {
        return executer.execute(action, buildRequestContext, actionParameters, contextServices);
    } catch (ReportedException e) {
        Throwable t = e.getCause();
        while (t != null) {
            if (t instanceof BuildCancelledException) {
                throw new InternalBuildCancelledException(e.getCause());
            }
            t = t.getCause();
        }
        throw new BuildExceptionVersion1(e.getCause());
    }
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) BuildExceptionVersion1(org.gradle.tooling.internal.protocol.BuildExceptionVersion1) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) File(java.io.File) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) BuildCancelledException(org.gradle.api.BuildCancelledException) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException) ReportedException(org.gradle.initialization.ReportedException) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException)

Aggregations

BuildCancelledException (org.gradle.api.BuildCancelledException)5 InternalBuildCancelledException (org.gradle.tooling.internal.protocol.InternalBuildCancelledException)3 BuildExceptionVersion1 (org.gradle.tooling.internal.protocol.BuildExceptionVersion1)2 File (java.io.File)1 IncludedBuild (org.gradle.api.initialization.IncludedBuild)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 IncludedBuildInternal (org.gradle.composite.internal.IncludedBuildInternal)1 ProjectConfigurer (org.gradle.execution.ProjectConfigurer)1 BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)1 ReportedException (org.gradle.initialization.ReportedException)1 ClassPath (org.gradle.internal.classpath.ClassPath)1 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)1 DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)1 DaemonStoppedException (org.gradle.launcher.daemon.server.api.DaemonStoppedException)1 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)1 DefaultBuildActionParameters (org.gradle.launcher.exec.DefaultBuildActionParameters)1 UnsupportedVersionException (org.gradle.tooling.UnsupportedVersionException)1 InternalBuildActionFailureException (org.gradle.tooling.internal.protocol.InternalBuildActionFailureException)1 InternalBuildController (org.gradle.tooling.internal.protocol.InternalBuildController)1