use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BazaarRepository method determineParent.
@Override
String determineParent(CommandTimeoutType cmdType) 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("parent_location");
Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
if (executor.exec(false) != 0) {
throw new IOException(executor.getErrorString());
}
return executor.getOutputString().trim();
}
use of org.opengrok.indexer.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 if I/O exception occurred
*/
@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 executor = new Executor(cmd, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
BazaarAnnotationParser parser = new BazaarAnnotationParser(file.getName());
int status = executor.exec(true, parser);
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed to get annotations for: \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status) });
throw new IOException(executor.getErrorString());
} else {
return parser.getAnnotation();
}
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class MercurialHistoryParser method parse.
/**
* Parse the history for the specified file or directory. If a changeset is
* specified, only return the history from the changeset right after the
* specified one.
*
* @param file the file or directory to get history for
* @param sinceRevision the changeset right before the first one to fetch, or
* {@code null} if all changesets should be fetched
* @param tillRevision end revision or {@code null}
* @param numCommits number of revisions to get
* @return history for the specified file or directory
* @throws HistoryException if an error happens when parsing the history
*/
History parse(File file, String sinceRevision, String tillRevision, Integer numCommits) throws HistoryException {
isDir = file.isDirectory();
try {
Executor executor = repository.getHistoryLogExecutor(file, sinceRevision, tillRevision, false, numCommits);
int status = executor.exec(true, this);
if (status != 0) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
}
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
}
// an exception.
if (sinceRevision != null) {
repository.removeAndVerifyOldestChangeset(entries, sinceRevision);
}
// See getHistoryLogExecutor() for explanation.
if (repository.isHandleRenamedFiles() && file.isFile() && tillRevision != null) {
removeChangesets(entries, tillRevision);
}
return new History(entries, renamedFiles);
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BitKeeperRepository method fileHasHistory.
/**
* Returns whether BitKeeper has history for a file.
*
* @return ret a boolean denoting whether it does or not
*/
@Override
public boolean fileHasHistory(File file) {
final File absolute = file.getAbsoluteFile();
final File directory = absolute.getParentFile();
final String basename = absolute.getName();
final ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("files");
argv.add(basename);
final Executor executor = new Executor(argv, directory);
if (executor.exec(true) != 0) {
LOGGER.log(Level.SEVERE, "Failed to check file: {0}", executor.getErrorString());
return false;
}
return executor.getOutputString().trim().equals(basename);
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BitKeeperRepository method getHistoryGet.
@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String revision) {
final File directory = new File(parent).getAbsoluteFile();
final List<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("get");
argv.add("-p");
if (revision != null) {
argv.add("-r" + revision);
}
argv.add(basename);
final Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
if (executor.exec(true) != 0) {
LOGGER.log(Level.SEVERE, "Failed to get history: {0}", executor.getErrorString());
return false;
}
try {
copyBytes(out::write, executor.getOutputStream());
return true;
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to get content for {0}", basename);
}
return false;
}
Aggregations