public Void visit()

in src/main/java/com/googlesource/gerrit/plugins/replication/pull/fetch/CGitFetchValidator.java [37:72]


  public Void visit(AssistedInjectBinding<? extends FetchFactory> binding) {
    TypeLiteral<CGitFetch> nativeGitFetchType = new TypeLiteral<CGitFetch>() {};
    for (AssistedMethod method : binding.getAssistedMethods()) {
      if (method.getImplementationType().equals(nativeGitFetchType)) {
        String[] command = new String[] {"git", "--version"};

        ProcessBuilder pb = new ProcessBuilder().command(command);
        try {
          Process process = pb.start();

          boolean isFinished = process.waitFor(DEFAULT_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
          if (!isFinished) {
            throw new IllegalStateException(
                "Timeout while checking if native git client is available");
          }
          if (process.exitValue() != 0) {
            String errorMessage = readMessage(process.getErrorStream());
            throw new IllegalStateException(
                String.format(
                    "Cannot check if native git client is available, error message: %s}",
                    errorMessage));
          }

          String commandOutputMessage = readMessage(process.getInputStream());
          logger.atInfo().log("Native git client version: %s", commandOutputMessage);
        } catch (IOException e) {
          throw new IllegalStateException(
              "Cannot start process to check if native git client is available", e);
        } catch (InterruptedException e) {
          throw new IllegalStateException(
              "Timeout while checking if native git client is available");
        }
      }
    }
    return null;
  }