Search in sources :

Example 1 with CrossBuildSessionScopeServices

use of org.gradle.internal.service.scopes.CrossBuildSessionScopeServices in project gradle by gradle.

the class ProjectBuilderImpl method createProject.

public Project createProject(String name, File inputProjectDir, File gradleUserHomeDir) {
    File projectDir = prepareProjectDir(inputProjectDir);
    final File homeDir = new File(projectDir, "gradleHome");
    StartParameter startParameter = new StartParameterInternal();
    File userHomeDir = gradleUserHomeDir == null ? new File(projectDir, "userHome") : FileUtils.canonicalize(gradleUserHomeDir);
    startParameter.setGradleUserHomeDir(userHomeDir);
    NativeServices.initialize(userHomeDir);
    BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
    CrossBuildSessionScopeServices crossBuildSessionScopeServices = new CrossBuildSessionScopeServices(getGlobalServices(), startParameter);
    ServiceRegistry userHomeServices = getUserHomeServices(userHomeDir);
    BuildSessionScopeServices buildSessionScopeServices = new BuildSessionScopeServices(userHomeServices, crossBuildSessionScopeServices, startParameter, buildRequestMetaData, ClassPath.EMPTY);
    BuildTreeScopeServices buildTreeScopeServices = new BuildTreeScopeServices(buildSessionScopeServices);
    ServiceRegistry topLevelRegistry = new TestBuildScopeServices(buildTreeScopeServices, homeDir);
    GradleInternal gradle = CLASS_GENERATOR.newInstance(DefaultGradle.class, null, startParameter, topLevelRegistry.get(ServiceRegistryFactory.class));
    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, new DefaultProjectDescriptorRegistry(), topLevelRegistry.get(FileResolver.class));
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope rootProjectScope = baseScope.createChild("root-project");
    ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle, rootProjectScope, baseScope);
    gradle.setRootProject(project);
    gradle.setDefaultProject(project);
    // Take a root worker lease, it won't ever be released as ProjectBuilder has no lifecycle
    ResourceLockCoordinationService coordinationService = topLevelRegistry.get(ResourceLockCoordinationService.class);
    WorkerLeaseService workerLeaseService = topLevelRegistry.get(WorkerLeaseService.class);
    coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(workerLeaseService.getWorkerLease()));
    return project;
}
Also used : DefaultProjectDescriptorRegistry(org.gradle.initialization.DefaultProjectDescriptorRegistry) StartParameter(org.gradle.StartParameter) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService) BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) BuildTreeScopeServices(org.gradle.internal.service.scopes.BuildTreeScopeServices) BuildSessionScopeServices(org.gradle.internal.service.scopes.BuildSessionScopeServices) CrossBuildSessionScopeServices(org.gradle.internal.service.scopes.CrossBuildSessionScopeServices) DefaultProjectDescriptor(org.gradle.initialization.DefaultProjectDescriptor) GradleInternal(org.gradle.api.internal.GradleInternal) IProjectFactory(org.gradle.api.internal.project.IProjectFactory) ServiceRegistryFactory(org.gradle.internal.service.scopes.ServiceRegistryFactory) CrossBuildSessionScopeServices(org.gradle.internal.service.scopes.CrossBuildSessionScopeServices) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) FileResolver(org.gradle.api.internal.file.FileResolver) ResourceLockCoordinationService(org.gradle.internal.resources.ResourceLockCoordinationService) DefaultResourceLockCoordinationService(org.gradle.internal.resources.DefaultResourceLockCoordinationService) File(java.io.File)

Example 2 with CrossBuildSessionScopeServices

use of org.gradle.internal.service.scopes.CrossBuildSessionScopeServices in project gradle by gradle.

the class ServicesSetupBuildActionExecuter method execute.

@Override
public Object execute(BuildAction action, BuildRequestContext requestContext, BuildActionParameters actionParameters, ServiceRegistry contextServices) {
    StartParameter startParameter = action.getStartParameter();
    final ServiceRegistry userHomeServices = userHomeServiceRegistry.getServicesFor(startParameter.getGradleUserHomeDir());
    CrossBuildSessionScopeServices crossBuildSessionScopeServices = new CrossBuildSessionScopeServices(contextServices, startParameter);
    try {
        ServiceRegistry buildSessionScopeServices = new BuildSessionScopeServices(userHomeServices, crossBuildSessionScopeServices, startParameter, requestContext, actionParameters.getInjectedPluginClasspath());
        try {
            SessionLifecycleListener sessionLifecycleListener = buildSessionScopeServices.get(ListenerManager.class).getBroadcaster(SessionLifecycleListener.class);
            try {
                sessionLifecycleListener.afterStart();
                return delegate.execute(action, requestContext, actionParameters, buildSessionScopeServices);
            } finally {
                sessionLifecycleListener.beforeComplete();
            }
        } finally {
            CompositeStoppable.stoppable(buildSessionScopeServices).stop();
        }
    } finally {
        new CompositeStoppable().add(new Stoppable() {

            @Override
            public void stop() {
                userHomeServiceRegistry.release(userHomeServices);
            }
        }, crossBuildSessionScopeServices).stop();
    }
}
Also used : StartParameter(org.gradle.StartParameter) CrossBuildSessionScopeServices(org.gradle.internal.service.scopes.CrossBuildSessionScopeServices) SessionLifecycleListener(org.gradle.initialization.SessionLifecycleListener) CompositeStoppable(org.gradle.internal.concurrent.CompositeStoppable) Stoppable(org.gradle.internal.concurrent.Stoppable) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) BuildSessionScopeServices(org.gradle.internal.service.scopes.BuildSessionScopeServices) CrossBuildSessionScopeServices(org.gradle.internal.service.scopes.CrossBuildSessionScopeServices) CompositeStoppable(org.gradle.internal.concurrent.CompositeStoppable) ListenerManager(org.gradle.internal.event.ListenerManager)

Aggregations

StartParameter (org.gradle.StartParameter)2 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)2 BuildSessionScopeServices (org.gradle.internal.service.scopes.BuildSessionScopeServices)2 CrossBuildSessionScopeServices (org.gradle.internal.service.scopes.CrossBuildSessionScopeServices)2 GradleUserHomeScopeServiceRegistry (org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry)2 File (java.io.File)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)1 FileResolver (org.gradle.api.internal.file.FileResolver)1 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)1 IProjectFactory (org.gradle.api.internal.project.IProjectFactory)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 BuildRequestMetaData (org.gradle.initialization.BuildRequestMetaData)1 DefaultBuildRequestMetaData (org.gradle.initialization.DefaultBuildRequestMetaData)1 DefaultProjectDescriptor (org.gradle.initialization.DefaultProjectDescriptor)1 DefaultProjectDescriptorRegistry (org.gradle.initialization.DefaultProjectDescriptorRegistry)1 SessionLifecycleListener (org.gradle.initialization.SessionLifecycleListener)1 CompositeStoppable (org.gradle.internal.concurrent.CompositeStoppable)1 Stoppable (org.gradle.internal.concurrent.Stoppable)1 ListenerManager (org.gradle.internal.event.ListenerManager)1