Search in sources :

Example 6 with Executor

use of org.opengrok.indexer.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.
 * @param tillRevision end revision
 * @param revisionsOnly get only revision numbers
 * @param numRevisions number of revisions to get
 * @return An Executor ready to be started
 */
Executor getHistoryLogExecutor(File file, String sinceRevision, String tillRevision, boolean revisionsOnly, Integer numRevisions) throws HistoryException, IOException {
    String filename = getRepoRelativePath(file);
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("log");
    if (file.isDirectory()) {
        // Note: assumes one of them is not null
        if ((sinceRevision != null) || (tillRevision != null)) {
            cmd.add("-r");
            StringBuilder stringBuilder = new StringBuilder();
            if (!revisionsOnly) {
                stringBuilder.append("reverse(");
            }
            if (sinceRevision != null) {
                stringBuilder.append(getRevisionNum(sinceRevision));
            }
            stringBuilder.append("::");
            if (tillRevision != null) {
                stringBuilder.append(getRevisionNum(tillRevision));
            } else {
                // If this is non-default branch we would like to get the changesets
                // on that branch and also follow any changesets from the parent branch.
                stringBuilder.append("'").append(getBranch()).append("'");
            }
            if (!revisionsOnly) {
                stringBuilder.append(")");
            }
            cmd.add(stringBuilder.toString());
        } else {
            cmd.add("-r");
            cmd.add("reverse(0::'" + getBranch() + "')");
        }
    } else {
        // Even if the revision filtering worked, this approach would be probably faster and consumed less memory.
        if (this.isHandleRenamedFiles()) {
            // When using --follow, the returned revisions are from newest to oldest, hence no reverse() is needed.
            cmd.add("--follow");
        }
    }
    cmd.add("--template");
    if (revisionsOnly) {
        cmd.add(TEMPLATE_REVS);
    } else {
        if (file.isDirectory()) {
            cmd.add(this.isHandleRenamedFiles() ? DIR_TEMPLATE_RENAMED : DIR_TEMPLATE);
        } else {
            cmd.add(FILE_TEMPLATE);
        }
    }
    if (numRevisions != null && numRevisions > 0) {
        cmd.add("-l");
        cmd.add(numRevisions.toString());
    }
    if (!filename.isEmpty()) {
        cmd.add("--");
        cmd.add(filename);
    }
    return new Executor(cmd, new File(getDirectoryName()), sinceRevision != null);
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 7 with Executor

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

the class MercurialRepository method buildTagList.

@Override
protected void buildTagList(File directory, CommandTimeoutType cmdType) {
    this.tagList = new TreeSet<>();
    ArrayList<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("tags");
    Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
    MercurialTagParser parser = new MercurialTagParser();
    int status = executor.exec(true, parser);
    if (status != 0) {
        LOGGER.log(Level.WARNING, "Failed to get tags for: \"{0}\" Exit code: {1}", new Object[] { directory.getAbsolutePath(), String.valueOf(status) });
    } else {
        this.tagList = parser.getEntries();
    }
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 8 with Executor

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

the class MonotoneHistoryParser 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 {
    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);
    }
    return new History(entries);
}
Also used : Executor(org.opengrok.indexer.util.Executor) IOException(java.io.IOException)

Example 9 with Executor

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

the class ClearCaseRepository method getHistoryGet.

@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
    File directory = new File(getDirectoryName());
    try {
        String filename = (new File(parent, basename)).getCanonicalPath().substring(getDirectoryName().length() + 1);
        final File tmp = File.createTempFile("opengrok", "tmp");
        String tmpName = tmp.getCanonicalPath();
        // cleartool can't get to a previously existing file
        if (tmp.exists() && !tmp.delete()) {
            LOGGER.log(Level.WARNING, "Failed to remove temporary file used by history cache");
        }
        String decorated = filename + "@@" + rev;
        ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
        String[] argv = { RepoCommand, "get", "-to", tmpName, decorated };
        Executor executor = new Executor(Arrays.asList(argv), directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
        int status = executor.exec();
        if (status != 0) {
            LOGGER.log(Level.SEVERE, "Failed to get history: {0}", executor.getErrorString());
            return false;
        }
        try (FileInputStream in = new FileInputStream(tmp)) {
            copyBytes(out::write, in);
        } finally {
            // delete the temporary file on close
            if (!tmp.delete()) {
                // failed, lets do the next best thing then ..
                // delete it on JVM exit
                tmp.deleteOnExit();
            }
        }
        return true;
    } catch (Exception exp) {
        LOGGER.log(Level.WARNING, "Failed to get history: " + exp.getClass().toString(), exp);
    }
    return false;
}
Also used : Executor(org.opengrok.indexer.util.Executor) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 10 with Executor

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

the class ClearCaseRepository 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
 * @return An Executor ready to be started
 */
Executor getHistoryLogExecutor(final File file) throws IOException {
    String filename = getRepoRelativePath(file);
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("lshistory");
    if (file.isDirectory()) {
        cmd.add("-dir");
    }
    cmd.add("-fmt");
    cmd.add("%e\n%Nd\n%Fu (%u)\n%Vn\n%Nc\n.\n");
    cmd.add(filename);
    return new Executor(cmd, new File(getDirectoryName()));
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) 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