Search in sources :

Example 6 with Executor

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

the class AccuRevRepository method annotate.

@Override
public Annotation annotate(File file, String rev) throws IOException {
    Annotation a = new Annotation(file.getName());
    ArrayList<String> cmd = new ArrayList<>();
    String path = file.getAbsolutePath();
    cmd.add(RepoCommand);
    cmd.add("annotate");
    // version & user
    cmd.add("-fvu");
    if (rev != null) {
        cmd.add("-v");
        cmd.add(rev.trim());
    }
    cmd.add(path);
    Executor executor = new Executor(cmd, file.getParentFile());
    executor.exec();
    try (BufferedReader reader = new BufferedReader(executor.getOutputReader())) {
        String line;
        int lineno = 0;
        try {
            while ((line = reader.readLine()) != null) {
                ++lineno;
                Matcher matcher = annotationPattern.matcher(line);
                if (matcher.find()) {
                    String version = matcher.group(1);
                    String author = matcher.group(2);
                    a.addLine(version, author, true);
                } else {
                    LOGGER.log(Level.SEVERE, "Did not find annotation in line {0}: [{1}]", new Object[] { lineno, line });
                }
            }
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Could not read annotations for " + file, e);
        }
    }
    return a;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 7 with Executor

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

the class BazaarHistoryParser method parse.

History parse(File file, String sinceRevision) throws HistoryException {
    try {
        Executor executor = repository.getHistoryLogExecutor(file, sinceRevision);
        int status = executor.exec(true, this);
        if (status != 0) {
            throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
        }
    } catch (IOException e) {
        throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
    }
    // an exception.
    if (sinceRevision != null) {
        repository.removeAndVerifyOldestChangeset(entries, sinceRevision);
    }
    return new History(entries);
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) IOException(java.io.IOException)

Example 8 with Executor

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

the class MercurialHistoryParser method parse.

/**
     * Parse the history for the specified file or directory. If a changeset is
     * specified, only return the history from the changeset right after the
     * specified one.
     *
     * @param file the file or directory to get history for
     * @param changeset the changeset right before the first one to fetch, or
     * {@code null} if all changesets should be fetched
     * @return history for the specified file or directory
     * @throws HistoryException if an error happens when parsing the history
     */
History parse(File file, String changeset) throws HistoryException {
    isDir = file.isDirectory();
    try {
        Executor executor = repository.getHistoryLogExecutor(file, changeset);
        int status = executor.exec(true, this);
        if (status != 0) {
            throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
        }
    } catch (IOException e) {
        throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
    }
    // an exception.
    if (changeset != null) {
        repository.removeAndVerifyOldestChangeset(entries, changeset);
    }
    return new History(entries, renamedFiles);
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) IOException(java.io.IOException)

Example 9 with Executor

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

the class MercurialRepository 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.
     *                  For files this does not apply and full history is returned.
     * @return An Executor ready to be started
     */
Executor getHistoryLogExecutor(File file, String sinceRevision) throws HistoryException, IOException {
    String abs = file.getCanonicalPath();
    String filename = "";
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    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");
    if (file.isDirectory()) {
        // on that branch and also follow any changesets from the parent branch.
        if (sinceRevision != null) {
            cmd.add("-r");
            String[] parts = sinceRevision.split(":");
            if (parts.length == 2) {
                cmd.add("reverse(" + parts[0] + "::'" + getBranch() + "')");
            } else {
                throw new HistoryException("Don't know how to parse changeset identifier: " + sinceRevision);
            }
        } else {
            cmd.add("-r");
            cmd.add("reverse(0::'" + getBranch() + "')");
        }
    } else {
        // For plain files we would like to follow the complete history
        // (this is necessary for getting the original name in given revision
        // when handling renamed files)
        // It is not needed to filter on a branch as 'hg log' will follow
        // the active branch.
        // Due to behavior of recent Mercurial versions, it is not possible
        // to filter the changesets of a file based on revision.
        // For files this does not matter since if getHistory() is called
        // for a file, the file has to be renamed so we want its complete history.
        cmd.add("--follow");
        cmd.add(filename);
    }
    cmd.add("--template");
    if (file.isDirectory()) {
        cmd.add(env.isHandleHistoryOfRenamedFiles() ? DIR_TEMPLATE_RENAMED : DIR_TEMPLATE);
    } else {
        cmd.add(FILE_TEMPLATE);
    }
    return new Executor(cmd, new File(directoryName), sinceRevision != null);
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 10 with Executor

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

the class GitRepository 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 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 {
    String abs = file.getCanonicalPath();
    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("--abbrev-commit");
    cmd.add(ABBREV_LOG);
    cmd.add("--name-only");
    cmd.add("--pretty=fuller");
    cmd.add("--date=rfc");
    if (file.isFile() && RuntimeEnvironment.getInstance().isHandleHistoryOfRenamedFiles()) {
        cmd.add("--follow");
    }
    if (sinceRevision != null) {
        cmd.add(sinceRevision + "..");
    }
    if (filename.length() > 0) {
        cmd.add("--");
        cmd.add(filename);
    }
    return new Executor(cmd, new File(getDirectoryName()), sinceRevision != null);
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) 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