use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class GitRepository method annotate.
/**
* Annotate the specified file/revision.
*
* @param file file to annotate
* @param revision revision to annotate
* @return file annotation
* @throws java.io.IOException
*/
@Override
public Annotation annotate(File file, String revision) throws IOException {
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add(BLAME);
// to get correctly formed changeset IDs
cmd.add("-c");
cmd.add(ABBREV_BLAME);
if (revision != null) {
cmd.add(revision);
}
cmd.add(file.getName());
Executor exec = new Executor(cmd, file.getParentFile());
int status = exec.exec();
// File might have changed its location
if (status != 0) {
cmd.clear();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add(BLAME);
// to get correctly formed changeset IDs
cmd.add("-c");
cmd.add(ABBREV_BLAME);
if (revision != null) {
cmd.add(revision);
}
cmd.add("--");
cmd.add(findOriginalName(file.getAbsolutePath(), revision));
File directory = new File(directoryName);
exec = new Executor(cmd, directory);
status = exec.exec();
}
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed to get annotations for: \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status) });
}
return parseAnnotation(newLogReader(exec.getOutputStream()), file.getName());
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class GitRepository 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("config");
cmd.add("--list");
Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
if (executor.getOutputString().contains("remote.origin.url=")) {
cmd.clear();
cmd.add(RepoCommand);
cmd.add("pull");
cmd.add("-n");
cmd.add("-q");
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class BazaarRepository method determineParent.
@Override
String determineParent() throws IOException {
File directory = new File(directoryName);
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("config");
cmd.add("parent_location");
Executor executor = new Executor(cmd, directory);
if (executor.exec(false) != 0) {
throw new IOException(executor.getErrorString());
}
return executor.getOutputString().trim();
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class BazaarRepository 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
* @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, final String sinceRevision) throws IOException {
String abs = file.getCanonicalPath();
String filename = "";
if (abs.length() > directoryName.length()) {
filename = abs.substring(directoryName.length() + 1);
}
List<String> cmd = new ArrayList<String>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("log");
if (file.isDirectory()) {
cmd.add("-v");
}
cmd.add(filename);
if (sinceRevision != null) {
cmd.add("-r");
cmd.add(sinceRevision + "..-1");
}
return new Executor(cmd, new File(getDirectoryName()), sinceRevision != null);
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class BazaarRepository method annotate.
/**
* Annotate the specified file/revision.
*
* @param file file to annotate
* @param revision revision to annotate
* @return file annotation
* @throws java.io.IOException
*/
@Override
public Annotation annotate(File file, String revision) throws IOException {
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("blame");
cmd.add("--all");
cmd.add("--long");
if (revision != null) {
cmd.add("-r");
cmd.add(revision);
}
cmd.add(file.getName());
Executor exec = new Executor(cmd, file.getParentFile());
int status = exec.exec();
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed to get annotations for: \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status) });
}
return parseAnnotation(exec.getOutputReader(), file.getName());
}
Aggregations