Search in sources :

Example 11 with Executor

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

the class MonotoneRepository 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);
        ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
        String[] argv = { RepoCommand, "cat", "-r", rev, filename };
        Executor executor = new Executor(Arrays.asList(argv), directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
        copyBytes(out::write, executor.getOutputStream());
        return true;
    } catch (Exception exp) {
        LOGGER.log(Level.SEVERE, "Failed to get history: {0}", exp.getClass().toString());
    }
    return false;
}
Also used : Executor(org.opengrok.indexer.util.Executor) File(java.io.File) IOException(java.io.IOException)

Example 12 with Executor

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

the class MonotoneRepository 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(File file, String sinceRevision) throws IOException {
    String filename = getRepoRelativePath(file);
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("log");
    if (sinceRevision != null) {
        cmd.add("--to");
        cmd.add(sinceRevision);
    }
    cmd.add("--no-graph");
    cmd.add("--no-merges");
    cmd.add("--no-format-dates");
    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 13 with Executor

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

the class MonotoneRepository method determineParent.

@Override
String determineParent(CommandTimeoutType cmdType) throws IOException {
    String parent = null;
    File directory = new File(getDirectoryName());
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("ls");
    cmd.add("vars");
    cmd.add("database");
    Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
    executor.exec();
    try (BufferedReader in = new BufferedReader(executor.getOutputReader())) {
        String line;
        while ((line = in.readLine()) != null) {
            if (line.startsWith("database") && line.contains("default-server")) {
                String[] parts = line.split("\\s+");
                if (parts.length != 3) {
                    LOGGER.log(Level.WARNING, "Failed to get parent for {0}", getDirectoryName());
                }
                parent = parts[2];
                break;
            }
        }
    }
    return parent;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 14 with Executor

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

the class AccuRevRepository method annotate.

@Override
public Annotation annotate(File file, String rev) throws IOException {
    ArrayList<String> cmd = new ArrayList<>();
    // Do not use absolute paths because symbolic links will cause havoc.
    String path = getDepotRelativePath(file);
    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(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    AccuRevAnnotationParser parser = new AccuRevAnnotationParser(file.getName());
    executor.exec(true, parser);
    return parser.getAnnotation();
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 15 with Executor

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

the class AccuRevRepository method getHistoryLogExecutor.

/**
 * Get an executor to be used for retrieving the history log for the given
 * file. (used by AccuRevHistoryParser).
 *
 * @param file file for which history is to be retrieved.
 * @return An Executor ready to be started
 */
Executor getHistoryLogExecutor(File file) throws IOException {
    // Do not use absolute paths because symbolic links will cause havoc.
    String path = getDepotRelativePath(file);
    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(RepoCommand);
    cmd.add("hist");
    if (!file.isDirectory()) {
        cmd.add("-k");
        // get a list of all 'real' file versions
        cmd.add("keep");
    }
    cmd.add(path);
    File workingDirectory = file.isDirectory() ? file : file.getParentFile();
    return new Executor(cmd, workingDirectory);
}
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