Search in sources :

Example 51 with Executor

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

the class CVSRepository method annotate.

@Override
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");
    if (revision != null) {
        cmd.add("-r");
        cmd.add(revision);
    } else if (getBranch() != null && !getBranch().isEmpty()) {
        cmd.add("-r");
        cmd.add(getBranch());
    }
    cmd.add(file.getName());
    Executor exec = new Executor(cmd, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    CVSAnnotationParser parser = new CVSAnnotationParser(file.getName());
    int status = exec.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) });
    }
    return parser.getAnnotation();
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 52 with Executor

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

the class CVSRepository 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("log");
    if (getBranch() != null && !getBranch().isEmpty()) {
        // Generate history on this branch and follow up to the origin.
        cmd.add("-r1.1:" + branch);
    } else {
        // Get revisions on this branch only (otherwise the revisions
        // list produced by the cvs log command would be unsorted).
        cmd.add("-b");
    }
    if (filename.length() > 0) {
        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)

Example 53 with Executor

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

the class CVSRepository method getHistoryGet.

@Override
public InputStream getHistoryGet(String parent, String basename, String rev) {
    InputStream ret = null;
    String revision = rev;
    if (rev.indexOf(':') != -1) {
        revision = rev.substring(0, rev.indexOf(':'));
    }
    try {
        ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
        String[] argv = { RepoCommand, "up", "-p", "-r", revision, basename };
        Executor executor = new Executor(Arrays.asList(argv), new File(parent), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
        executor.exec();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buffer = new byte[32 * 1024];
        try (InputStream in = executor.getOutputStream()) {
            int len;
            while ((len = in.read(buffer)) != -1) {
                if (len > 0) {
                    out.write(buffer, 0, len);
                }
            }
        }
        ret = new ByteArrayInputStream(out.toByteArray());
    } catch (Exception exp) {
        LOGGER.log(Level.WARNING, "Failed to get history", exp);
    }
    return ret;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) IOException(java.io.IOException)

Example 54 with Executor

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

the class ClearCaseHistoryParser method parse.

History parse(File file, Repository repos) throws HistoryException {
    repository = (ClearCaseRepository) repos;
    try {
        Executor executor = repository.getHistoryLogExecutor(file);
        int status = executor.exec(true, this);
        if (status != 0) {
            throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
        }
        return history;
    } 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 55 with Executor

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

the class AccuRevRepository method getHistoryGet.

@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
    ArrayList<String> cmd = new ArrayList<>();
    File directory = new File(parent);
    /*
         * Only way to guarantee getting the contents of a file is to fire off
         * an AccuRev 'stat'us command to get the element ID number for the
         * subsequent 'cat' command. (Element ID's are unique for a file, unless
         * evil twins are present) This is because it is possible that the file
         * may have been moved to a different place in the depot. The 'stat'
         * command will produce a line with the format:
         *
         * <filePath> <elementID> <virtualVersion> (<realVersion>) (<status>)
         *
         *  /./myFile e:17715 CP.73_Depot/2 (3220/2) (backed)
         */
    cmd.add(RepoCommand);
    cmd.add("stat");
    cmd.add("-fe");
    cmd.add(basename);
    Executor executor = new Executor(cmd, directory);
    executor.exec();
    String elementID = null;
    try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
        String line = info.readLine();
        String[] statInfo = line.split("\\s+");
        // skip over 'e:'
        elementID = statInfo[1].substring(2);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not obtain status for {0}", basename);
    }
    if (elementID != null) {
        /*
             *  This really gets the contents of the file.
             */
        cmd.clear();
        cmd.add(RepoCommand);
        cmd.add("cat");
        cmd.add("-v");
        cmd.add(rev.trim());
        cmd.add("-e");
        cmd.add(elementID);
        executor = new Executor(cmd, directory);
        executor.exec();
        try {
            copyBytes(out::write, executor.getOutputStream());
            return true;
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Failed to obtain content for {0}", basename);
        }
    }
    return false;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) 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