use of org.gradle.api.internal.project.ProjectState in project gradle by gradle.
the class ProjectScopeServices method createPluginRegistry.
protected PluginRegistry createPluginRegistry(PluginRegistry rootRegistry) {
PluginRegistry parentRegistry;
ProjectState parent = project.getOwner().getBuildParent();
if (parent == null) {
parentRegistry = rootRegistry.createChild(project.getBaseClassLoaderScope());
} else {
parentRegistry = parent.getMutableModel().getServices().get(PluginRegistry.class);
}
return parentRegistry.createChild(project.getClassLoaderScope());
}
use of org.gradle.api.internal.project.ProjectState in project gradle by gradle.
the class ProjectBuilderImpl method createChildProject.
public Project createChildProject(String name, Project parent, File projectDir) {
ProjectInternal parentProject = (ProjectInternal) parent;
ProjectDescriptorRegistry descriptorRegistry = parentProject.getServices().get(ProjectDescriptorRegistry.class);
DefaultProjectDescriptor parentDescriptor = descriptorRegistry.getProject(parentProject.getPath());
projectDir = (projectDir != null) ? projectDir.getAbsoluteFile() : new File(parentProject.getProjectDir(), name);
DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(parentDescriptor, name, projectDir, descriptorRegistry, parentProject.getServices().get(FileResolver.class));
descriptorRegistry.addProject(projectDescriptor);
ProjectState projectState = parentProject.getServices().get(ProjectStateRegistry.class).registerProject(parentProject.getServices().get(BuildState.class), projectDescriptor);
projectState.createMutableModel(parentProject.getClassLoaderScope().createChild("project-" + name), parentProject.getBaseClassLoaderScope());
ProjectInternal project = projectState.getMutableModel();
// Lock the project, these won't ever be released as ProjectBuilder has no lifecycle
ResourceLockCoordinationService coordinationService = project.getServices().get(ResourceLockCoordinationService.class);
coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(project.getOwner().getAccessLock()));
return project;
}
use of org.gradle.api.internal.project.ProjectState 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.api.internal.project.ProjectState in project gradle by gradle.
the class DefaultRootComponentMetadataBuilder method buildRootComponentMetadata.
private DefaultLocalComponentMetadata buildRootComponentMetadata(final Module module, final ComponentIdentifier componentIdentifier) {
final ModuleVersionIdentifier moduleVersionIdentifier = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getName(), module.getVersion());
ProjectComponentIdentifier projectId = module.getProjectId();
if (projectId != null) {
ProjectState projectState = projectStateRegistry.stateFor(projectId);
if (!projectState.hasMutableState()) {
throw new IllegalStateException("Thread should hold project lock for " + projectId);
}
return projectState.fromMutableState(project -> {
AttributesSchemaInternal schema = (AttributesSchemaInternal) project.getDependencies().getAttributesSchema();
return getRootComponentMetadata(module, componentIdentifier, moduleVersionIdentifier, schema, dependencyLockingProvider);
});
} else {
return getRootComponentMetadata(module, componentIdentifier, moduleVersionIdentifier, null, dependencyLockingProvider);
}
}
use of org.gradle.api.internal.project.ProjectState in project gradle by gradle.
the class DefaultLocalComponentRegistry method getComponent.
@Override
public LocalComponentMetadata getComponent(ProjectComponentIdentifier projectIdentifier) {
CalculatedValueContainer<LocalComponentMetadata, ?> valueContainer = projects.computeIfAbsent(projectIdentifier, projectComponentIdentifier -> {
ProjectState projectState = projectStateRegistry.stateFor(projectIdentifier);
return calculatedValueContainerFactory.create(Describables.of("metadata of", projectIdentifier), new MetadataSupplier(projectState));
});
// Calculate the value after adding the entry to the map, so that the value container can take care of thread synchronization
valueContainer.finalizeIfNotAlready();
return valueContainer.get();
}
Aggregations