Search in sources :

Example 1 with WorkerLeaseService

use of org.gradle.internal.work.WorkerLeaseService in project gradle by gradle.

the class DefaultIncludedBuild method execute.

@Override
public synchronized void execute(final Iterable<String> tasks, final Object listener) {
    cleanupLauncherIfRequired();
    final GradleLauncher launcher = getGradleLauncher();
    launcher.addListener(listener);
    launcher.scheduleTasks(tasks);
    WorkerLeaseService workerLeaseService = launcher.getGradle().getServices().get(WorkerLeaseService.class);
    try {
        workerLeaseService.withSharedLease(parentLease, new Runnable() {

            @Override
            public void run() {
                launcher.executeTasks();
            }
        });
    } finally {
        markAsNotReusable();
    }
}
Also used : GradleLauncher(org.gradle.initialization.GradleLauncher) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService)

Example 2 with WorkerLeaseService

use of org.gradle.internal.work.WorkerLeaseService 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)

Aggregations

WorkerLeaseService (org.gradle.internal.work.WorkerLeaseService)2 File (java.io.File)1 StartParameter (org.gradle.StartParameter)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 GradleLauncher (org.gradle.initialization.GradleLauncher)1 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)1 DefaultResourceLockCoordinationService (org.gradle.internal.resources.DefaultResourceLockCoordinationService)1 ResourceLockCoordinationService (org.gradle.internal.resources.ResourceLockCoordinationService)1 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)1 BuildSessionScopeServices (org.gradle.internal.service.scopes.BuildSessionScopeServices)1 BuildTreeScopeServices (org.gradle.internal.service.scopes.BuildTreeScopeServices)1