public String runCommand()

in commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/gerrit/GerritClientImpl.java [49:79]


  public String runCommand(@NotNull GerritConnectionDetails connectionDetails, @NotNull String command) throws JSchException, IOException {
    ChannelExec channel = null;
    Session session = null;
    String out = null;
    try {
      JSch jsch = new JSch();
      addKeys(jsch, connectionDetails.getProject(), connectionDetails.getKeyId());
      session = createSession(jsch, connectionDetails.getServer(), connectionDetails.getUserName());
      session.setConfig("StrictHostKeyChecking", "no");
      session.connect();
      channel = (ChannelExec) session.openChannel("exec");
      channel.setPty(false);
      channel.setCommand(command);
      BufferedReader stdout = new BufferedReader(new InputStreamReader(channel.getInputStream()));
      BufferedReader stderr = new BufferedReader(new InputStreamReader(channel.getErrStream()));
      LOG.debug("Run command '" + command + "'");
      channel.connect();
      out = readFully(stdout);
      String err = readFully(stderr);
      LOG.info("Command '" + command + "' finished, exitCode: " + channel.getExitStatus());
      LOG.debug("Command '" + command + "' has returned stdout: '" + out + "', stderr: '" + err + "'");
      if (err.length() > 0)
        throw new IOException(err);
    } finally {
      if (channel != null)
        channel.disconnect();
      if (session != null)
        session.disconnect();
    }
    return out;
  }