Search in sources :

Example 1 with Executor

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

the class AccuRevHistoryParser method parse.

/**
     * Parse the history for the specified file.
     *
     * @param file the file to parse history for
     * @param repos Pointer to the {@code AccuRevRepository}
     * @return object representing the file's history
     * @throws HistoryException if a problem occurs while executing p4 command
     */
History parse(File file, Repository repos) throws HistoryException {
    repository = (AccuRevRepository) repos;
    history = null;
    foundHistory = false;
    String relPath = repository.getDepotRelativePath(file);
    /*
         * When the path given is really just the root to the source
         * workarea, no history is available, create fake.
         */
    String rootRelativePath = File.separator + "." + File.separator;
    if (relPath.equals(rootRelativePath)) {
        List<HistoryEntry> entries = new ArrayList<HistoryEntry>();
        entries.add(new HistoryEntry("", new Date(), "OpenGrok", null, "Workspace Root", true));
        history = new History(entries);
    } else {
        try {
            /*
                 * Errors will be logged, so not bothering to add to the output.
                 */
            Executor executor = repository.getHistoryLogExecutor(file);
            executor.exec(true, this);
            /*
                 * Try again because there was no 'keep' history.
                 */
            if (!foundHistory) {
                executor = repository.getHistoryLogExecutor(file);
                executor.exec(true, this);
            }
        } catch (IOException e) {
            throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"" + e);
        }
    }
    return history;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date)

Example 2 with Executor

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

the class AccuRevRepository method getHistoryGet.

@Override
InputStream getHistoryGet(String parent, String basename, String rev) {
    ArrayList<String> cmd = new ArrayList<>();
    InputStream inputStream = null;
    File directory = new File(parent);
    /*
         * ----------------------------------------------------------------- The
         * 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();
        inputStream = new ByteArrayInputStream(executor.getOutputString().getBytes());
    }
    return inputStream;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File)

Example 3 with Executor

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

the class AccuRevRepository method isInAccuRevDepot.

/**
     * Check if a given path is associated with an AccuRev workspace
     *
     * The AccuRev 'info' command provides a Depot name when in a known
     * workspace. Otherwise, the Depot name will be missing.
     *
     * @param path The presumed path to an AccuRev workspace directory.
     * @return true if the given path is in the depot, false otherwise
     */
private boolean isInAccuRevDepot(File wsPath) {
    boolean status = false;
    if (isWorking()) {
        ArrayList<String> cmd = new ArrayList<>();
        cmd.add(RepoCommand);
        cmd.add("info");
        Executor executor = new Executor(cmd, wsPath);
        executor.exec(true);
        try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
            String line;
            while ((line = info.readLine()) != null) {
                Matcher depotMatch = depotPattern.matcher(line);
                if (line.contains("not logged in")) {
                    LOGGER.log(Level.SEVERE, "Not logged into AccuRev server");
                    break;
                }
                if (depotMatch.find()) {
                    status = true;
                    break;
                }
            }
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Could not find AccuRev repository for {0}", wsPath);
        }
    }
    return status;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 4 with Executor

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

the class AccuRevRepository method update.

@Override
public void update() throws IOException {
    File directory = new File(getDirectoryName());
    List<String> cmd = new ArrayList<>();
    cmd.add(RepoCommand);
    cmd.add("update");
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() != 0) {
        throw new IOException(executor.getErrorString());
    }
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 5 with Executor

use of org.opensolaris.opengrok.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 {
    String path = file.getAbsolutePath();
    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.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

Executor (org.opensolaris.opengrok.util.Executor)56 ArrayList (java.util.ArrayList)43 File (java.io.File)33 IOException (java.io.IOException)33 BufferedReader (java.io.BufferedReader)6 InputStream (java.io.InputStream)4 Properties (java.util.Properties)4 Matcher (java.util.regex.Matcher)4 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Date (java.util.Date)2 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)2 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 ParseException (java.text.ParseException)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