Ejemplo n.º 1
0
  public Runnable createAction(CommandLineParser parser, ParsedCommandLine commandLine) {
    Parameters parameters = parametersConverter.convert(commandLine, new Parameters());
    parameters
        .getDaemonParameters()
        .applyDefaultsFor(
            new JvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver()))
                .getJavaVersion(parameters.getDaemonParameters().getEffectiveJvm()));

    if (parameters.getDaemonParameters().isStop()) {
      return stopAllDaemons(parameters.getDaemonParameters(), loggingServices);
    }
    if (parameters.getDaemonParameters().isForeground()) {
      DaemonParameters daemonParameters = parameters.getDaemonParameters();
      ForegroundDaemonConfiguration conf =
          new ForegroundDaemonConfiguration(
              UUID.randomUUID().toString(),
              daemonParameters.getBaseDir(),
              daemonParameters.getIdleTimeout(),
              daemonParameters.getPeriodicCheckInterval());
      return new ForegroundDaemonAction(loggingServices, conf);
    }
    if (parameters.getDaemonParameters().getDaemonUsage().isEnabled()) {
      return runBuildWithDaemon(
          parameters.getStartParameter(), parameters.getDaemonParameters(), loggingServices);
    }
    if (canUseCurrentProcess(parameters.getDaemonParameters())) {
      return runBuildInProcess(
          parameters.getStartParameter(), parameters.getDaemonParameters(), loggingServices);
    }

    return runBuildInSingleUseDaemon(
        parameters.getStartParameter(), parameters.getDaemonParameters(), loggingServices);
  }
  private Action<ExecutionListener> createAction(
      CommandLineParser parser,
      final ParsedCommandLine commandLine,
      CommandLineConverter<StartParameter> startParameterConverter,
      final ServiceRegistry loggingServices) {
    if (commandLine.hasOption(HELP)) {
      return new ActionAdapter(new ShowUsageAction(parser));
    }
    if (commandLine.hasOption(VERSION)) {
      return new ActionAdapter(new ShowVersionAction());
    }
    if (commandLine.hasOption(GUI)) {
      return new ActionAdapter(new ShowGuiAction());
    }

    final StartParameter startParameter = new StartParameter();
    startParameterConverter.convert(commandLine, startParameter);
    DaemonParameters daemonParameters = constructDaemonParameters(startParameter);
    if (commandLine.hasOption(FOREGROUND)) {
      ForegroundDaemonConfiguration conf =
          new ForegroundDaemonConfiguration(
              daemonParameters.getUid(),
              daemonParameters.getBaseDir(),
              daemonParameters.getIdleTimeout());
      return new ActionAdapter(new ForegroundDaemonMain(conf));
    }

    if (commandLine.hasOption(STOP)) {
      return stopAllDaemons(daemonParameters, loggingServices);
    }
    if (useDaemon(commandLine, daemonParameters)) {
      return runBuildWithDaemon(commandLine, daemonParameters, loggingServices);
    }
    if (canUseCurrentProcess(daemonParameters)) {
      return runBuildInProcess(loggingServices, startParameter);
    }
    return runBuildInSingleUseDaemon(commandLine, daemonParameters, loggingServices);
  }