Search in sources :

Example 41 with Executor

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

the class PerforceHistoryParser method parseDirectory.

private History parseDirectory(File file, String sinceRevision) throws IOException {
    ArrayList<String> cmd = new ArrayList<>();
    // First run
    cmd.add(repo.RepoCommand);
    cmd.add("changes");
    cmd.add("-tl");
    String directorySpec = "..." + asRevisionSuffix(sinceRevision);
    cmd.add(directorySpec);
    Executor executor = new Executor(cmd, file);
    executor.exec();
    History history = parseChanges(executor.getOutputReader());
    // Run filelog without -l
    cmd.clear();
    cmd.add(repo.RepoCommand);
    cmd.add("filelog");
    cmd.add("-sti");
    cmd.add(directorySpec);
    executor = new Executor(cmd, file);
    executor.exec();
    parseTruncatedFileLog(history, executor.getOutputReader());
    return history;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 42 with Executor

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

the class PerforceHistoryParser method getRevisions.

/**
 * Retrieve the history of a given file.
 *
 * @param file the file to parse history for
 * @param sinceRevision the revision at which to end history
 * @return object representing the file's history
 */
History getRevisions(File file, String sinceRevision) throws IOException {
    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(repo.RepoCommand);
    cmd.add("filelog");
    cmd.add("-slti");
    cmd.add(protectPerforceFilename(file.getName()) + asRevisionSuffix(sinceRevision));
    Executor executor = new Executor(cmd, file.getParentFile());
    executor.exec();
    return parseFileLog(executor.getOutputReader());
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 43 with Executor

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

the class SSCMRepository method getHistoryGet.

@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
    File directory = new File(parent);
    try {
        final File tmp = Files.createTempDirectory("opengrokSSCMtmp").toFile();
        String tmpName = tmp.getCanonicalPath();
        List<String> argv = new ArrayList<>();
        ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
        argv.add(RepoCommand);
        argv.add("get");
        argv.add(basename);
        argv.add("-d" + tmpName);
        Properties props = getProperties(directory);
        String branch = props.getProperty(BRANCH_PROPERTY);
        if (branch != null && !branch.isEmpty()) {
            argv.add("-b" + branch);
        }
        String repo = props.getProperty(REPOSITORY_PROPERTY);
        if (repo != null && !repo.isEmpty()) {
            argv.add("-p" + repo);
        }
        if (rev != null) {
            argv.add("-v" + rev);
        }
        argv.add("-q");
        argv.add("-tmodify");
        argv.add("-wreplace");
        Executor exec = new Executor(argv, directory);
        int status = exec.exec();
        if (status != 0) {
            LOGGER.log(Level.WARNING, "Failed get revision {2} for: \"{0}\" Exit code: {1}", new Object[] { new File(parent, basename).getAbsolutePath(), String.valueOf(status), rev });
            return false;
        }
        File tmpFile = new File(tmp, basename);
        try (FileInputStream in = new FileInputStream(tmpFile)) {
            copyBytes(out::write, in);
        } finally {
            boolean deleteOnExit = false;
            // delete the temporary file on close
            if (!tmpFile.delete()) {
                // try on JVM exit
                deleteOnExit = true;
                tmpFile.deleteOnExit();
            }
            // delete the temporary directory on close
            if (deleteOnExit || !tmp.delete()) {
                // try on JVM exit
                tmp.deleteOnExit();
            }
        }
        return true;
    } catch (IOException exception) {
        LOGGER.log(Level.SEVERE, "Failed to get file", exception);
    }
    return false;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 44 with Executor

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

the class SSCMRepository 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(final File file, String sinceRevision) throws IOException {
    List<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("history");
    if (file.isDirectory()) {
        argv.add("/");
    } else {
        argv.add(file.getName());
    }
    if (sinceRevision != null) {
        try (Scanner scanner = new Scanner(sinceRevision)) {
            if (scanner.hasNextInt()) {
                argv.add("-v" + (Integer.parseInt(sinceRevision) + 1) + ":" + Integer.MAX_VALUE);
            }
        }
    }
    argv.add("-w-");
    Properties props = getProperties(file);
    String branch = props.getProperty(BRANCH_PROPERTY);
    if (branch != null && !branch.isEmpty()) {
        argv.add("-b" + branch);
    }
    String repo = props.getProperty(REPOSITORY_PROPERTY);
    if (repo != null && !repo.isEmpty()) {
        argv.add("-p" + repo);
    }
    return new Executor(argv, new File(getDirectoryName()), sinceRevision != null);
}
Also used : Scanner(java.util.Scanner) Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File)

Example 45 with Executor

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

the class SubversionHistoryParser method parse.

/**
 * Parse the history for the specified file.
 *
 * @param file the file to parse history for
 * @param repos Pointer to the SubversionRepository
 * @param sinceRevision the revision number immediately preceding the first
 * revision we want, or {@code null} to fetch the entire history
 * @return object representing the file's history
 */
History parse(File file, SubversionRepository repos, String sinceRevision, int numEntries, CommandTimeoutType cmdType) throws HistoryException {
    initSaxParser();
    handler = new Handler(repos.getDirectoryName(), repos.reposPath, RuntimeEnvironment.getInstance().getSourceRootPath().length(), repos);
    Executor executor;
    try {
        executor = repos.getHistoryLogExecutor(file, sinceRevision, numEntries, cmdType);
    } catch (IOException e) {
        throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
    }
    int status = executor.exec(true, this);
    if (status != 0) {
        throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
    }
    List<HistoryEntry> entries = handler.entries;
    // sinceRevision. Remove it.
    if (sinceRevision != null) {
        repos.removeAndVerifyOldestChangeset(entries, sinceRevision);
    }
    return new History(entries, handler.getRenamedFiles());
}
Also used : Executor(org.opengrok.indexer.util.Executor) IOException(java.io.IOException)

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