Search in sources :

Example 16 with Executor

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

the class BazaarRepository method determineParent.

@Override
String determineParent(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("config");
    cmd.add("parent_location");
    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)

Example 17 with Executor

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

the class BazaarRepository method annotate.

/**
 * Annotate the specified file/revision.
 *
 * @param file file to annotate
 * @param revision revision to annotate
 * @return file annotation
 * @throws java.io.IOException if I/O exception occurred
 */
@Override
public Annotation annotate(File file, String revision) throws IOException {
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("blame");
    cmd.add("--all");
    cmd.add("--long");
    if (revision != null) {
        cmd.add("-r");
        cmd.add(revision);
    }
    cmd.add(file.getName());
    Executor executor = new Executor(cmd, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    BazaarAnnotationParser parser = new BazaarAnnotationParser(file.getName());
    int status = executor.exec(true, parser);
    if (status != 0) {
        LOGGER.log(Level.WARNING, "Failed to get annotations for: \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status) });
        throw new IOException(executor.getErrorString());
    } else {
        return parser.getAnnotation();
    }
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 18 with Executor

use of org.opengrok.indexer.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 sinceRevision the changeset right before the first one to fetch, or
 * {@code null} if all changesets should be fetched
 * @param tillRevision end revision or {@code null}
 * @param numCommits number of revisions to get
 * @return history for the specified file or directory
 * @throws HistoryException if an error happens when parsing the history
 */
History parse(File file, String sinceRevision, String tillRevision, Integer numCommits) throws HistoryException {
    isDir = file.isDirectory();
    try {
        Executor executor = repository.getHistoryLogExecutor(file, sinceRevision, tillRevision, false, numCommits);
        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);
    }
    // See getHistoryLogExecutor() for explanation.
    if (repository.isHandleRenamedFiles() && file.isFile() && tillRevision != null) {
        removeChangesets(entries, tillRevision);
    }
    return new History(entries, renamedFiles);
}
Also used : Executor(org.opengrok.indexer.util.Executor) IOException(java.io.IOException)

Example 19 with Executor

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

the class BitKeeperRepository method fileHasHistory.

/**
 * Returns whether BitKeeper has history for a file.
 *
 * @return ret a boolean denoting whether it does or not
 */
@Override
public boolean fileHasHistory(File file) {
    final File absolute = file.getAbsoluteFile();
    final File directory = absolute.getParentFile();
    final String basename = absolute.getName();
    final ArrayList<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("files");
    argv.add(basename);
    final Executor executor = new Executor(argv, directory);
    if (executor.exec(true) != 0) {
        LOGGER.log(Level.SEVERE, "Failed to check file: {0}", executor.getErrorString());
        return false;
    }
    return executor.getOutputString().trim().equals(basename);
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 20 with Executor

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

the class BitKeeperRepository method getHistoryGet.

@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String revision) {
    final File directory = new File(parent).getAbsoluteFile();
    final List<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("get");
    argv.add("-p");
    if (revision != null) {
        argv.add("-r" + revision);
    }
    argv.add(basename);
    final Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    if (executor.exec(true) != 0) {
        LOGGER.log(Level.SEVERE, "Failed to get history: {0}", executor.getErrorString());
        return false;
    }
    try {
        copyBytes(out::write, executor.getOutputStream());
        return true;
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failed to get content for {0}", basename);
    }
    return false;
}
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