public RubySdk createSdk()

in rake-runner-agent/src/jetbrains/buildServer/agent/rakerunner/SharedParamsType.java [202:257]


    public RubySdk createSdk(@NotNull final BuildRunnerContext context,
                             @NotNull final SharedParams sharedParams)
      throws RakeTasksBuildService.MyBuildFailureException {
      final InstalledRbEnv rbEnv = RbEnvPathsSettings.getInstance().getRbEnv();
      if (rbEnv == null) {
        throw new RakeTasksBuildService.MyBuildFailureException("Cannot find rbenv. Please check that it installed on agent", false);
      }

      final String path = StringUtil.emptyIfNull(sharedParams.getRbEnvVersionFile());
      final File cd = context.getBuild().getCheckoutDirectory();
      final File file;
      if (!StringUtil.isEmptyOrSpaces(path)) {
        final File f = new File(cd, path);
        if (f.isDirectory()) {
          file = FileUtil2.getFirstExistChild(f, ".ruby-version", ".rbenv-version");
        } else {
          file = f; // For backward compatibility (enter file name, not directory)
        }
      } else {
        file = FileUtil2.getFirstExistChild(cd, ".ruby-version", ".rbenv-version");
      }

      if (file == null) {
        throw new RakeTasksBuildService.MyBuildFailureException(
          "Rbenv support: local version file file not found. Specified path: \"" + path + "\". Resolved path: \"" +
          new File(cd, path).getAbsolutePath() + "\"", false);
      }

      final String version;
      try {
        final List<String> strings = FileUtil.readFile(file);
        if (strings.isEmpty()) {
          throw new RakeTasksBuildService.MyBuildFailureException(
            "Rbenv support: local version file is empty. Specified path: \"" + path + "\". Resolved path: \"" +
            file.getAbsolutePath() + "\"", false);
        }
        version = StringUtil.emptyIfNull(StringUtil.trim(strings.iterator().next()));
      } catch (IOException e) {
        throw new RakeTasksBuildService.MyBuildFailureException(
          "Rbenv support: cannot read local version file. Specified path: \"" + path + "\". Resolved path: \"" +
          file.getAbsolutePath() + "\"", e, false);
      }

      if ("system".equals(version)) {
        final EnvironmentPatchableMap env = new EnvironmentPatchableMap(context.getBuildParameters().getEnvironmentVariables());
        env.put(RBENV_VERSION_ENV_VARIABLE, version);
        final File executable = findSystemInterpreterExecutable(env);
        return new RubySdkImpl(executable, true);
      } else {
        if (!rbEnv.isVersionInstalled(version)) {
          throw new RakeTasksBuildService.MyBuildFailureException(
            "Specified Ruby interpreter version '" + version + "' isn't installed in rbenv");
        }
        return new RbEnvRubySdk(rbEnv.getInterpreterHome(version), version, rbEnv);
      }
    }