private <T extends ComponentSpec> void registerImplementation(
     ComponentSpecFactory components, List<ModelView<?>> inputs) {
   ServiceRegistry serviceRegistry =
       ModelViews.assertType(inputs.get(0), ModelType.of(ServiceRegistry.class)).getInstance();
   final Instantiator instantiator = serviceRegistry.get(Instantiator.class);
   final ProjectIdentifier projectIdentifier =
       ModelViews.assertType(inputs.get(1), ModelType.of(ProjectIdentifier.class)).getInstance();
   final ProjectSourceSet projectSourceSet =
       ModelViews.assertType(inputs.get(2), ModelType.of(ProjectSourceSet.class)).getInstance();
   components.registerFactory(
       Cast.<ModelType<ComponentSpec>>uncheckedCast(publicType),
       descriptor,
       new BiFunction<ComponentSpec, String, MutableModelNode>() {
         @Override
         public ComponentSpec apply(String name, MutableModelNode modelNode) {
           ComponentSpecIdentifier id =
               new DefaultComponentSpecIdentifier(projectIdentifier.getPath(), name);
           return BaseComponentSpec.create(
               implementationType.getConcreteClass(),
               id,
               modelNode,
               projectSourceSet,
               instantiator);
         }
       });
   components.registerImplementation(
       Cast.<ModelType<T>>uncheckedCast(publicType),
       descriptor,
       Cast.<ModelType<? extends T>>uncheckedCast(implementationType));
   if (COMPONENT_SPEC_INTERNAL_MODEL_TYPE.isAssignableFrom(implementationType)) {
     components.registerInternalView(publicType, descriptor, COMPONENT_SPEC_INTERNAL_MODEL_TYPE);
   }
 }
Ejemplo n.º 2
0
  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 runBuild(startParameter, daemonParameters, client, clientSharedServices);
  }
Ejemplo n.º 3
0
 private BuildActionExecuter<ProviderOperationParameters> createExecuter(
     ProviderOperationParameters operationParameters) {
   LoggingServiceRegistry loggingServices;
   Parameters params = initParams(operationParameters);
   BuildActionExecuter<BuildActionParameters> executer;
   if (Boolean.TRUE.equals(operationParameters.isEmbedded())) {
     loggingServices = this.loggingServices;
     executer = embeddedExecutor;
   } else {
     if (Boolean.TRUE.equals(operationParameters.isColorOutput())) {
       PrintStream outStr = new PrintStream(operationParameters.getStandardOutput());
       DefaultColorMap colourMap = new DefaultColorMap();
       colourMap.setUseColor(true);
       Console console = new AnsiConsole(outStr, outStr, colourMap, true);
       loggingServices = this.loggingServices.newColoredLogging(console);
     } else {
       loggingServices = this.loggingServices.newToolingApiLogging();
     }
     loggingServices
         .get(OutputEventRenderer.class)
         .configure(operationParameters.getBuildLogLevel());
     ServiceRegistry clientServices =
         daemonClientFactory.createBuildClientServices(
             loggingServices.get(OutputEventListener.class),
             params.daemonParams,
             operationParameters.getStandardInput(SafeStreams.emptyInput()));
     executer = clientServices.get(DaemonClient.class);
   }
   Factory<LoggingManagerInternal> loggingManagerFactory =
       loggingServices.getFactory(LoggingManagerInternal.class);
   return new LoggingBridgingBuildActionExecuter(
       new DaemonBuildActionExecuter(executer, params.daemonParams), loggingManagerFactory);
 }
Ejemplo n.º 4
0
    @Defaults
    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 BuildOperationProcessor buildOperationProcessor =
          serviceRegistry.get(BuildOperationProcessor.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,
                  buildOperationProcessor,
                  OperatingSystem.current(),
                  fileResolver,
                  execActionFactory,
                  metaDataProviderFactory,
                  instantiator);
            }
          });
      toolChainRegistry.registerDefaultToolChain(ClangToolChain.DEFAULT_NAME, Clang.class);
    }
Ejemplo n.º 5
0
    @Model
    public static VisualStudioExtensionInternal visualStudio(ServiceRegistry serviceRegistry) {
      Instantiator instantiator = serviceRegistry.get(Instantiator.class);
      ProjectLocator projectLocator = serviceRegistry.get(ProjectLocator.class);
      FileResolver fileResolver = serviceRegistry.get(FileResolver.class);

      return instantiator.newInstance(
          DefaultVisualStudioExtension.class, instantiator, projectLocator, fileResolver);
    }
  private void _forceProjectHierarchyEvaluation(Project project) {
    GradleInternal gradleInternal = (GradleInternal) project.getGradle();

    ServiceRegistry serviceRegistry = gradleInternal.getServices();

    ProjectConfigurer projectConfigurer = serviceRegistry.get(ProjectConfigurer.class);

    projectConfigurer.configureHierarchy((ProjectInternal) project);
  }
Ejemplo n.º 7
0
 private Runnable stopAllDaemons(
     DaemonParameters daemonParameters, ServiceRegistry loggingServices) {
   ServiceRegistry clientSharedServices = createGlobalClientServices();
   ServiceRegistry clientServices =
       clientSharedServices
           .get(DaemonClientFactory.class)
           .createStopDaemonServices(
               loggingServices.get(OutputEventListener.class), daemonParameters);
   DaemonStopClient stopClient = clientServices.get(DaemonStopClient.class);
   return new StopDaemonAction(stopClient);
 }
  public DefaultGradleLauncherFactory(ServiceRegistry globalServices) {
    sharedServices = globalServices;
    tracker = new NestedBuildTracker();

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

    GradleLauncher.injectCustomFactory(this);
  }
Ejemplo n.º 9
0
 /** This is used by consumers 1.0-milestone-3 and later */
 public DefaultConnection() {
   LOGGER.debug("Tooling API provider {} created.", GradleVersion.current().getVersion());
   LoggingServiceRegistry loggingServices = LoggingServiceRegistry.newEmbeddableLogging();
   services =
       ServiceRegistryBuilder.builder()
           .displayName("Connection services")
           .parent(loggingServices)
           .parent(NativeServices.getInstance())
           .provider(new ConnectionScopeServices(loggingServices))
           .build();
   adapter = services.get(ProtocolToModelAdapter.class);
   connection = services.get(ProviderConnection.class);
 }
Ejemplo n.º 10
0
 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 runBuild(startParameter, daemonParameters, client, clientSharedServices);
 }
 public ConfigurationContainerInternal getConfigurationContainer() {
   if (configurationContainer == null) {
     final Instantiator instantiator = parent.get(Instantiator.class);
     ConfigurationResolver resolver = createDependencyResolver(getResolveRepositoryHandler());
     configurationContainer =
         instantiator.newInstance(
             DefaultConfigurationContainer.class,
             resolver,
             instantiator,
             domainObjectContext,
             parent.get(ListenerManager.class),
             dependencyMetaDataProvider);
   }
   return configurationContainer;
 }
Ejemplo n.º 12
0
 @Override
 public ComponentResolvers create(ResolveContext context) {
   final ModelSchemaStore schemaStore = registry.get(ModelSchemaStore.class);
   VariantsMetaData variants = ((LocalComponentResolveContext) context).getVariants();
   JvmLocalLibraryMetaDataAdapter libraryMetaDataAdapter = new JvmLocalLibraryMetaDataAdapter();
   LocalLibraryDependencyResolver<JvmBinarySpec> delegate =
       new LocalLibraryDependencyResolver<JvmBinarySpec>(
           JvmBinarySpec.class,
           projectModelResolver,
           registry.getAll(VariantAxisCompatibilityFactory.class),
           variants,
           schemaStore,
           libraryMetaDataAdapter,
           new DefaultLibraryResolutionErrorMessageBuilder(variants, schemaStore));
   return DelegatingComponentResolvers.of(delegate);
 }
 public DependencyHandler getDependencyHandler() {
   if (dependencyHandler == null) {
     dependencyHandler =
         new DefaultDependencyHandler(
             getConfigurationContainer(), parent.get(DependencyFactory.class), projectFinder);
   }
   return dependencyHandler;
 }
 public void execute(ExecutionListener executionListener) {
   LoggingManagerInternal loggingManager =
       loggingServices.getFactory(LoggingManagerInternal.class).create();
   loggingManager.setLevel(loggingConfiguration.getLogLevel());
   loggingManager.colorStdOutAndStdErr(loggingConfiguration.isColorOutput());
   loggingManager.start();
   action.execute(executionListener);
 }
 public DefaultComponentMetadataHandler getComponentMetadataHandler() {
   if (componentMetadataHandler == null) {
     Instantiator instantiator = parent.get(Instantiator.class);
     componentMetadataHandler =
         instantiator.newInstance(DefaultComponentMetadataHandler.class, instantiator);
   }
   return componentMetadataHandler;
 }
  /**
   * Converts the given command-line arguments to a {@code Runnable} action which performs the
   * action requested by the command-line args. Does not have any side-effects. Each action will
   * call the supplied {@link org.gradle.launcher.exec.ExecutionListener} once it has completed.
   *
   * <p>Implementation note: attempt to defer as much as possible until action execution time.
   *
   * @param args The command-line arguments.
   * @return The action to execute.
   */
  public Action<ExecutionListener> convert(List<String> args) {
    CommandLineParser parser = new CommandLineParser();

    CommandLineConverter<StartParameter> startParameterConverter = createStartParameterConverter();
    startParameterConverter.configure(parser);

    parser.option(HELP, "?", "help").hasDescription("Shows this help message.");
    parser.option(VERSION, "version").hasDescription("Print version info.");
    parser.option(GUI).hasDescription("Launches the Gradle GUI.");
    parser
        .option(FOREGROUND)
        .hasDescription("Starts the Gradle daemon in the foreground.")
        .experimental();
    parser
        .option(DAEMON)
        .hasDescription(
            "Uses the Gradle daemon to run the build. Starts the daemon if not running.");
    parser.option(NO_DAEMON).hasDescription("Do not use the Gradle daemon to run the build.");
    parser.option(STOP).hasDescription("Stops the Gradle daemon if it is running.");

    LoggingConfiguration loggingConfiguration = new LoggingConfiguration();
    ServiceRegistry loggingServices = createLoggingServices();

    Action<ExecutionListener> action;
    try {
      ParsedCommandLine commandLine = parser.parse(args);
      @SuppressWarnings("unchecked")
      CommandLineConverter<LoggingConfiguration> loggingConfigurationConverter =
          (CommandLineConverter<LoggingConfiguration>)
              loggingServices.get(CommandLineConverter.class);
      loggingConfigurationConverter.convert(commandLine, loggingConfiguration);
      action = createAction(parser, commandLine, startParameterConverter, loggingServices);
    } catch (CommandLineArgumentException e) {
      action = new CommandLineParseFailureAction(parser, e);
    }

    return new WithLoggingAction(
        loggingConfiguration,
        loggingServices,
        new ExceptionReportingAction(
            action,
            new BuildExceptionReporter(
                loggingServices.get(StyledTextOutputFactory.class),
                loggingConfiguration,
                clientMetaData())));
  }
 private DefaultRepositoryHandler createRepositoryHandler() {
   Instantiator instantiator = parent.get(Instantiator.class);
   ResolverFactory resolverFactory =
       new DefaultResolverFactory(
           get(LocalMavenCacheLocator.class),
           fileResolver,
           instantiator,
           get(RepositoryTransportFactory.class));
   return instantiator.newInstance(
       DefaultRepositoryHandler.class, resolverFactory, instantiator);
 }
Ejemplo n.º 18
0
  private Runnable runBuildInProcess(
      StartParameter startParameter,
      DaemonParameters daemonParameters,
      ServiceRegistry loggingServices) {
    ServiceRegistry globalServices =
        ServiceRegistryBuilder.builder()
            .displayName("Global services")
            .parent(loggingServices)
            .parent(NativeServices.getInstance())
            .provider(new GlobalScopeServices(startParameter.isContinuous()))
            .build();

    BuildActionExecuter<BuildActionParameters> executer = globalServices.get(BuildExecuter.class);
    StyledTextOutputFactory textOutputFactory = globalServices.get(StyledTextOutputFactory.class);
    DocumentationRegistry documentationRegistry = globalServices.get(DocumentationRegistry.class);
    DaemonUsageSuggestingBuildActionExecuter daemonUsageSuggestingExecuter =
        new DaemonUsageSuggestingBuildActionExecuter(
            executer, textOutputFactory, documentationRegistry);

    return runBuild(
        startParameter, daemonParameters, daemonUsageSuggestingExecuter, globalServices);
  }
Ejemplo n.º 19
0
 // TODO:DAZ Test suites should belong to ComponentSpecContainer, and we could rely on more
 // conventions from the base plugins
 @Defaults
 public void createGoogleTestTestSuitePerComponent(
     TestSuiteContainer testSuites,
     NamedDomainObjectSet<NativeComponentSpec> components,
     ProjectSourceSet projectSourceSet,
     ServiceRegistry serviceRegistry) {
   Instantiator instantiator = serviceRegistry.get(Instantiator.class);
   FileResolver fileResolver = serviceRegistry.get(FileResolver.class);
   for (NativeComponentSpec component : components) {
     testSuites.add(
         createGoogleTestTestSuite(component, instantiator, projectSourceSet, fileResolver));
   }
 }
Ejemplo n.º 20
0
    private DefaultGoogleTestTestSuiteBinary createTestBinary(
        ServiceRegistry serviceRegistry,
        GoogleTestTestSuiteSpec googleTestTestSuite,
        NativeBinarySpec testedBinary,
        ITaskFactory taskFactory) {
      BinaryNamingScheme namingScheme =
          new DefaultBinaryNamingSchemeBuilder(
                  ((NativeBinarySpecInternal) testedBinary).getNamingScheme())
              .withComponentName(googleTestTestSuite.getBaseName())
              .withTypeString("GoogleTestExe")
              .build();

      Instantiator instantiator = serviceRegistry.get(Instantiator.class);
      NativeDependencyResolver resolver = serviceRegistry.get(NativeDependencyResolver.class);
      return DefaultGoogleTestTestSuiteBinary.create(
          googleTestTestSuite,
          (NativeBinarySpecInternal) testedBinary,
          namingScheme,
          resolver,
          instantiator,
          taskFactory);
    }
    public ResolverFactory getResolverFactory() {
      if (resolverFactory == null) {
        Instantiator instantiator = parent.get(Instantiator.class);
        //noinspection unchecked
        resolverFactory =
            new DefaultResolverFactory(
                get(LocalMavenRepositoryLocator.class),
                fileResolver,
                instantiator,
                get(RepositoryTransportFactory.class),
                get(LocallyAvailableResourceFinder.class),
                get(ByUrlCachedExternalResourceIndex.class));
      }

      return resolverFactory;
    }
    public BaseRepositoryFactory getBaseRepositoryFactory() {
      if (baseRepositoryFactory == null) {
        Instantiator instantiator = parent.get(Instantiator.class);
        //noinspection unchecked
        baseRepositoryFactory =
            new DefaultBaseRepositoryFactory(
                get(LocalMavenRepositoryLocator.class),
                fileResolver,
                instantiator,
                get(RepositoryTransportFactory.class),
                get(LocallyAvailableResourceFinder.class),
                getComponentMetadataHandler(),
                get(LegacyDependencyResolverRepositoryFactory.class));
      }

      return baseRepositoryFactory;
    }
    public BaseRepositoryFactory getBaseRepositoryFactory() {
      if (baseRepositoryFactory == null) {
        Instantiator instantiator = parent.get(Instantiator.class);
        //noinspection unchecked
        baseRepositoryFactory =
            new DefaultBaseRepositoryFactory(
                get(LocalMavenRepositoryLocator.class),
                fileResolver,
                instantiator,
                get(RepositoryTransportFactory.class),
                get(LocallyAvailableResourceFinder.class),
                get(ProgressLoggerFactory.class),
                get(LocalFileRepositoryCacheManager.class),
                get(DownloadingRepositoryCacheManager.class),
                new DefaultArtifactPublisherFactory(
                    new Transformer<ArtifactPublisher, ResolverProvider>() {
                      public ArtifactPublisher transform(ResolverProvider resolverProvider) {
                        return createArtifactPublisher(resolverProvider);
                      }
                    }));
      }

      return baseRepositoryFactory;
    }
Ejemplo n.º 24
0
 @Model
 ScalaToolChain scalaToolChain(ServiceRegistry serviceRegistry) {
   return serviceRegistry.get(ScalaToolChain.class);
 }
 public void removeListener(Object listener) {
   sharedServices.get(ListenerManager.class).removeListener(listener);
 }
Ejemplo n.º 26
0
 protected TaskClassValidatorExtractor createTaskClassValidatorExtractor(
     ServiceRegistry registry) {
   return new DefaultTaskClassValidatorExtractor(registry.getAll(PropertyAnnotationHandler.class));
 }
 public void addListener(Object listener) {
   sharedServices.get(ListenerManager.class).addListener(listener);
 }
 public StartParameter createStartParameter(String... commandLineArgs) {
   if (commandLineConverter == null) {
     commandLineConverter = sharedServices.get(CommandLineConverter.class);
   }
   return commandLineConverter.convert(Arrays.asList(commandLineArgs));
 }
 private DefaultRepositoryHandler createRepositoryHandler() {
   Instantiator instantiator = parent.get(Instantiator.class);
   return instantiator.newInstance(
       DefaultRepositoryHandler.class, getRepositoryFactory(), instantiator);
 }
 @Model
 TestSuiteContainer testSuites(ServiceRegistry serviceRegistry) {
   Instantiator instantiator = serviceRegistry.get(Instantiator.class);
   return instantiator.newInstance(DefaultTestSuiteContainer.class, instantiator);
 }