예제 #1
0
  public Gradle newInstance(StartParameter startParameter) {
    loggingConfigurer.configure(startParameter.getLogLevel());
    ImportsReader importsReader = new ImportsReader(startParameter.getDefaultImportsFile());
    CachePropertiesHandler cachePropertiesHandler = new DefaultCachePropertiesHandler();

    ISettingsFinder settingsFinder =
        new EmbeddedScriptSettingsFinder(
            new DefaultSettingsFinder(
                WrapUtil.<ISettingsFileSearchStrategy>toList(
                    new MasterDirSettingsFinderStrategy(), new ParentDirSettingsFinderStrategy())));
    ConfigurationContainerFactory configurationContainerFactory =
        new DefaultConfigurationContainerFactory();
    DefaultInternalRepository internalRepository = new DefaultInternalRepository();
    DependencyFactory dependencyFactory =
        new DefaultDependencyFactory(
            WrapUtil.<IDependencyImplementationFactory>toSet(new ModuleDependencyFactory()),
            new DefaultClientModuleFactory(),
            new DefaultProjectDependencyFactory());
    ResolverFactory resolverFactory = new DefaultResolverFactory();
    DefaultProjectEvaluator projectEvaluator =
        new DefaultProjectEvaluator(
            importsReader,
            new DefaultScriptProcessor(
                new DefaultScriptCompilationHandler(
                    cachePropertiesHandler, new BuildScriptTransformer()),
                startParameter.getCacheUsage()),
            new DefaultProjectScriptMetaData());
    Gradle gradle =
        new Gradle(
            startParameter,
            settingsFinder,
            new DefaultGradlePropertiesLoader(),
            new ScriptLocatingSettingsProcessor(
                new PropertiesLoadingSettingsProcessor(
                    new ScriptEvaluatingSettingsProcessor(
                        new DefaultSettingsScriptMetaData(),
                        new DefaultScriptProcessor(
                            new DefaultScriptCompilationHandler(cachePropertiesHandler),
                            startParameter.getCacheUsage()),
                        importsReader,
                        new SettingsFactory(
                            new DefaultProjectDescriptorRegistry(),
                            dependencyFactory,
                            new DefaultRepositoryHandler(resolverFactory, null),
                            configurationContainerFactory,
                            internalRepository,
                            new BuildSourceBuilder(
                                new DefaultGradleFactory(
                                    new LoggingConfigurer() {
                                      public void configure(LogLevel logLevel) {
                                        // do nothing
                                      }
                                    }),
                                new DefaultCacheInvalidationStrategy()))))),
            new BuildLoader(
                new ProjectFactory(
                    new TaskFactory(),
                    configurationContainerFactory,
                    dependencyFactory,
                    new DefaultRepositoryHandlerFactory(resolverFactory),
                    new DefaultPublishArtifactFactory(),
                    internalRepository,
                    projectEvaluator,
                    new PluginRegistry(startParameter.getPluginPropertiesFile()),
                    startParameter.getBuildScriptSource(),
                    new DefaultAntBuilderFactory(new AntLoggingAdapter())),
                internalRepository),
            new BuildConfigurer(new ProjectDependencies2TaskResolver()));
    gradle.addBuildListener(internalRepository);
    gradle.addBuildListener(projectEvaluator);
    return gradle;
  }
  private DefaultGradleLauncher doNewInstance(
      StartParameter startParameter, BuildRequestMetaData requestMetaData) {
    final BuildScopeServices serviceRegistry =
        new BuildScopeServices(sharedServices, startParameter);
    serviceRegistry.add(BuildRequestMetaData.class, requestMetaData);
    serviceRegistry.add(BuildClientMetaData.class, requestMetaData.getClient());
    ListenerManager listenerManager = serviceRegistry.get(ListenerManager.class);
    LoggingManagerInternal loggingManager =
        serviceRegistry.newInstance(LoggingManagerInternal.class);
    loggingManager.setLevel(startParameter.getLogLevel());

    // this hooks up the ListenerManager and LoggingConfigurer so you can call Gradle.addListener()
    // with a StandardOutputListener.
    loggingManager.addStandardOutputListener(
        listenerManager.getBroadcaster(StandardOutputListener.class));
    loggingManager.addStandardErrorListener(
        listenerManager.getBroadcaster(StandardOutputListener.class));

    listenerManager.useLogger(
        new TaskExecutionLogger(serviceRegistry.get(ProgressLoggerFactory.class)));
    if (tracker.getCurrentBuild() == null) {
      listenerManager.useLogger(
          new BuildLogger(
              Logging.getLogger(BuildLogger.class),
              serviceRegistry.get(StyledTextOutputFactory.class),
              startParameter,
              requestMetaData));
    }
    listenerManager.addListener(tracker);
    listenerManager.addListener(new BuildCleanupListener(serviceRegistry));

    listenerManager.addListener(serviceRegistry.get(ProfileEventAdapter.class));
    if (startParameter.isProfile()) {
      listenerManager.addListener(new ReportGeneratingProfileListener());
    }
    ScriptUsageLocationReporter usageLocationReporter = new ScriptUsageLocationReporter();
    listenerManager.addListener(usageLocationReporter);
    DeprecationLogger.useLocationReporter(usageLocationReporter);

    GradleInternal gradle =
        serviceRegistry
            .get(Instantiator.class)
            .newInstance(
                DefaultGradle.class, tracker.getCurrentBuild(), startParameter, serviceRegistry);
    return new DefaultGradleLauncher(
        gradle,
        serviceRegistry.get(InitScriptHandler.class),
        new SettingsHandler(
            new DefaultSettingsFinder(new BuildLayoutFactory()),
            serviceRegistry.get(SettingsProcessor.class),
            new BuildSourceBuilder(
                this,
                serviceRegistry.get(ClassLoaderRegistry.class),
                serviceRegistry.get(CacheRepository.class))),
        serviceRegistry.get(BuildLoader.class),
        serviceRegistry.get(BuildConfigurer.class),
        gradle.getBuildListenerBroadcaster(),
        serviceRegistry.get(ExceptionAnalyser.class),
        loggingManager,
        listenerManager.getBroadcaster(ModelConfigurationListener.class),
        listenerManager.getBroadcaster(TasksCompletionListener.class),
        gradle.getServices().get(BuildExecuter.class));
  }