private static String findBundlerGemRoot()

in rake-runner-agent/src/jetbrains/buildServer/agent/rakerunner/utils/BundlerUtil.java [328:371]


  private static String findBundlerGemRoot(@NotNull final RubySdk sdk,
                                           @NotNull final Map<String, String> buildParameters)
    throws RakeTasksBuildService.MyBuildFailureException {

    // At first let's try to find script in "test-unit" gem
    // then in sdk load path

    final String forcedBundlerGemVersion = RubySDKUtil.getForcedGemVersion(BUNDLER_GEM_VERSION_PROPERTY, buildParameters);

    // P.S: we are not interested to search bundler gem in bundler git paths or in "frozen" bundler paths
    final Pair<String, String> gemInfo = RubySDKUtil.findGemRootFolderAndVersion(BUNDLER_GEM_NAME,
                                                                                 sdk.getGemPaths(),
                                                                                 forcedBundlerGemVersion);


    if (gemInfo != null) {
      final String bundlerGemPath = gemInfo.first;
      if (checkIfExists(bundlerGemPath)) {
        return bundlerGemPath;
      } else {
        // Error: bundler gem home directory wasn't found
        final String msg = "Expected bundler gem installation directory doesn't exist: '" + bundlerGemPath + "'.";
        throw new RakeTasksBuildService.MyBuildFailureException(msg);
      }
    } else {
      // bundler gem not found
      if (forcedBundlerGemVersion != null) {
        // forced version
        final StringBuilder msg = new StringBuilder();
        msg.append("bundler gem with version '").append(forcedBundlerGemVersion)
          .append("' wasn't found in Gem paths of Ruby SDK with interpreter: '").append(sdk.getName()).append("'.\n").append("Gem paths:\n")
          .append(sdk.getGemPathsFetchLog().getStdout());
        throw new RakeTasksBuildService.MyBuildFailureException(msg.toString());
      } else {
        // any version
        final StringBuilder msg = new StringBuilder();
        msg.append(
          "If you want to use bundler please install it at first. The gem wasn't found in Gem paths of Ruby SDK with interpreter: '");
        msg.append(sdk.getName()).append("'.\n");
        msg.append("Gem paths:\n").append(sdk.getGemPathsFetchLog().getStdout());
        throw new RakeTasksBuildService.MyBuildFailureException(msg.toString());
      }
    }
  }