public DefaultGradleLauncher newInstance(StartParameter startParameter) {
   BuildRequestMetaData requestMetaData;
   if (tracker.getCurrentBuild() != null) {
     requestMetaData =
         new DefaultBuildRequestMetaData(
             tracker.getCurrentBuild().getServices().get(BuildClientMetaData.class),
             System.currentTimeMillis());
   } else {
     requestMetaData = new DefaultBuildRequestMetaData(System.currentTimeMillis());
   }
   return doNewInstance(startParameter, requestMetaData);
 }
  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));
  }
 public DefaultGradleLauncher newInstance(
     StartParameter startParameter, BuildRequestMetaData requestMetaData) {
   // This should only be used for top-level builds
   assert tracker.getCurrentBuild() == null;
   return doNewInstance(startParameter, requestMetaData);
 }