001package io.ebean.docker.commands.process;
002
003import java.util.List;
004
005/**
006 * The result of an external process call.
007 */
008public class ProcessResult {
009
010  private final int result;
011
012  private final List<String> out;
013
014  /**
015   * Create with the result exit code and std out and err content.
016   */
017  public ProcessResult(int result, List<String> out) {
018    this.result = result;
019    this.out = out;
020  }
021
022  /**
023   * Return true if exit result was 0.
024   */
025  public boolean success() {
026    return result == 0;
027  }
028
029  /**
030   * Return the STD OUT lines.
031   */
032  public List<String> getOutLines() {
033    return out;
034  }
035
036  /**
037   * Return all the stdOut and stdErr content (merged).
038   */
039  private String out() {
040    return lines(out);
041  }
042
043  /**
044   * Return debug output.
045   */
046  public String debug() {
047    return "exit:" + result + "\n out:" + out(); // + "\n err:" + stdErr();
048  }
049
050  private String lines(List<String> lines) {
051    StringBuilder sb = new StringBuilder();
052    for (int i = 0; i < lines.size(); i++) {
053      if (i > 0) {
054        sb.append("\n");
055      }
056      sb.append(lines.get(i));
057    }
058    return sb.toString();
059  }
060
061}