Search in sources :

Example 1 with GradleUserHomeDirProvider

use of org.gradle.initialization.GradleUserHomeDirProvider 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)

Aggregations

File (java.io.File)1 GradleUserHomeDirProvider (org.gradle.initialization.GradleUserHomeDirProvider)1 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)1