Search in sources :

Example 11 with DefaultServiceRegistry

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

the class WorkerAction method execute.

@Override
public void execute(WorkerProcessContext workerProcessContext) {
    completed = new CountDownLatch(1);
    RequestArgumentSerializers argumentSerializers = new RequestArgumentSerializers();
    try {
        ServiceRegistry parentServices = workerProcessContext.getServiceRegistry();
        if (instantiatorFactory == null) {
            instantiatorFactory = new DefaultInstantiatorFactory(new DefaultCrossBuildInMemoryCacheFactory(new DefaultListenerManager(Global.class)), Collections.emptyList(), new OutputPropertyRoleAnnotationHandler(Collections.emptyList()));
        }
        DefaultServiceRegistry serviceRegistry = new DefaultServiceRegistry("worker-action-services", parentServices);
        // Make the argument serializers available so work implementations can register their own serializers
        serviceRegistry.add(RequestArgumentSerializers.class, argumentSerializers);
        serviceRegistry.add(InstantiatorFactory.class, instantiatorFactory);
        Class<?> workerImplementation = Class.forName(workerImplementationName);
        implementation = Cast.uncheckedNonnullCast(instantiatorFactory.inject(serviceRegistry).newInstance(workerImplementation));
    } catch (Exception e) {
        failure = e;
    }
    ObjectConnection connection = workerProcessContext.getServerConnection();
    connection.addIncoming(RequestProtocol.class, this);
    responder = connection.addOutgoing(ResponseProtocol.class);
    workerLogEventListener = workerProcessContext.getServiceRegistry().get(WorkerLogEventListener.class);
    if (failure == null) {
        connection.useParameterSerializers(RequestSerializerRegistry.create(this.getClass().getClassLoader(), argumentSerializers));
    } else {
        // Discard incoming requests, as the serializers may not have been configured
        connection.useParameterSerializers(RequestSerializerRegistry.createDiscardRequestArg());
        // Notify the client
        responder.infrastructureFailed(failure);
    }
    connection.connect();
    try {
        completed.await();
    } catch (InterruptedException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : DefaultInstantiatorFactory(org.gradle.internal.instantiation.generator.DefaultInstantiatorFactory) DefaultCrossBuildInMemoryCacheFactory(org.gradle.cache.internal.DefaultCrossBuildInMemoryCacheFactory) DefaultListenerManager(org.gradle.internal.event.DefaultListenerManager) WorkerLogEventListener(org.gradle.process.internal.worker.child.WorkerLogEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Global(org.gradle.internal.service.scopes.Scope.Global) UncheckedException(org.gradle.internal.UncheckedException) ObjectConnection(org.gradle.internal.remote.ObjectConnection) DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) OutputPropertyRoleAnnotationHandler(org.gradle.api.internal.tasks.properties.annotations.OutputPropertyRoleAnnotationHandler) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry)

Example 12 with DefaultServiceRegistry

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

the class DefaultIvyArtifactRepository method createInjectorForMetadataSupplier.

/**
 * Creates a service registry giving access to the services we want to expose to rules and returns an instantiator that uses this service registry.
 *
 * @param transport the transport used to create the repository accessor
 * @return a dependency injecting instantiator, aware of services we want to expose
 */
private Instantiator createInjectorForMetadataSupplier(final RepositoryTransport transport) {
    DefaultServiceRegistry registry = new DefaultServiceRegistry();
    registry.addProvider(new Object() {

        RepositoryResourceAccessor createResourceAccessor() {
            return createRepositoryAccessor(transport);
        }
    });
    return instantiatorFactory.inject(registry);
}
Also used : DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) RepositoryResourceAccessor(org.gradle.api.artifacts.repositories.RepositoryResourceAccessor) ExternalRepositoryResourceAccessor(org.gradle.api.internal.artifacts.repositories.resolver.ExternalRepositoryResourceAccessor)

Example 13 with DefaultServiceRegistry

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

the class DaemonClientFactory method createStopDaemonServices.

/**
 * Creates the services for a {@link DaemonStopClient} that can be used to stop builds.
 */
public ServiceRegistry createStopDaemonServices(OutputEventListener loggingReceiver, DaemonParameters daemonParameters) {
    DefaultServiceRegistry loggingServices = new DefaultServiceRegistry(sharedServices);
    loggingServices.add(OutputEventListener.class, loggingReceiver);
    return new DaemonClientServices(loggingServices, daemonParameters, new ByteArrayInputStream(new byte[0]));
}
Also used : DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 14 with DefaultServiceRegistry

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

the class DefaultValueSourceProviderFactory method instantiateValueSource.

@NotNull
public <T, P extends ValueSourceParameters> ValueSource<T, P> instantiateValueSource(Class<? extends ValueSource<T, P>> valueSourceType, @Nullable Class<P> parametersType, @Nullable P isolatedParameters) {
    DefaultServiceRegistry services = new DefaultServiceRegistry();
    services.add(GradleProperties.class, gradleProperties);
    services.add(ExecOperations.class, execOperations);
    if (isolatedParameters != null) {
        services.add(parametersType, isolatedParameters);
    }
    return instantiatorFactory.injectScheme().withServices(services).instantiator().newInstance(valueSourceType);
}
Also used : DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with DefaultServiceRegistry

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

the class AsmBackedClassGeneratorTest method newInstance.

private <T> T newInstance(Class<T> clazz, Object... args) throws Exception {
    DefaultServiceRegistry services = new DefaultServiceRegistry();
    services.add(InstantiatorFactory.class, TestUtil.instantiatorFactory());
    return newInstance(clazz, services, args);
}
Also used : DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry)

Aggregations

DefaultServiceRegistry (org.gradle.internal.service.DefaultServiceRegistry)17 RepositoryResourceAccessor (org.gradle.api.artifacts.repositories.RepositoryResourceAccessor)3 ExternalRepositoryResourceAccessor (org.gradle.api.internal.artifacts.repositories.resolver.ExternalRepositoryResourceAccessor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectConnection (org.gradle.internal.remote.ObjectConnection)2 File (java.io.File)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 DependencyInjectingInstantiator (org.gradle.api.internal.DependencyInjectingInstantiator)1 DomainObjectContext (org.gradle.api.internal.DomainObjectContext)1 DependencyManagementServices (org.gradle.api.internal.artifacts.DependencyManagementServices)1 DependencyResolutionServices (org.gradle.api.internal.artifacts.DependencyResolutionServices)1 UnknownProjectFinder (org.gradle.api.internal.artifacts.dsl.dependencies.UnknownProjectFinder)1 DependencyVerificationOverride (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DependencyVerificationOverride)1 OutputPropertyRoleAnnotationHandler (org.gradle.api.internal.tasks.properties.annotations.OutputPropertyRoleAnnotationHandler)1 PropertyAnnotationHandler (org.gradle.api.internal.tasks.properties.annotations.PropertyAnnotationHandler)1 DefaultCrossBuildInMemoryCacheFactory (org.gradle.cache.internal.DefaultCrossBuildInMemoryCacheFactory)1 UncheckedException (org.gradle.internal.UncheckedException)1 DefaultExecutorFactory (org.gradle.internal.concurrent.DefaultExecutorFactory)1 DefaultListenerManager (org.gradle.internal.event.DefaultListenerManager)1 ExtensibleDynamicObject (org.gradle.internal.extensibility.ExtensibleDynamicObject)1