Search in sources :

Example 51 with Executor

use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.

the class SCCSget method getRevision.

public static InputStream getRevision(String command, File file, String revision) throws IOException {
    InputStream ret = null;
    ArrayList<String> argv = new ArrayList<String>();
    argv.add(command);
    argv.add("get");
    argv.add("-p");
    if (revision != null) {
        argv.add("-r" + revision);
    }
    argv.add(file.getCanonicalPath());
    Executor executor = new Executor(argv);
    if (executor.exec() == 0) {
        ret = executor.getOutputStream();
    }
    return ret;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList)

Example 52 with Executor

use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.

the class SSCMRepository method getHistoryLogExecutor.

/**
     * Get an executor to be used for retrieving the history log for the named
     * file or directory.
     *
     * @param file The file or directory to retrieve history for
     * @param sinceRevision  the oldest changeset to return from the executor, or
     *                  {@code null} if all changesets should be returned
     * @return An Executor ready to be started
     */
Executor getHistoryLogExecutor(final File file, String sinceRevision) throws IOException {
    List<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("history");
    if (file.isDirectory()) {
        argv.add("/");
    } else {
        argv.add(file.getName());
    }
    if (sinceRevision != null && new Scanner(sinceRevision).hasNextInt()) {
        argv.add("-v" + (Integer.parseInt(sinceRevision) + 1) + ":" + Integer.MAX_VALUE);
    }
    argv.add("-w-");
    Properties props = getProperties(file);
    String branch = props.getProperty(BRANCH_PROPERTY);
    if (branch != null && !branch.isEmpty()) {
        argv.add("-b" + branch);
    }
    String repo = props.getProperty(REPOSITORY_PROPERTY);
    if (repo != null && !repo.isEmpty()) {
        argv.add("-p" + repo);
    }
    return new Executor(argv, new File(getDirectoryName()), sinceRevision != null);
}
Also used : Scanner(java.util.Scanner) Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File)

Example 53 with Executor

use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.

the class SubversionRepository method update.

@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());
    }
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 54 with Executor

use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.

the class SubversionRepository method getHistoryLogExecutor.

/**
     * Get an executor to be used for retrieving the history log for the named
     * file.
     *
     * @param file The file to retrieve history for
     * @param sinceRevision the revision number immediately preceding the first
     *                      revision we want, or {@code null} to fetch the entire
     *                      history
     * @return An Executor ready to be started
     */
Executor getHistoryLogExecutor(final File file, String sinceRevision) {
    String abs;
    try {
        abs = file.getCanonicalPath();
    } catch (IOException exp) {
        LOGGER.log(Level.SEVERE, "Failed to get canonical path: {0}", exp.getClass().toString());
        return null;
    }
    String filename = "";
    if (abs.length() > directoryName.length()) {
        filename = abs.substring(directoryName.length() + 1);
    }
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("log");
    cmd.add("--non-interactive");
    cmd.addAll(getAuthCommandLineParams());
    cmd.add("--xml");
    cmd.add("-v");
    if (sinceRevision != null) {
        cmd.add("-r");
        // We would like to use sinceRevision+1 here, but if no new
        // revisions have been added after sinceRevision, it would fail
        // because there is no such revision as sinceRevision+1. Instead,
        // fetch the unneeded revision and remove it later.
        cmd.add("BASE:" + sinceRevision);
    }
    if (filename.length() > 0) {
        cmd.add(escapeFileName(filename));
    }
    return new Executor(cmd, new File(directoryName), sinceRevision != null);
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 55 with Executor

use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.

the class RepoRepository method update.

@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("sync");
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() != 0) {
        throw new IOException(executor.getErrorString());
    }
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Aggregations

Executor (org.opensolaris.opengrok.util.Executor)56 ArrayList (java.util.ArrayList)43 File (java.io.File)33 IOException (java.io.IOException)33 BufferedReader (java.io.BufferedReader)6 InputStream (java.io.InputStream)4 Properties (java.util.Properties)4 Matcher (java.util.regex.Matcher)4 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Date (java.util.Date)2 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)2 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 Scanner (java.util.Scanner)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1