Search in sources :

Example 11 with ServiceRegistry

use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.

the class BuildActionsFactory method runBuildWithDaemon.

private Runnable runBuildWithDaemon(StartParameter startParameter, DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
    // Create a client that will match based on the daemon startup parameters.
    ServiceRegistry clientSharedServices = createGlobalClientServices();
    ServiceRegistry clientServices = clientSharedServices.get(DaemonClientFactory.class).createBuildClientServices(loggingServices.get(OutputEventListener.class), daemonParameters, System.in);
    DaemonClient client = clientServices.get(DaemonClient.class);
    return runBuildAndCloseServices(startParameter, daemonParameters, client, clientSharedServices, clientServices);
}
Also used : DaemonClient(org.gradle.launcher.daemon.client.DaemonClient) DaemonClientFactory(org.gradle.launcher.daemon.client.DaemonClientFactory) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener)

Example 12 with ServiceRegistry

use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.

the class TestUtility method createMockProject.

/**
     * Creates a mock project with the specified properties.
     *
     * Note: depth is 0 for a root project. 1 for a root project's subproject, etc.
     */
public static Project createMockProject(JUnit4Mockery context, final String name, final String buildFilePath, final int depth, Project[] subProjectArray, Task[] tasks, String[] defaultTasks) {
    final ProjectInternal project = context.mock(ProjectInternal.class, "[project]_" + name + '_' + uniqueNameCounter++);
    final ServiceRegistry services = ServiceRegistryBuilder.builder().provider(new Object() {

        ProjectTaskLister createTaskLister() {
            return new DefaultProjectTaskLister();
        }
    }).build();
    context.checking(new Expectations() {

        {
            allowing(project).getName();
            will(returnValue(name));
            allowing(project).getDescription();
            will(returnValue(null));
            allowing(project).getBuildFile();
            will(returnValue(new File(buildFilePath)));
            allowing(project).getDepth();
            will(returnValue(depth));
            allowing(project).getServices();
            will(returnValue(services));
        }
    });
    attachSubProjects(context, project, subProjectArray);
    attachTasks(context, project, tasks);
    assignDefaultTasks(context, project, defaultTasks);
    return project;
}
Also used : Expectations(org.jmock.Expectations) DefaultProjectTaskLister(org.gradle.api.internal.project.DefaultProjectTaskLister) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) File(java.io.File)

Example 13 with ServiceRegistry

use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.

the class DefaultGradleLauncherFactory method createChildInstance.

private GradleLauncher createChildInstance(BuildDefinition buildDefinition, GradleLauncher parent, BuildTreeScopeServices buildTreeScopeServices, List<?> servicesToStop) {
    ServiceRegistry services = parent.getGradle().getServices();
    BuildRequestMetaData requestMetaData = new DefaultBuildRequestMetaData(services.get(BuildClientMetaData.class));
    BuildCancellationToken cancellationToken = services.get(BuildCancellationToken.class);
    BuildEventConsumer buildEventConsumer = services.get(BuildEventConsumer.class);
    return doNewInstance(buildDefinition, parent, cancellationToken, requestMetaData, buildEventConsumer, buildTreeScopeServices, servicesToStop);
}
Also used : GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) ServiceRegistry(org.gradle.internal.service.ServiceRegistry)

Example 14 with ServiceRegistry

use of org.gradle.internal.service.ServiceRegistry 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 15 with ServiceRegistry

use of org.gradle.internal.service.ServiceRegistry in project gradle by gradle.

the class BuildActionsFactory method runBuildInSingleUseDaemon.

private Runnable runBuildInSingleUseDaemon(StartParameterInternal startParameter, DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
    // (SF) this is a workaround until this story is completed. I'm hardcoding setting the idle timeout to be max X mins.
    // this way we avoid potential runaway daemons that steal resources on linux and break builds on windows.
    // We might leave that in if we decide it's a good idea for an extra safety net.
    int maxTimeout = 2 * 60 * 1000;
    if (daemonParameters.getIdleTimeout() > maxTimeout) {
        daemonParameters.setIdleTimeout(maxTimeout);
    }
    // end of workaround.
    // Create a client that will not match any existing daemons, so it will always startup a new one
    ServiceRegistry clientSharedServices = createGlobalClientServices(true);
    ServiceRegistry clientServices = clientSharedServices.get(DaemonClientFactory.class).createSingleUseDaemonClientServices(loggingServices.get(OutputEventListener.class), daemonParameters, System.in);
    DaemonClient client = clientServices.get(DaemonClient.class);
    return runBuildAndCloseServices(startParameter, daemonParameters, client, clientSharedServices, clientServices);
}
Also used : DaemonClient(org.gradle.launcher.daemon.client.DaemonClient) DaemonClientFactory(org.gradle.launcher.daemon.client.DaemonClientFactory) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener)

Aggregations

ServiceRegistry (org.gradle.internal.service.ServiceRegistry)20 GradleUserHomeScopeServiceRegistry (org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry)9 OutputEventListener (org.gradle.internal.logging.events.OutputEventListener)7 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)6 DaemonClientFactory (org.gradle.launcher.daemon.client.DaemonClientFactory)6 DaemonClient (org.gradle.launcher.daemon.client.DaemonClient)5 File (java.io.File)4 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)3 DaemonStopClient (org.gradle.launcher.daemon.client.DaemonStopClient)3 StartParameter (org.gradle.StartParameter)2 BuildLayoutParameters (org.gradle.initialization.BuildLayoutParameters)2 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)2 ObjectConnection (org.gradle.internal.remote.ObjectConnection)2 BuildSessionScopeServices (org.gradle.internal.service.scopes.BuildSessionScopeServices)2 CrossBuildSessionScopeServices (org.gradle.internal.service.scopes.CrossBuildSessionScopeServices)2 DaemonParameters (org.gradle.launcher.daemon.configuration.DaemonParameters)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 GradleInternal (org.gradle.api.internal.GradleInternal)1