private static RubySdk createAndSetup()

in rake-runner-agent/src/jetbrains/buildServer/agent/ruby/rvm/impl/RVMRCBasedRubySdkImpl.java [54:100]


  private static RubySdk createAndSetup(@NotNull final String pathToRVMRCFolder, @NotNull final Map<String, String> env)
    throws RakeTasksBuildService.MyBuildFailureException {
    final ShellScriptRunner shellScriptRunner = ScriptingRunnersProvider.getRVMDefault().getShellScriptRunner();
    final ExecResult testRun = shellScriptRunner.run(String.format(TEST_RVM_SHELL_SCRIPT, pathToRVMRCFolder), pathToRVMRCFolder, env);
    //noinspection ThrowableResultOfMethodCallIgnored
    if (testRun.getExitCode() != 0 || testRun.getException() != null) {
      StringBuilder sb = new StringBuilder();
      sb.append("Configuring RVM with ").append(pathToRVMRCFolder).append("/.rvmrc failed:");
      sb.append(testRun.toString());
      throw new RakeTasksBuildService.MyBuildFailureException(sb.toString());
    }
    final RVMInfo info = RVMInfoUtil.gatherInfoUnderRvmShell(pathToRVMRCFolder, env);

    // Constructor params
    final String name = info.getInterpreterName();

    if (RVMSupportUtil.isSystemRuby(name)) {
      final String executablePath = info.getSection(RVMInfo.Section.binaries).get("ruby");

      if (LOG.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\t").append("Configuring system interpreter with .rvmrc");
        sb.append("\n\t").append("PathToRVMRCFolder = ").append(pathToRVMRCFolder);
        sb.append("\n\t").append("Executable Path is ").append(executablePath);
        LOG.debug(sb.toString());
      }

      return new RVMRubySdkImpl(new File(executablePath));
    } else {
      final String gemset = info.getSection(RVMInfo.Section.environment).get("gemset");

      if (LOG.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\t").append("Configuring rvm interpreter with .rvmrc");
        sb.append("\n\t").append("PathToRVMRCFolder = ").append(pathToRVMRCFolder);
        sb.append("\n\t").append("Gemset is ").append(gemset);
        sb.append("\n\t").append("Name is ").append(name);
        LOG.debug(sb.toString());
      }

      final File home = RVMPathsSettings.getRVMNullSafe().getHomeForVersionName(name);
      if (home == null) {
        throw new RakeTasksBuildService.MyBuildFailureException(String.format("Cannot find home path for RVM SDK with name %s", name));
      }
      return new RVMRCBasedRubySdkImpl(home, name, gemset, pathToRVMRCFolder);
    }
  }