Exemplo n.º 1
0
  /**
   * Annotate the specified file/revision.
   *
   * @param file file to annotate
   * @param revision revision to annotate
   * @return file annotation
   */
  @Override
  public Annotation annotate(File file, String revision) throws IOException {
    List<String> cmd = new ArrayList<String>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(this.cmd);
    cmd.add("blame");
    cmd.add("--all");
    cmd.add("--long");
    if (revision != null) {
      cmd.add("-r");
      cmd.add(revision);
    }
    cmd.add(file.getName());

    Executor exec = new Executor(cmd, file.getParentFile());
    int status = exec.exec();

    if (status != 0) {
      OpenGrokLogger.getLogger()
          .log(
              Level.WARNING,
              "Failed to get annotations for: \"{0}\" Exit code: {1}",
              new Object[] {file.getAbsolutePath(), String.valueOf(status)});
    }

    return parseAnnotation(exec.getOutputReader(), file.getName());
  }