Search in sources :

Example 46 with Executor

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

the class GitHistoryParser method parse.

/**
     * Parse the history for the specified file.
     *
     * @param file the file to parse history for
     * @param repos Pointer to the GitRepository
     * @param sinceRevision the oldest changeset to return from the executor, or
     *                      {@code null} if all changesets should be returned
     * @return object representing the file's history
     */
History parse(File file, Repository repos, String sinceRevision) throws HistoryException {
    myDir = repos.getDirectoryName() + File.separator;
    repository = (GitRepository) repos;
    RenamedFilesParser parser = new RenamedFilesParser();
    try {
        Executor executor = repository.getHistoryLogExecutor(file, sinceRevision);
        int status = executor.exec(true, this);
        if (status != 0) {
            throw new HistoryException(String.format("Failed to get history for: \"%s\" Exit code: %d", file.getAbsolutePath(), status));
        }
        if (RuntimeEnvironment.getInstance().isHandleHistoryOfRenamedFiles()) {
            executor = repository.getRenamedFilesExecutor(file, sinceRevision);
            status = executor.exec(true, parser);
            if (status != 0) {
                throw new HistoryException(String.format("Failed to get renamed files for: \"%s\" Exit code: %d", file.getAbsolutePath(), status));
            }
        }
    } catch (IOException e) {
        throw new HistoryException(String.format("Failed to get history for: \"%s\"", file.getAbsolutePath()), e);
    }
    return new History(entries, parser.getRenamedFiles());
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) IOException(java.io.IOException)

Example 47 with Executor

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

the class GitRepository method determineCurrentVersion.

@Override
String determineCurrentVersion() throws IOException {
    File directory = new File(directoryName);
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("log");
    cmd.add("-1");
    cmd.add("--pretty=%cd: %h %an %s");
    cmd.add("--date=rfc");
    Executor executor = new Executor(cmd, directory);
    if (executor.exec(false) != 0) {
        throw new IOException(executor.getErrorString());
    }
    String output = executor.getOutputString().trim();
    int indexOf = StringUtils.nthIndexOf(output, ":", 3);
    if (indexOf < 0) {
        throw new IOException(String.format("Couldn't extract date from \"%s\".", new Object[] { output }));
    }
    try {
        Date date = getDateFormat().parse(output.substring(0, indexOf));
        return String.format("%s%s", new Object[] { outputDateFormat.format(date), output.substring(indexOf) });
    } catch (ParseException ex) {
        throw new IOException(ex);
    }
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ParseException(java.text.ParseException) File(java.io.File) Date(java.util.Date)

Example 48 with Executor

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

the class GitRepository method getRenamedFilesExecutor.

Executor getRenamedFilesExecutor(final File file, String sinceRevision) throws IOException {
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    List<String> cmd = new ArrayList<>();
    cmd.add(RepoCommand);
    cmd.add("log");
    // similarity 80%
    cmd.add("--find-renames=8");
    cmd.add("--summary");
    cmd.add(ABBREV_LOG);
    cmd.add("--name-status");
    cmd.add("--oneline");
    if (file.isFile()) {
        cmd.add("--follow");
    }
    if (sinceRevision != null) {
        cmd.add(sinceRevision + "..");
    }
    if (file.getCanonicalPath().length() > directoryName.length() + 1) {
        // this is a file in the repository
        cmd.add("--");
        cmd.add(file.getCanonicalPath().substring(directoryName.length() + 1));
    }
    return new Executor(cmd, new File(getDirectoryName()), sinceRevision != null);
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 49 with Executor

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

the class PerforceRepository method annotate.

@Override
public Annotation annotate(File file, String rev) throws IOException {
    Annotation a = new Annotation(file.getName());
    List<HistoryEntry> revisions = PerforceHistoryParser.getRevisions(file, rev).getHistoryEntries();
    HashMap<String, String> revAuthor = new HashMap<>();
    for (HistoryEntry entry : revisions) {
        // a.addDesc(entry.getRevision(), entry.getMessage());
        revAuthor.put(entry.getRevision(), entry.getAuthor());
    }
    ArrayList<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("annotate");
    cmd.add("-qci");
    cmd.add(file.getPath() + getRevisionCmd(rev));
    Executor executor = new Executor(cmd, file.getParentFile());
    executor.exec();
    String line;
    int lineno = 0;
    try (BufferedReader reader = new BufferedReader(executor.getOutputReader())) {
        while ((line = reader.readLine()) != null) {
            ++lineno;
            Matcher matcher = annotation_pattern.matcher(line);
            if (matcher.find()) {
                String revision = matcher.group(1);
                String author = revAuthor.get(revision);
                a.addLine(revision, author, true);
            } else {
                LOGGER.log(Level.SEVERE, "Error: did not find annotation in line {0}: [{1}]", new Object[] { lineno, line });
            }
        }
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Error: Could not read annotations for " + file, e);
    }
    return a;
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Executor(org.opensolaris.opengrok.util.Executor) BufferedReader(java.io.BufferedReader)

Example 50 with Executor

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

the class PerforceRepository method update.

@Override
public void update() throws IOException {
    File directory = new File(getDirectoryName());
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("sync");
    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)

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