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