Search in sources :

Example 6 with DefaultServiceRegistry

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

the class SystemApplicationClassLoaderWorker method call.

@Override
public Void call() throws Exception {
    if (System.getProperty("org.gradle.worker.test.stuck") != null) {
        // Simulate a stuck worker. There's probably a way to inject this failure...
        Thread.sleep(30000);
        return null;
    }
    Decoder decoder = new InputStreamBackedDecoder(configInputStream);
    // Read logging config and setup logging
    int logLevel = decoder.readSmallInt();
    LoggingServiceRegistry loggingServiceRegistry = LoggingServiceRegistry.newEmbeddableLogging();
    LoggingManagerInternal loggingManager = createLoggingManager(loggingServiceRegistry).setLevelInternal(LogLevel.values()[logLevel]);
    // Read whether process info should be published
    boolean shouldPublishJvmMemoryInfo = decoder.readBoolean();
    // Read path to Gradle user home
    String gradleUserHomeDirPath = decoder.readString();
    File gradleUserHomeDir = new File(gradleUserHomeDirPath);
    // Read server address and start connecting
    MultiChoiceAddress serverAddress = new MultiChoiceAddressSerializer().read(decoder);
    NativeServices.initializeOnWorker(gradleUserHomeDir);
    DefaultServiceRegistry basicWorkerServices = new DefaultServiceRegistry(NativeServices.getInstance(), loggingServiceRegistry);
    basicWorkerServices.add(ExecutorFactory.class, new DefaultExecutorFactory());
    basicWorkerServices.addProvider(new MessagingServices());
    final WorkerServices workerServices = new WorkerServices(basicWorkerServices, gradleUserHomeDir);
    WorkerLogEventListener workerLogEventListener = new WorkerLogEventListener();
    workerServices.add(WorkerLogEventListener.class, workerLogEventListener);
    File workingDirectory = workerServices.get(WorkerDirectoryProvider.class).getWorkingDirectory();
    File errorLog = getLastResortErrorLogFile(workingDirectory);
    PrintUnrecoverableErrorToFileHandler unrecoverableErrorHandler = new PrintUnrecoverableErrorToFileHandler(errorLog);
    ObjectConnection connection = null;
    try {
        // Read serialized worker details
        final long workerId = decoder.readSmallLong();
        final String displayName = decoder.readString();
        byte[] serializedWorker = decoder.readBinary();
        Action<WorkerProcessContext> workerAction = deserializeWorker(serializedWorker);
        connection = basicWorkerServices.get(MessagingClient.class).getConnection(serverAddress);
        connection.addUnrecoverableErrorHandler(unrecoverableErrorHandler);
        configureLogging(loggingManager, connection, workerLogEventListener);
        // start logging now that the logging manager is connected
        loggingManager.start();
        if (shouldPublishJvmMemoryInfo) {
            configureWorkerJvmMemoryInfoEvents(workerServices, connection);
        }
        ActionExecutionWorker worker = new ActionExecutionWorker(workerAction);
        worker.execute(new ContextImpl(workerId, displayName, connection, workerServices));
    } finally {
        try {
            loggingManager.removeOutputEventListener(workerLogEventListener);
            CompositeStoppable.stoppable(connection, basicWorkerServices).stop();
            loggingManager.stop();
        } catch (Throwable t) {
            // We're failing while shutting down, so log whatever might have happened.
            unrecoverableErrorHandler.execute(t);
        }
    }
    return null;
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) MessagingServices(org.gradle.internal.remote.services.MessagingServices) Decoder(org.gradle.internal.serialize.Decoder) InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) DefaultExecutorFactory(org.gradle.internal.concurrent.DefaultExecutorFactory) ObjectConnection(org.gradle.internal.remote.ObjectConnection) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) WorkerProcessContext(org.gradle.process.internal.worker.WorkerProcessContext) File(java.io.File) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Example 7 with DefaultServiceRegistry

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

the class DaemonClientFactory method createBuildClientServices.

/**
 * Creates the services for a {@link DaemonClient} that can be used to run builds.
 */
public ServiceRegistry createBuildClientServices(OutputEventListener loggingReceiver, DaemonParameters daemonParameters, InputStream stdin) {
    DefaultServiceRegistry loggingServices = new DefaultServiceRegistry(sharedServices);
    loggingServices.add(OutputEventListener.class, loggingReceiver);
    return new DaemonClientServices(loggingServices, daemonParameters, stdin);
}
Also used : DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry)

Example 8 with DefaultServiceRegistry

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

the class DaemonClientFactory method createSingleUseDaemonClientServices.

/**
 * Creates the services for a {@link DaemonClient} that can be used to run a build in a single-use daemon.
 */
public ServiceRegistry createSingleUseDaemonClientServices(OutputEventListener loggingReceiver, DaemonParameters daemonParameters, InputStream stdin) {
    DefaultServiceRegistry loggingServices = new DefaultServiceRegistry(sharedServices);
    loggingServices.add(OutputEventListener.class, loggingReceiver);
    return new SingleUseDaemonClientServices(loggingServices, daemonParameters, stdin);
}
Also used : DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry)

Example 9 with DefaultServiceRegistry

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

the class DaemonClientFactory method createMessageDaemonServices.

/**
 * Creates the services for sending simple messages to daemons.
 *
 * Currently, there are two clients which can be used from this registry:
 *   - {@link DaemonStopClient} that can be used to stop daemons.
 *   - {@link NotifyDaemonAboutChangedPathsClient} that can be used to notify daemons about changed paths.
 */
public ServiceRegistry createMessageDaemonServices(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 10 with DefaultServiceRegistry

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

the class ValidationServicesFixture method getServices.

public static ServiceRegistry getServices() {
    DefaultServiceRegistry registry = new DefaultServiceRegistry();
    registry.addProvider(new Object() {

        ExecutionGlobalServices.AnnotationHandlerRegistration createAnnotationRegistration() {
            return () -> ImmutableList.of(ValidationProblem.class);
        }

        PropertyAnnotationHandler createValidationProblemAnnotationHandler() {
            return new ValidationProblemPropertyAnnotationHandler();
        }
    });
    return registry;
}
Also used : DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) PropertyAnnotationHandler(org.gradle.api.internal.tasks.properties.annotations.PropertyAnnotationHandler)

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