use of org.gradle.tooling.internal.provider.action.BuildModelAction in project gradle by gradle.
the class BuildModelActionRunner method run.
@Override
public Result run(BuildAction action, final BuildTreeLifecycleController buildController) {
if (!(action instanceof BuildModelAction)) {
return Result.nothing();
}
BuildModelAction buildModelAction = (BuildModelAction) action;
ModelCreateAction createAction = new ModelCreateAction(buildModelAction);
try {
if (buildModelAction.isCreateModel()) {
Object result = buildController.fromBuildModel(buildModelAction.isRunTasks(), createAction);
SerializedPayload serializedResult = payloadSerializer.serialize(result);
return Result.of(serializedResult);
} else {
buildController.scheduleAndRunTasks();
return Result.of(null);
}
} catch (RuntimeException e) {
RuntimeException clientFailure = e;
if (createAction.modelLookupFailure != null) {
clientFailure = (RuntimeException) new InternalUnsupportedModelException().initCause(createAction.modelLookupFailure);
}
return Result.failed(e, clientFailure);
}
}
use of org.gradle.tooling.internal.provider.action.BuildModelAction in project gradle by gradle.
the class BuildTreeLifecycleBuildActionExecutor method execute.
@Override
public BuildActionRunner.Result execute(BuildAction action, BuildSessionContext buildSession) {
BuildActionRunner.Result result = null;
try {
buildLayoutValidator.validate(action.getStartParameter());
BuildActionModelRequirements actionRequirements;
if (action instanceof BuildModelAction && action.isCreateModel()) {
BuildModelAction buildModelAction = (BuildModelAction) action;
actionRequirements = new QueryModelRequirements(action.getStartParameter(), action.isRunTasks(), buildModelAction.getModelName());
} else if (action instanceof ClientProvidedBuildAction) {
actionRequirements = new RunActionRequirements(action.getStartParameter(), action.isRunTasks());
} else if (action instanceof ClientProvidedPhasedAction) {
actionRequirements = new RunPhasedActionRequirements(action.getStartParameter(), action.isRunTasks());
} else {
actionRequirements = new RunTasksRequirements(action.getStartParameter());
}
BuildTreeModelControllerServices.Supplier modelServices = buildTreeModelControllerServices.servicesForBuildTree(actionRequirements);
BuildTreeState buildTree = new BuildTreeState(buildSession.getServices(), modelServices);
try {
result = buildTree.run(context -> context.execute(action));
} finally {
buildTree.close();
}
} catch (Throwable t) {
if (result == null) {
// whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
throw UncheckedException.throwAsUncheckedException(t);
} else {
// whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
throw UncheckedException.throwAsUncheckedException(result.addFailure(t).getBuildFailure());
}
}
return result;
}
use of org.gradle.tooling.internal.provider.action.BuildModelAction in project gradle by gradle.
the class ProviderConnection method run.
public Object run(String modelName, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
List<String> tasks = providerParameters.getTasks();
if (modelName.equals(ModelIdentifier.NULL_MODEL) && tasks == null) {
throw new IllegalArgumentException("No model type or tasks specified.");
}
Parameters params = initParams(providerParameters);
if (BuildEnvironment.class.getName().equals(modelName)) {
// we don't really need to launch the daemon to acquire information needed for BuildEnvironment
if (tasks != null) {
throw new IllegalArgumentException("Cannot run tasks and fetch the build environment model.");
}
return new DefaultBuildEnvironment(new DefaultBuildIdentifier(providerParameters.getProjectDir()), params.buildLayout.getGradleUserHomeDir(), GradleVersion.current().getVersion(), params.daemonParams.getEffectiveJvm().getJavaHome(), params.daemonParams.getEffectiveJvmArgs());
}
StartParameterInternal startParameter = new ProviderStartParameterConverter().toStartParameter(providerParameters, params.buildLayout, params.properties);
ProgressListenerConfiguration listenerConfig = ProgressListenerConfiguration.from(providerParameters, consumerVersion);
BuildAction action = new BuildModelAction(startParameter, modelName, tasks != null, listenerConfig.clientSubscriptions);
return run(action, cancellationToken, listenerConfig, listenerConfig.buildEventConsumer, providerParameters, params);
}
Aggregations