Search in sources :

Example 31 with Executor

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

the class SCCSRepository method getAuthors.

private Map<String, String> getAuthors(File file) throws IOException {
    ArrayList<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("prs");
    argv.add("-e");
    argv.add("-d:I: :P:");
    argv.add(file.getCanonicalPath());
    Executor executor = new Executor(argv, file.getCanonicalFile().getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    SCCSRepositoryAuthorParser parser = new SCCSRepositoryAuthorParser();
    executor.exec(true, parser);
    return parser.getAuthors();
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 32 with Executor

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

the class SSCMHistoryParser 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);
    }
    return history;
}
Also used : Executor(org.opengrok.indexer.util.Executor) IOException(java.io.IOException)

Example 33 with Executor

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

the class MercurialRepository method findOriginalName.

/**
 * Get the name of file in given revision. This is used to get contents
 * of a file in historical revision.
 *
 * @param fullpath file path
 * @param fullRevToFind revision number (in the form of
 * {rev}:{node|short})
 * @return original filename
 */
private String findOriginalName(String fullpath, String fullRevToFind) throws IOException {
    Matcher matcher = LOG_COPIES_PATTERN.matcher("");
    String file = fullpath.substring(getDirectoryName().length() + 1);
    ArrayList<String> argv = new ArrayList<>();
    File directory = new File(getDirectoryName());
    // Extract {rev} from the full revision specification string.
    String[] revArray = fullRevToFind.split(":");
    String revToFind = revArray[0];
    if (revToFind.isEmpty()) {
        LOGGER.log(Level.SEVERE, "Invalid revision string: {0}", fullRevToFind);
        return null;
    }
    /*
         * Get the list of file renames for given file to the specified
         * revision. We need to get them from the newest to the oldest
         * so that we can follow the renames down to the revision we are after.
         */
    argv.add(ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK));
    argv.add("log");
    argv.add("--follow");
    /*
         * hg log --follow -r behavior has changed since Mercurial 3.4
         * so filtering the changesets of a file no longer works with --follow.
         * This is tracked by https://bz.mercurial-scm.org/show_bug.cgi?id=4959
         * Once this is fixed and Mercurial versions with the fix are prevalent,
         * we can revert to the old behavior.
         */
    // argv.add("-r");
    // Use reverse() to get the changesets from newest to oldest.
    // argv.add("reverse(" + rev_to_find + ":)");
    argv.add("--template");
    argv.add("{rev}:{file_copies}\\n");
    argv.add(fullpath);
    Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    int status = executor.exec();
    try (BufferedReader in = new BufferedReader(new InputStreamReader(executor.getOutputStream()))) {
        String line;
        while ((line = in.readLine()) != null) {
            matcher.reset(line);
            if (!matcher.find()) {
                LOGGER.log(Level.SEVERE, "Failed to match: {0}", line);
                return (null);
            }
            String rev = matcher.group(1);
            String content = matcher.group(2);
            if (rev.equals(revToFind)) {
                break;
            }
            if (!content.isEmpty()) {
                /*
                     * Split string of 'newfile1 (oldfile1)newfile2 (oldfile2) ...' into pairs of renames.
                     */
                String[] splitArray = content.split("\\)");
                for (String s : splitArray) {
                    /*
                         * This will fail for file names containing ' ('.
                         */
                    String[] move = s.split(" \\(");
                    if (file.equals(move[0])) {
                        file = move[1];
                        break;
                    }
                }
            }
        }
    }
    if (status != 0) {
        LOGGER.log(Level.WARNING, "Failed to get original name in revision {2} for: \"{0}\" Exit code: {1}", new Object[] { fullpath, String.valueOf(status), fullRevToFind });
        return null;
    }
    return (fullpath.substring(0, getDirectoryName().length() + 1) + file);
}
Also used : Executor(org.opengrok.indexer.util.Executor) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 34 with Executor

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

the class MercurialRepository method determineBranch.

/**
 * Return name of the branch or "default".
 */
@Override
String determineBranch(CommandTimeoutType cmdType) throws IOException {
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("branch");
    Executor executor = new Executor(cmd, new File(getDirectoryName()), RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
    if (executor.exec(false) != 0) {
        throw new IOException(executor.getErrorString());
    }
    return executor.getOutputString().trim();
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 35 with Executor

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

the class PerforceRepository method determineCurrentVersion.

@Override
String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException {
    File directory = new File(getDirectoryName());
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("changes");
    cmd.add("-t");
    cmd.add("-m");
    cmd.add("1");
    cmd.add("...#have");
    Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
    if (executor.exec(false) != 0) {
        throw new IOException(executor.getErrorString());
    }
    return executor.getOutputString().trim();
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Aggregations

Executor (org.opengrok.indexer.util.Executor)63 ArrayList (java.util.ArrayList)48 File (java.io.File)31 IOException (java.io.IOException)30 BufferedReader (java.io.BufferedReader)4 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)4 Properties (java.util.Properties)3 Matcher (java.util.regex.Matcher)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Path (java.nio.file.Path)1 Date (java.util.Date)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