Search in sources :

Example 36 with Executor

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

the class PerforceRepository method getHistoryGet.

@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
    ArrayList<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("print");
    cmd.add("-q");
    cmd.add(protectPerforceFilename(basename) + getRevisionCmd(rev));
    Executor executor = new Executor(cmd, new File(parent));
    // TODO: properly evaluate Perforce return code
    executor.exec();
    try {
        copyBytes(out::write, executor.getOutputStream());
        return true;
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failed to get history for file {0}/{1} in revision {2}: ", new Object[] { parent, basename, rev });
    }
    return false;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 37 with Executor

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

the class PerforceRepository method isInP4Depot.

/**
 * Check if a given file is in the depot.
 *
 * @param file The file to test
 * @param cmdType command timeout type
 * @return true if the given file is in the depot, false otherwise
 */
boolean isInP4Depot(File file, CommandTimeoutType cmdType) {
    boolean status = false;
    if (isWorking()) {
        RuntimeEnvironment env = RuntimeEnvironment.getInstance();
        ArrayList<String> cmd = new ArrayList<>();
        String name = protectPerforceFilename(file.getName());
        File dir = file.getParentFile();
        if (file.isDirectory()) {
            dir = file;
            name = "*";
            cmd.add(RepoCommand);
            cmd.add("dirs");
            cmd.add(name);
            Executor executor = new Executor(cmd, dir, env.getCommandTimeout(cmdType));
            executor.exec();
            /* OUTPUT:
                 stdout: //depot_path/name
                 stderr: name - no such file(s).
                 */
            status = (executor.getOutputString().contains("//"));
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.log(Level.FINEST, "p4 status is {0} for {1}", new Object[] { status, file });
            }
        }
        if (!status) {
            cmd.clear();
            cmd.add(RepoCommand);
            cmd.add("files");
            cmd.add(name);
            Executor executor = new Executor(cmd, dir, env.getCommandTimeout(cmdType));
            executor.exec();
            /* OUTPUT:
                 stdout: //depot_path/name
                 stderr: name - no such file(s).
                 */
            status = (executor.getOutputString().contains("//"));
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.log(Level.FINEST, "p4 status is {0} for {1}", new Object[] { status, file });
            }
        }
    }
    return status;
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 38 with Executor

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

the class PerforceRepository method annotate.

@Override
public Annotation annotate(File file, String rev) {
    ArrayList<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("annotate");
    cmd.add("-qci");
    cmd.add(protectPerforceFilename(file.getName()) + getRevisionCmd(rev));
    Executor executor = new Executor(cmd, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    PerforceAnnotationParser parser = new PerforceAnnotationParser(this, file);
    executor.exec(true, parser);
    return parser.getAnnotation();
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 39 with Executor

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

the class MercurialHistoryParserRevisionsOnly method parse.

void parse(File file, String sinceRevision) throws HistoryException {
    try {
        Executor executor = repository.getHistoryLogExecutor(file, sinceRevision, null, true);
        int status = executor.exec(true, this);
        if (status != 0) {
            throw new HistoryException(String.format("Failed to get revisions for: \"%s\" since revision %s Exit code: %d", file.getAbsolutePath(), sinceRevision, status));
        }
    } catch (IOException e) {
        throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
    }
}
Also used : Executor(org.opengrok.indexer.util.Executor) IOException(java.io.IOException)

Example 40 with Executor

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

the class MonotoneRepository method annotate.

/**
 * Annotate the specified file/revision using the {@code mnt annotate} command.
 *
 * @param file file to annotate
 * @param revision revision to annotate
 * @return file annotation
 * @throws java.io.IOException if I/O exception occurred or the command failed
 */
@Override
public Annotation annotate(File file, String revision) throws IOException {
    ArrayList<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("annotate");
    cmd.add(getQuietOption());
    if (revision != null) {
        cmd.add("-r");
        cmd.add(revision);
    }
    cmd.add(file.getName());
    File directory = new File(getDirectoryName());
    Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    MonotoneAnnotationParser parser = new MonotoneAnnotationParser(file);
    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) 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