use of org.gradle.internal.buildtree.BuildTreeState 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.internal.buildtree.BuildTreeState in project gradle by gradle.
the class ProjectBuilderImpl method createProject.
public ProjectInternal createProject(String name, File inputProjectDir, File gradleUserHomeDir) {
final File projectDir = prepareProjectDir(inputProjectDir);
File userHomeDir = gradleUserHomeDir == null ? new File(projectDir, "userHome") : FileUtils.canonicalize(gradleUserHomeDir);
StartParameterInternal startParameter = new StartParameterInternal();
startParameter.setGradleUserHomeDir(userHomeDir);
NativeServices.initializeOnDaemon(userHomeDir);
final ServiceRegistry globalServices = getGlobalServices();
BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
CrossBuildSessionState crossBuildSessionState = new CrossBuildSessionState(globalServices, startParameter);
GradleUserHomeScopeServiceRegistry userHomeServices = userHomeServicesOf(globalServices);
BuildSessionState buildSessionState = new BuildSessionState(userHomeServices, crossBuildSessionState, startParameter, buildRequestMetaData, ClassPath.EMPTY, new DefaultBuildCancellationToken(), buildRequestMetaData.getClient(), new NoOpBuildEventConsumer());
BuildTreeModelControllerServices.Supplier modelServices = buildSessionState.getServices().get(BuildTreeModelControllerServices.class).servicesForBuildTree(new RunTasksRequirements(startParameter));
BuildTreeState buildTreeState = new BuildTreeState(buildSessionState.getServices(), modelServices);
TestRootBuild build = new TestRootBuild(projectDir, startParameter, buildTreeState);
BuildScopeServices buildServices = build.getBuildServices();
buildServices.get(BuildStateRegistry.class).attachRootBuild(build);
// Take a root worker lease; this won't ever be released as ProjectBuilder has no lifecycle
ResourceLockCoordinationService coordinationService = buildServices.get(ResourceLockCoordinationService.class);
WorkerLeaseService workerLeaseService = buildServices.get(WorkerLeaseService.class);
WorkerLeaseRegistry.WorkerLeaseCompletion workerLease = workerLeaseService.maybeStartWorker();
GradleInternal gradle = build.getMutableModel();
gradle.setIncludedBuilds(Collections.emptyList());
ProjectDescriptorRegistry projectDescriptorRegistry = buildServices.get(ProjectDescriptorRegistry.class);
DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, projectDescriptorRegistry, buildServices.get(FileResolver.class));
projectDescriptorRegistry.addProject(projectDescriptor);
ClassLoaderScope baseScope = gradle.getClassLoaderScope();
ClassLoaderScope rootProjectScope = baseScope.createChild("root-project");
ProjectStateRegistry projectStateRegistry = buildServices.get(ProjectStateRegistry.class);
ProjectState projectState = projectStateRegistry.registerProject(build, projectDescriptor);
projectState.createMutableModel(rootProjectScope, baseScope);
ProjectInternal project = projectState.getMutableModel();
gradle.setRootProject(project);
gradle.setDefaultProject(project);
// Lock root project; this won't ever be released as ProjectBuilder has no lifecycle
coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(project.getOwner().getAccessLock()));
project.getExtensions().getExtraProperties().set("ProjectBuilder.stoppable", stoppable((Stoppable) workerLeaseService::runAsIsolatedTask, (Stoppable) workerLease::leaseFinish, buildServices, buildTreeState, buildSessionState, crossBuildSessionState));
return project;
}
use of org.gradle.internal.buildtree.BuildTreeState in project gradle by gradle.
the class DefaultNestedBuildTree method run.
@Override
public <T> T run(Function<? super BuildTreeLifecycleController, T> buildAction) {
StartParameterInternal startParameter = buildDefinition.getStartParameter();
BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
BuildSessionState session = new BuildSessionState(userHomeDirServiceRegistry, crossBuildSessionState, startParameter, buildRequestMetaData, ClassPath.EMPTY, buildCancellationToken, buildRequestMetaData.getClient(), new NoOpBuildEventConsumer());
try {
session.getServices().get(BuildLayoutValidator.class).validate(startParameter);
BuildTreeModelControllerServices.Supplier modelServices = session.getServices().get(BuildTreeModelControllerServices.class).servicesForNestedBuildTree(startParameter);
BuildTreeState buildTree = new BuildTreeState(session.getServices(), modelServices);
try {
RootOfNestedBuildTree rootBuild = new RootOfNestedBuildTree(buildDefinition, buildIdentifier, identityPath, owner, buildTree);
rootBuild.attach();
return rootBuild.run(buildAction);
} finally {
buildTree.close();
}
} finally {
session.close();
}
}
Aggregations