Example #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());
  }
  @Override
  public InputStream getHistoryGet(String parent, String basename, String rev) {
    InputStream ret = null;

    File directory = new File(directoryName);

    String filepath;
    try {
      filepath = (new File(parent, basename)).getCanonicalPath();
    } catch (IOException exp) {
      LOGGER.log(Level.SEVERE, "Failed to get canonical path: {0}", exp.getClass().toString());
      return null;
    }
    String filename = filepath.substring(directoryName.length() + 1);

    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("cat");
    cmd.add("-r");
    cmd.add(rev);
    cmd.add(escapeFileName(filename));

    Executor executor = new Executor(cmd, directory);
    if (executor.exec() == 0) {
      ret = executor.getOutputStream();
    }

    return ret;
  }
  @Override
  public void setDirectoryName(String directoryName) {
    super.setDirectoryName(directoryName);

    if (isWorking()) {
      // set to true if we manage to find the root directory
      Boolean rootFound = Boolean.FALSE;

      List<String> cmd = new ArrayList<String>();
      cmd.add(this.cmd);
      cmd.add("info");
      cmd.add("--xml");
      File directory = new File(getDirectoryName());

      Executor executor = new Executor(cmd, directory);
      if (executor.exec() == 0) {
        try {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();
          Document document = builder.parse(executor.getOutputStream());

          String url = getValue(document.getElementsByTagName("url").item(0));
          if (url == null) {
            OpenGrokLogger.getLogger()
                .warning(
                    "svn info did not contain an URL for ["
                        + directoryName
                        + "]. Assuming remote repository.");
            setRemote(true);
          } else {
            if (!url.startsWith("file")) {
              setRemote(true);
            }
          }
          String root = getValue(document.getElementsByTagName("root").item(0));
          if (url != null && root != null) {
            reposPath = url.substring(root.length());
            rootFound = Boolean.TRUE;
          }
        } catch (SAXException saxe) {
          OpenGrokLogger.getLogger().log(Level.WARNING, "Parser error parsing svn output", saxe);
        } catch (ParserConfigurationException pce) {
          OpenGrokLogger.getLogger()
              .log(Level.WARNING, "Parser configuration error parsing svn output", pce);
        } catch (IOException ioe) {
          OpenGrokLogger.getLogger()
              .log(Level.WARNING, "IOException reading from svn process", ioe);
        }
      } else {
        OpenGrokLogger.getLogger()
            .warning(
                "Failed to execute svn info for [" + directoryName + "]. Repository disabled.");
      }

      setWorking(rootFound);
    }
  }
  @Override
  public void update() throws IOException {
    File directory = new File(getDirectoryName());

    List<String> cmd = new ArrayList<String>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(this.cmd);
    cmd.add("update");
    cmd.add("--trust-server-cert");
    cmd.add("--non-interactive");
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() != 0) {
      throw new IOException(executor.getErrorString());
    }
  }
  @Override
  public void update() throws IOException {
    File directory = new File(getDirectoryName());

    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("update");
    cmd.addAll(getAuthCommandLineParams());
    cmd.add("--non-interactive");
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() != 0) {
      throw new IOException(executor.getErrorString());
    }
  }
  @Override
  public InputStream getHistoryGet(String parent, String basename, String rev) {
    InputStream ret = null;

    File directory = new File(directoryName);

    String filename =
        (new File(parent, basename)).getAbsolutePath().substring(directoryName.length() + 1);

    List<String> cmd = new ArrayList<String>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(this.cmd);
    cmd.add("cat");
    cmd.add("-r");
    cmd.add(rev);
    cmd.add(escapeFileName(filename));

    Executor executor = new Executor(cmd, directory);
    if (executor.exec() == 0) {
      ret = executor.getOutputStream();
    }

    return ret;
  }
Example #7
0
  @Override
  public void update() throws IOException {
    File directory = new File(getDirectoryName());

    List<String> cmd = new ArrayList<String>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(this.cmd);
    cmd.add("info");
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() != 0) {
      throw new IOException(executor.getErrorString());
    }

    if (executor.getOutputString().indexOf("parent branch:") != -1) {
      cmd.clear();
      cmd.add(this.cmd);
      cmd.add("up");
      executor = new Executor(cmd, directory);
      if (executor.exec() != 0) {
        throw new IOException(executor.getErrorString());
      }
    }
  }
Example #8
0
 static Boolean checkCmd(String... args) {
   Executor exec = new Executor(args);
   return exec.exec(false) == 0;
 }