Java Code Examples for org.gradle.internal.service.ServiceRegistry

The following examples show how to use org.gradle.internal.service.ServiceRegistry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Mutate
public void createBinaries(BinaryContainer binaries, PlatformContainer platforms, BinaryNamingSchemeBuilder namingSchemeBuilder,
                           NamedDomainObjectCollection<JvmLibrarySpec> libraries, @Path("buildDir") File buildDir, ServiceRegistry serviceRegistry, JavaToolChainRegistry toolChains) {
    Instantiator instantiator = serviceRegistry.get(Instantiator.class);

    List<Action<? super JarBinarySpec>> actions = Lists.newArrayList();
    actions.add(new JarBinarySpecInitializer(buildDir));
    actions.add(new MarkBinariesBuildable());
    Action<JarBinarySpec> initAction = Actions.composite(actions);
    JarBinariesFactory factory = new DefaultJarBinariesFactory(instantiator, initAction);

    Action<JvmLibrarySpec> createBinariesAction =
            new JvmLibrarySpecInitializer(factory, namingSchemeBuilder, toolChains, platforms);

    for (JvmLibrarySpec jvmLibrary : libraries) {
        createBinariesAction.execute(jvmLibrary);
        binaries.addAll(jvmLibrary.getBinaries());
    }
}
 
Example 2
private void startReceivingTests(WorkerProcessContext workerProcessContext, ServiceRegistry testServices) {
    TestClassProcessor targetProcessor = factory.create(testServices);
    IdGenerator<Object> idGenerator = testServices.get(IdGenerator.class);

    targetProcessor = new WorkerTestClassProcessor(targetProcessor, idGenerator.generateId(),
            workerProcessContext.getDisplayName(), new TrueTimeProvider());
    ContextClassLoaderProxy<TestClassProcessor> proxy = new ContextClassLoaderProxy<TestClassProcessor>(
            TestClassProcessor.class, targetProcessor, workerProcessContext.getApplicationClassLoader());
    processor = proxy.getSource();

    ObjectConnection serverConnection = workerProcessContext.getServerConnection();
    serverConnection.useParameterSerializer(new TestEventSerializer());
    this.resultProcessor = serverConnection.addOutgoing(TestResultProcessor.class);
    serverConnection.addIncoming(RemoteTestClassProcessor.class, this);
    serverConnection.connect();
}
 
Example 3
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 daemonBuildAction(startParameter, daemonParameters, client);
}
 
Example 4
public void init(final Object target, ServiceRegistry services) {
    super.init(target, services);
    this.__scriptServices = services;
    loggingManager = services.get(LoggingManager.class);
    Instantiator instantiator = services.get(Instantiator.class);
    FileLookup fileLookup = services.get(FileLookup.class);
    if (target instanceof FileOperations) {
        fileOperations = (FileOperations) target;
    } else if (getScriptSource().getResource().getFile() != null) {
        fileOperations = new DefaultFileOperations(fileLookup.getFileResolver(getScriptSource().getResource().getFile().getParentFile()), null, null, instantiator, fileLookup);
    } else {
        fileOperations = new DefaultFileOperations(fileLookup.getFileResolver(), null, null, instantiator, fileLookup);
    }

    processOperations = (ProcessOperations) fileOperations;
}
 
Example 5
public BaseSettings(ServiceRegistryFactory serviceRegistryFactory, GradleInternal gradle,
                    ClassLoaderScope classLoaderScope, File settingsDir, ScriptSource settingsScript,
                    StartParameter startParameter) {
    this.gradle = gradle;
    this.settingsDir = settingsDir;
    this.settingsScript = settingsScript;
    this.startParameter = startParameter;
    this.classLoaderScope = classLoaderScope;
    ServiceRegistry services = serviceRegistryFactory.createFor(this);
    this.plugins = services.get(PluginContainer.class);
    this.fileResolver = services.get(FileResolver.class);
    this.scriptPluginFactory = services.get(ScriptPluginFactory.class);
    this.scriptHandlerFactory = services.get(ScriptHandlerFactory.class);
    this.projectDescriptorRegistry = services.get(ProjectDescriptorRegistry.class);
    rootProjectDescriptor = createProjectDescriptor(null, settingsDir.getName(), settingsDir);
}
 
Example 6
public DaemonServices(DaemonServerConfiguration configuration, ServiceRegistry loggingServices, LoggingManagerInternal loggingManager) {
    super(NativeServices.getInstance(), loggingServices);
    this.configuration = configuration;
    this.loggingManager = loggingManager;

    addProvider(new DaemonRegistryServices(configuration.getBaseDir()));
    addProvider(new GlobalScopeServices(true));
}
 
Example 7
private Action<? super ExecutionListener> runBuildInProcess(StartParameter startParameter, DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
    ServiceRegistry globalServices = ServiceRegistryBuilder.builder()
            .displayName("Global services")
            .parent(loggingServices)
            .parent(NativeServices.getInstance())
            .provider(new GlobalScopeServices(false))
            .build();
    InProcessBuildActionExecuter executer = new InProcessBuildActionExecuter(globalServices.get(GradleLauncherFactory.class));
    return daemonBuildAction(startParameter, daemonParameters, executer);
}
 
Example 8
BuildActionsFactory(ServiceRegistry loggingServices, DefaultCommandLineConverter commandLineConverter,
                    DaemonCommandLineConverter daemonConverter, LayoutCommandLineConverter layoutConverter,
                    SystemPropertiesCommandLineConverter propertiesConverter,
                    LayoutToPropertiesConverter layoutToPropertiesConverter,
                    PropertiesToStartParameterConverter propertiesToStartParameterConverter,
                    PropertiesToDaemonParametersConverter propertiesToDaemonParametersConverter) {
    this.loggingServices = loggingServices;
    this.commandLineConverter = commandLineConverter;
    this.daemonConverter = daemonConverter;
    this.layoutConverter = layoutConverter;
    this.propertiesConverter = propertiesConverter;
    this.layoutToPropertiesConverter = layoutToPropertiesConverter;
    this.propertiesToStartParameterConverter = propertiesToStartParameterConverter;
    this.propertiesToDaemonParametersConverter = propertiesToDaemonParametersConverter;
}
 
Example 9
private Runnable runBuildWithDaemon(StartParameter startParameter, DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
    // Create a client that will match based on the daemon startup parameters.
    ServiceRegistry clientSharedServices = createGlobalClientServices();
    ServiceRegistry clientServices = clientSharedServices.get(DaemonClientFactory.class).createBuildClientServices(loggingServices.get(OutputEventListener.class), daemonParameters, System.in);
    DaemonClient client = clientServices.get(DaemonClient.class);
    return daemonBuildAction(startParameter, daemonParameters, client);
}
 
Example 10
public BuildScopeServices(final ServiceRegistry parent, final StartParameter startParameter) {
    super(parent);
    register(new Action<ServiceRegistration>() {
        public void execute(ServiceRegistration registration) {
            add(StartParameter.class, startParameter);
            for (PluginServiceRegistry pluginServiceRegistry : parent.getAll(PluginServiceRegistry.class)) {
                pluginServiceRegistry.registerBuildServices(registration);
            }
        }
    });
}
 
Example 11
private DefaultCUnitTestSuiteBinary createTestBinary(ServiceRegistry serviceRegistry, CUnitTestSuiteSpec cUnitTestSuite, NativeBinarySpec testedBinary) {
    BinaryNamingScheme namingScheme = new DefaultBinaryNamingSchemeBuilder(((NativeBinarySpecInternal) testedBinary).getNamingScheme())
            .withComponentName(cUnitTestSuite.getBaseName())
            .withTypeString("CUnitExe").build();

    Instantiator instantiator = serviceRegistry.get(Instantiator.class);
    NativeDependencyResolver resolver = serviceRegistry.get(NativeDependencyResolver.class);
    return instantiator.newInstance(DefaultCUnitTestSuiteBinary.class, cUnitTestSuite, testedBinary, namingScheme, resolver);
}
 
Example 12
/**
 * <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 LoggingConfiguration();

    return new ExceptionReportingAction(
            new WithLogging(loggingServices, args, loggingConfiguration,
                    new ParseAndBuildAction(loggingServices, args)),
            new BuildExceptionReporter(loggingServices.get(StyledTextOutputFactory.class), loggingConfiguration, clientMetaData()));
}
 
Example 13
@Mutate
public static void addToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) {
    final FileResolver fileResolver = serviceRegistry.get(FileResolver.class);
    final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class);
    final Instantiator instantiator = serviceRegistry.get(Instantiator.class);
    final CompilerMetaDataProviderFactory metaDataProviderFactory = serviceRegistry.get(CompilerMetaDataProviderFactory.class);

    toolChainRegistry.registerFactory(Clang.class, new NamedDomainObjectFactory<Clang>() {
        public Clang create(String name) {
            return instantiator.newInstance(ClangToolChain.class, name, OperatingSystem.current(), fileResolver, execActionFactory, metaDataProviderFactory, instantiator);
        }
    });
    toolChainRegistry.registerDefaultToolChain(ClangToolChain.DEFAULT_NAME, Clang.class);
}
 
Example 14
@Mutate
public static void addGccToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) {
    final FileResolver fileResolver = serviceRegistry.get(FileResolver.class);
    final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class);
    final Instantiator instantiator = serviceRegistry.get(Instantiator.class);
    final CompilerMetaDataProviderFactory metaDataProviderFactory = serviceRegistry.get(CompilerMetaDataProviderFactory.class);

    toolChainRegistry.registerFactory(Gcc.class, new NamedDomainObjectFactory<Gcc>() {
        public Gcc create(String name) {
            return instantiator.newInstance(GccToolChain.class, instantiator, name, OperatingSystem.current(), fileResolver, execActionFactory, metaDataProviderFactory);
        }
    });
    toolChainRegistry.registerDefaultToolChain(GccToolChain.DEFAULT_NAME, Gcc.class);
}
 
Example 15
@Model
Repositories repositories(ServiceRegistry serviceRegistry, FlavorContainer flavors, PlatformContainer platforms, BuildTypeContainer buildTypes) {
    Instantiator instantiator = serviceRegistry.get(Instantiator.class);
    FileResolver fileResolver = serviceRegistry.get(FileResolver.class);
    Action<PrebuiltLibrary> initializer = new PrebuiltLibraryInitializer(instantiator, platforms.withType(NativePlatform.class), buildTypes, flavors);
    return new DefaultRepositories(instantiator, fileResolver, initializer);
}
 
Example 16
@Mutate
public void registerNativePlatformFactory(PlatformContainer platforms, ServiceRegistry serviceRegistry) {
    final Instantiator instantiator = serviceRegistry.get(Instantiator.class);
    NamedDomainObjectFactory<NativePlatform> nativePlatformFactory = new NamedDomainObjectFactory<NativePlatform>() {
        public NativePlatform create(String name) {
            return instantiator.newInstance(DefaultNativePlatform.class, name);
        }
    };

    //TODO freekh: remove cast/this comment when registerDefault exists on interface
    ((DefaultPlatformContainer) platforms).registerDefaultFactory(nativePlatformFactory);
    platforms.registerFactory(NativePlatform.class, nativePlatformFactory);
}
 
Example 17
private Action<? super ExecutionListener> 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
    DaemonClientServices clientServices = new SingleUseDaemonClientServices(loggingServices, daemonParameters, System.in);
    DaemonClient client = clientServices.get(DaemonClient.class);
    return daemonBuildAction(startParameter, daemonParameters, client);
}
 
Example 18
public DefaultGradleLauncherFactory(ServiceRegistry globalServices) {
    sharedServices = globalServices;
    tracker = new NestedBuildTracker();

    // Register default loggers 
    ListenerManager listenerManager = sharedServices.get(ListenerManager.class);
    buildProgressLogger = new BuildProgressLogger(sharedServices.get(ProgressLoggerFactory.class));
    listenerManager.addListener(new BuildProgressFilter(buildProgressLogger));
    listenerManager.useLogger(new DependencyResolutionLogger(sharedServices.get(ProgressLoggerFactory.class)));

    GradleLauncher.injectCustomFactory(this);
}
 
Example 19
public ProjectScopeServices(final ServiceRegistry parent, final ProjectInternal project) {
    super(parent);
    this.project = project;
    register(new Action<ServiceRegistration>() {
        public void execute(ServiceRegistration registration) {
            registration.add(DomainObjectContext.class, project);
            parent.get(DependencyManagementServices.class).addDslServices(registration);
            for (PluginServiceRegistry pluginServiceRegistry : parent.getAll(PluginServiceRegistry.class)) {
                pluginServiceRegistry.registerProjectServices(registration);
            }
        }
    });
}
 
Example 20
public DependencyInjectingInstantiator(ServiceRegistry services) {
    this.services = services;
    onDeprecationWarning = new Action<String>() {
        public void execute(String message) {
            DeprecationLogger.nagUserWith(message);
        }
    };
}
 
Example 21
ServiceRegistryFactory createServiceRegistryFactory(final ServiceRegistry services) {
    return new ServiceRegistryFactory() {
        public ServiceRegistry createFor(Object domainObject) {
            if (domainObject instanceof ProjectInternal) {
                ProjectScopeServices projectScopeServices = new ProjectScopeServices(services, (ProjectInternal) domainObject);
                registries.add(projectScopeServices);
                return projectScopeServices;
            }
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 22
public BuildScopeServices(final ServiceRegistry parent, final StartParameter startParameter) {
    super(parent);
    register(new Action<ServiceRegistration>() {
        public void execute(ServiceRegistration registration) {
            add(StartParameter.class, startParameter);
            for (PluginServiceRegistry pluginServiceRegistry : parent.getAll(PluginServiceRegistry.class)) {
                pluginServiceRegistry.registerBuildServices(registration);
            }
        }
    });
}
 
Example 23
public ServiceRegistry createFor(Object domainObject) {
    if (domainObject instanceof GradleInternal) {
        GradleScopeServices gradleServices = new GradleScopeServices(services, (GradleInternal) domainObject);
        registries.add(gradleServices);
        return gradleServices;
    }
    if (domainObject instanceof SettingsInternal) {
        SettingsScopeServices settingsServices = new SettingsScopeServices(services, (SettingsInternal) domainObject);
        registries.add(settingsServices);
        return settingsServices;
    }
    throw new IllegalArgumentException(String.format("Cannot create services for unknown domain object of type %s.",
            domainObject.getClass().getSimpleName()));
}
 
Example 24
public ProjectScopeServices(final ServiceRegistry parent, final ProjectInternal project) {
    super(parent);
    this.project = project;
    register(new Action<ServiceRegistration>() {
        public void execute(ServiceRegistration registration) {
            registration.add(DomainObjectContext.class, project);
            parent.get(DependencyManagementServices.class).addDslServices(registration);
            for (PluginServiceRegistry pluginServiceRegistry : parent.getAll(PluginServiceRegistry.class)) {
                pluginServiceRegistry.registerProjectServices(registration);
            }
        }
    });
}
 
Example 25
@Model
JavaToolChainRegistry javaToolChain(ServiceRegistry serviceRegistry) {
    JavaToolChainInternal toolChain = serviceRegistry.get(JavaToolChainInternal.class);
    return new DefaultJavaToolChainRegistry(toolChain);
}
 
Example 26
private Action<? super ExecutionListener> runBuildWithDaemon(StartParameter startParameter, DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
    // Create a client that will match based on the daemon startup parameters.
    DaemonClientServices clientServices = new DaemonClientServices(loggingServices, daemonParameters, System.in);
    DaemonClient client = clientServices.get(DaemonClient.class);
    return daemonBuildAction(startParameter, daemonParameters, client);
}
 
Example 27
public EmbeddedDaemonClientServices(ServiceRegistry loggingServices) {
    super(loggingServices, System.in);
    addProvider(new GlobalScopeServices(false));
    add(EmbeddedDaemonFactory.class, new EmbeddedDaemonFactory());
}
 
Example 28
public TestClassProcessor create(ServiceRegistry serviceRegistry) {
    return new JUnitTestClassProcessor(spec, serviceRegistry.get(IdGenerator.class), serviceRegistry.get(ActorFactory.class), new JULRedirector());
}
 
Example 29
DependencyResolutionServices createDependencyResolutionServices(ServiceRegistry services) {
    return new DefaultDependencyResolutionServices(services);
}
 
Example 30
@Model
ProjectPublicationRegistry projectPublicationRegistry(ServiceRegistry serviceRegistry) {
    return serviceRegistry.get(ProjectPublicationRegistry.class);
}