Search in sources :

Example 16 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope 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;
}
Also used : BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) WorkerLeaseRegistry(org.gradle.internal.work.WorkerLeaseRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) GradleInternal(org.gradle.api.internal.GradleInternal) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) RunTasksRequirements(org.gradle.internal.buildtree.RunTasksRequirements) ResourceLockCoordinationService(org.gradle.internal.resources.ResourceLockCoordinationService) DefaultResourceLockCoordinationService(org.gradle.internal.resources.DefaultResourceLockCoordinationService) FileResolver(org.gradle.api.internal.file.FileResolver) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildStateRegistry(org.gradle.internal.build.BuildStateRegistry) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildSessionState(org.gradle.internal.session.BuildSessionState) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) Stoppable(org.gradle.internal.concurrent.Stoppable) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState) DefaultProjectDescriptor(org.gradle.initialization.DefaultProjectDescriptor) NoOpBuildEventConsumer(org.gradle.initialization.NoOpBuildEventConsumer) ProjectDescriptorRegistry(org.gradle.initialization.ProjectDescriptorRegistry) DefaultBuildCancellationToken(org.gradle.initialization.DefaultBuildCancellationToken) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ProjectState(org.gradle.api.internal.project.ProjectState) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) ProjectStateRegistry(org.gradle.api.internal.project.ProjectStateRegistry) File(java.io.File)

Example 17 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope in project gradle by gradle.

the class DefaultInitScriptProcessor method process.

@Override
public void process(final ScriptSource initScript, GradleInternal gradle) {
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    URI uri = initScript.getResource().getLocation().getURI();
    String id = uri == null ? idGenerator.generateId().toString() : uri.toString();
    ClassLoaderScope scriptScope = baseScope.createChild("init-" + id);
    ScriptHandler scriptHandler = scriptHandlerFactory.create(initScript, scriptScope);
    ScriptPlugin configurer = configurerFactory.create(initScript, scriptHandler, scriptScope, baseScope, true);
    configurer.apply(gradle);
}
Also used : ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) URI(java.net.URI) ScriptHandler(org.gradle.api.initialization.dsl.ScriptHandler)

Example 18 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope in project gradle by gradle.

the class InstantiatingBuildLoader method createProjects.

private void createProjects(GradleInternal gradle, DefaultProjectDescriptor rootProjectDescriptor) {
    ClassLoaderScope baseProjectClassLoaderScope = gradle.baseProjectClassLoaderScope();
    ClassLoaderScope rootProjectClassLoaderScope = baseProjectClassLoaderScope.createChild("root-project[" + gradle.getIdentityPath() + "]");
    ProjectState projectState = gradle.getOwner().getProjects().getProject(rootProjectDescriptor.path());
    projectState.createMutableModel(rootProjectClassLoaderScope, baseProjectClassLoaderScope);
    ProjectInternal rootProject = projectState.getMutableModel();
    gradle.setRootProject(rootProject);
    createChildProjectsRecursively(gradle.getOwner(), rootProjectDescriptor, rootProjectClassLoaderScope, baseProjectClassLoaderScope);
}
Also used : ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ProjectState(org.gradle.api.internal.project.ProjectState)

Aggregations

ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)18 File (java.io.File)4 URI (java.net.URI)2 Nullable (javax.annotation.Nullable)2 ScriptHandler (org.gradle.api.initialization.dsl.ScriptHandler)2 DynamicObjectAware (org.gradle.api.internal.DynamicObjectAware)2 SettingsInternal (org.gradle.api.internal.SettingsInternal)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 ProjectState (org.gradle.api.internal.project.ProjectState)2 ScriptPlugin (org.gradle.configuration.ScriptPlugin)2 ScriptSource (org.gradle.groovy.scripts.ScriptSource)2 ClassPath (org.gradle.internal.classpath.ClassPath)2 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 StringWriter (java.io.StringWriter)1 URLClassLoader (java.net.URLClassLoader)1 Collections (java.util.Collections)1