Ejemplo n.º 1
0
  /**
   * This runner needs runner options (user configurations) and environment name (inputted by user).
   * It analyzes all given information and get necessary information.
   *
   * @param locale localization constants
   * @param runnerCounter utility that support the counter of runners
   * @param runOptions options which needs to be used
   * @param environmentName name of custom configuration
   */
  @AssistedInject
  public RunnerImpl(
      @NotNull RunnerLocalizationConstant locale,
      @NotNull RunnerCounter runnerCounter,
      @NotNull GetEnvironmentsUtil util,
      @NotNull @Assisted RunOptions runOptions,
      @NotNull @Assisted Scope environmentScope,
      @Nullable @Assisted String environmentName) {
    this.runOptions = runOptions;
    this.ram = runOptions.getMemorySize();
    this.title =
        RUNNER_NAME
            + runnerCounter.getRunnerNumber()
            + (environmentName == null ? "" : " - " + getCorrectName(environmentName));
    this.activeTab = locale.runnerTabConsole();
    this.status = IN_QUEUE;
    this.scope = environmentScope;

    creationTime = System.currentTimeMillis();

    String environmentId = runOptions.getEnvironmentId();

    if (environmentId == null || environmentId.startsWith("project:/")) {
      this.type = util.getType();
    } else {
      this.type = util.getCorrectCategoryName(runOptions.getEnvironmentId());
    }

    // the environment ID in runOptions should be an URL
    if (environmentId != null) {
      runOptions.setEnvironmentId(environmentId);
    }
  }
  /** {@inheritDoc} */
  @Override
  public Runner launchRunner() {
    CurrentProject currentProject = appContext.getCurrentProject();
    if (currentProject == null) {
      throw new IllegalStateException(
          "Can't launch runner for current project. Current project is absent...");
    }

    int ram = DEFAULT.getValue();

    RunnersDescriptor runnersDescriptor = currentProject.getProjectDescription().getRunners();
    String defaultRunner = runnersDescriptor.getDefault();

    if (!EnvironmentIdValidator.isValid(defaultRunner)) {
      defaultRunner = URL.encode(defaultRunner);
    }

    RunnerConfiguration defaultConfigs = runnersDescriptor.getConfigs().get(defaultRunner);

    if (defaultRunner != null && defaultConfigs != null) {
      ram = defaultConfigs.getRam();
    }

    RunOptions runOptions =
        dtoFactory
            .createDto(RunOptions.class)
            .withSkipBuild(Boolean.valueOf(currentProject.getAttributeValue("runner:skipBuild")))
            .withEnvironmentId(defaultRunner)
            .withMemorySize(ram);

    Environment environment = chooseRunnerAction.selectEnvironment();
    if (environment != null) {
      if (defaultRunner != null && defaultRunner.equals(environment.getId())) {
        Runner runner = modelsFactory.createRunner(runOptions);
        if (defaultRunner.startsWith(PROJECT_PREFIX)) {
          runner.setScope(PROJECT);
        }
        return launchRunner(runner);
      }
      runOptions =
          runOptions
              .withOptions(environment.getOptions())
              .withMemorySize(environment.getRam())
              .withEnvironmentId(environment.getId());
      Runner runner =
          modelsFactory.createRunner(runOptions, environment.getScope(), environment.getName());
      if (environment.getId().startsWith(PROJECT_PREFIX)) {
        runner.setScope(PROJECT);
      }
      return launchRunner(runner);
    }

    Runner runner = modelsFactory.createRunner(runOptions);
    if (defaultRunner != null && defaultRunner.startsWith(PROJECT_PREFIX)) {
      runner.setScope(PROJECT);
    }
    return launchRunner(modelsFactory.createRunner(runOptions));
  }
Ejemplo n.º 3
0
 /** {@inheritDoc} */
 @NotNull
 @Override
 public String getEnvironmentId() {
   return runOptions.getEnvironmentId();
 }