protected void doPrepareGemset()

in rake-runner-test/src/jetbrains/slow/plugins/rakerunner/AbstractRakeRunnerTest.java [453:487]


  protected void doPrepareGemset(@NotNull final String version, @NotNull final String gemset, @NotNull final Logger LOG, @NotNull final File gemfile) throws IOException {
    if (!SystemInfo.isUnix) {
      return;
    }
    final File cacheDir = getTestDataPath("gems/vendor/cache");
    FileUtil.createDir(cacheDir);
    final File workingDirectory = gemfile.getParentFile();
    final List<String> commands = new ArrayList<String>();
    if (RakeRunnerTestUtil.isUseRVM()) {
      commands.add("source " + getTestDataPath("gems/checkRVMCommand.sh").getAbsolutePath());
      commands.add("checkRVMCommand");
      commands.add(String.format("rvm use \"%s@%s\" --create", version, gemset));
    } else if (RakeRunnerTestUtil.isUseRbEnv()) {
      commands.add("rbenv local " + version);
    } else {
      throw new IllegalStateException("Expected to be run on machine with either RVM or RbEnv installed.");
    }
    Collections.addAll(commands,
                       "[[ ! -d 'vendor' ]] && mkdir vendor",
                       "[[ ! -d 'vendor/cache' ]] && ln -s '" + cacheDir.getAbsolutePath() + "' 'vendor/cache'",
                       "gem which bundler || gem install bundler",
                       "rm -f Gemfile.lock",
                       "bundle install --local --no-prune || (rm -f Gemfile.lock; bundle install --no-prune)",
                       "bundle update",
                       "bundle package --no-prune");
    RunCommandsHelper.runBashScript(LOG, workingDirectory, commands.toArray(new String[commands.size()]));
    //FileUtil.copyDir(localCacheDir, cacheDir);
    try {
      final FlowLogger fl = LogUtil.getFlowLogger(LOG);
      fl.activityStarted("Actual Gemfile.lock:", "AGL");
      fl.message(FileUtil.readText(new File(gemfile.getParent(), "Gemfile.lock")));
      fl.activityFinished("Actual Gemfile.lock:", "AGL");
    } catch (Exception ignored) {
    }
  }