Search in sources :

Example 1 with OutputPropertyRoleAnnotationHandler

use of org.gradle.api.internal.tasks.properties.annotations.OutputPropertyRoleAnnotationHandler 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)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 OutputPropertyRoleAnnotationHandler (org.gradle.api.internal.tasks.properties.annotations.OutputPropertyRoleAnnotationHandler)1 DefaultCrossBuildInMemoryCacheFactory (org.gradle.cache.internal.DefaultCrossBuildInMemoryCacheFactory)1 UncheckedException (org.gradle.internal.UncheckedException)1 DefaultListenerManager (org.gradle.internal.event.DefaultListenerManager)1 DefaultInstantiatorFactory (org.gradle.internal.instantiation.generator.DefaultInstantiatorFactory)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 DefaultServiceRegistry (org.gradle.internal.service.DefaultServiceRegistry)1 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)1 Global (org.gradle.internal.service.scopes.Scope.Global)1 WorkerLogEventListener (org.gradle.process.internal.worker.child.WorkerLogEventListener)1