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());
}
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);
}
}
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);
}
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;
}
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());
}
}
Aggregations