Search in sources :

Example 1 with ServiceRegistry

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

the class DefaultGradleUserHomeScopeServiceRegistry method getServicesFor.

@Override
public ServiceRegistry getServicesFor(final File gradleUserHomeDir) {
    lock.lock();
    try {
        Services services = servicesForHomeDir.get(gradleUserHomeDir);
        if (services == null) {
            if (servicesForHomeDir.size() == 1) {
                Services otherServices = servicesForHomeDir.values().iterator().next();
                if (otherServices.count == 0) {
                    // Other home dir cached and not in use, clean it up
                    CompositeStoppable.stoppable(otherServices.registry).stop();
                    servicesForHomeDir.clear();
                }
            }
            ServiceRegistry userHomeServices = ServiceRegistryBuilder.builder().parent(sharedServices).displayName("services for Gradle user home dir " + gradleUserHomeDir).provider(new Object() {

                GradleUserHomeDirProvider createGradleUserHomeDirProvider() {
                    return new GradleUserHomeDirProvider() {

                        @Override
                        public File getGradleUserHomeDirectory() {
                            return gradleUserHomeDir;
                        }
                    };
                }
            }).provider(provider).build();
            services = new Services(userHomeServices);
            servicesForHomeDir.put(gradleUserHomeDir, services);
        }
        services.count++;
        return services.registry;
    } finally {
        lock.unlock();
    }
}
Also used : GradleUserHomeDirProvider(org.gradle.initialization.GradleUserHomeDirProvider) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) File(java.io.File)

Example 2 with ServiceRegistry

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

the class ProjectBuilderImpl method getUserHomeServices.

private ServiceRegistry getUserHomeServices(File userHomeDir) {
    ServiceRegistry globalServices = getGlobalServices();
    GradleUserHomeScopeServiceRegistry userHomeScopeServiceRegistry = globalServices.get(GradleUserHomeScopeServiceRegistry.class);
    return userHomeScopeServiceRegistry.getServicesFor(userHomeDir);
}
Also used : GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry)

Example 3 with ServiceRegistry

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

the class BuildActionsFactory method runBuildInSingleUseDaemon.

private Runnable runBuildInSingleUseDaemon(StartParameter 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();
    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) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener)

Example 4 with ServiceRegistry

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

the class ProviderConnection method createExecuter.

private BuildActionExecuter<ProviderOperationParameters> createExecuter(ProviderOperationParameters operationParameters, Parameters params) {
    LoggingManagerInternal loggingManager;
    BuildActionExecuter<BuildActionParameters> executer;
    if (Boolean.TRUE.equals(operationParameters.isEmbedded())) {
        loggingManager = loggingServices.getFactory(LoggingManagerInternal.class).create();
        loggingManager.captureSystemSources();
        executer = embeddedExecutor;
    } else {
        LoggingServiceRegistry loggingServices = LoggingServiceRegistry.newNestedLogging();
        loggingManager = loggingServices.getFactory(LoggingManagerInternal.class).create();
        InputStream standardInput = operationParameters.getStandardInput();
        ServiceRegistry clientServices = daemonClientFactory.createBuildClientServices(loggingServices.get(OutputEventListener.class), params.daemonParams, standardInput == null ? SafeStreams.emptyInput() : standardInput);
        executer = clientServices.get(DaemonClient.class);
    }
    return new LoggingBridgingBuildActionExecuter(new DaemonBuildActionExecuter(executer, params.daemonParams), loggingManager);
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DaemonClient(org.gradle.launcher.daemon.client.DaemonClient) InputStream(java.io.InputStream) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) OutputEventListener(org.gradle.internal.logging.events.OutputEventListener) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry)

Example 5 with ServiceRegistry

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

the class CommandLineActionFactory method convert.

/**
     * <p>Converts the given command-line arguments to an {@link Action} which performs the action requested by the
     * command-line args.
     *
     * @param args The command-line arguments.
     * @return The action to execute.
     */
public Action<ExecutionListener> convert(List<String> args) {
    ServiceRegistry loggingServices = createLoggingServices();
    LoggingConfiguration loggingConfiguration = new DefaultLoggingConfiguration();
    return new WithLogging(loggingServices, args, loggingConfiguration, new ExceptionReportingAction(new JavaRuntimeValidationAction(new ParseAndBuildAction(loggingServices, args)), new BuildExceptionReporter(loggingServices.get(StyledTextOutputFactory.class), loggingConfiguration, clientMetaData())));
}
Also used : StyledTextOutputFactory(org.gradle.internal.logging.text.StyledTextOutputFactory) LoggingConfiguration(org.gradle.api.logging.configuration.LoggingConfiguration) DefaultLoggingConfiguration(org.gradle.internal.logging.DefaultLoggingConfiguration) DefaultLoggingConfiguration(org.gradle.internal.logging.DefaultLoggingConfiguration) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) BuildExceptionReporter(org.gradle.internal.buildevents.BuildExceptionReporter)

Aggregations

ServiceRegistry (org.gradle.internal.service.ServiceRegistry)12 OutputEventListener (org.gradle.internal.logging.events.OutputEventListener)5 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)4 DaemonClientFactory (org.gradle.launcher.daemon.client.DaemonClientFactory)4 File (java.io.File)3 GradleUserHomeScopeServiceRegistry (org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry)3 DaemonClient (org.gradle.launcher.daemon.client.DaemonClient)3 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 DaemonStopClient (org.gradle.launcher.daemon.client.DaemonStopClient)2 InputStream (java.io.InputStream)1 StartParameter (org.gradle.StartParameter)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 FileResolver (org.gradle.api.internal.file.FileResolver)1 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)1 DefaultProjectTaskLister (org.gradle.api.internal.project.DefaultProjectTaskLister)1 IProjectFactory (org.gradle.api.internal.project.IProjectFactory)1 LoggingConfiguration (org.gradle.api.logging.configuration.LoggingConfiguration)1 BuildLayoutParameters (org.gradle.initialization.BuildLayoutParameters)1 DefaultProjectDescriptor (org.gradle.initialization.DefaultProjectDescriptor)1 DefaultProjectDescriptorRegistry (org.gradle.initialization.DefaultProjectDescriptorRegistry)1