use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class CVSRepository method annotate.
@Override
Annotation annotate(File file, String revision) throws IOException {
ArrayList<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("annotate");
if (revision != null) {
cmd.add("-r");
cmd.add(revision);
} else if (getBranch() != null && !getBranch().isEmpty()) {
cmd.add("-r");
cmd.add(getBranch());
}
cmd.add(file.getName());
Executor exec = new Executor(cmd, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
CVSAnnotationParser parser = new CVSAnnotationParser(file.getName());
int status = exec.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) });
}
return parser.getAnnotation();
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class CVSRepository 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
* @return An Executor ready to be started
*/
Executor getHistoryLogExecutor(final File file) throws IOException {
String filename = getRepoRelativePath(file);
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("log");
if (getBranch() != null && !getBranch().isEmpty()) {
// Generate history on this branch and follow up to the origin.
cmd.add("-r1.1:" + branch);
} else {
// Get revisions on this branch only (otherwise the revisions
// list produced by the cvs log command would be unsorted).
cmd.add("-b");
}
if (filename.length() > 0) {
cmd.add(filename);
}
return new Executor(cmd, new File(getDirectoryName()));
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class CVSRepository method getHistoryGet.
@Override
public InputStream getHistoryGet(String parent, String basename, String rev) {
InputStream ret = null;
String revision = rev;
if (rev.indexOf(':') != -1) {
revision = rev.substring(0, rev.indexOf(':'));
}
try {
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
String[] argv = { RepoCommand, "up", "-p", "-r", revision, basename };
Executor executor = new Executor(Arrays.asList(argv), new File(parent), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
executor.exec();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[32 * 1024];
try (InputStream in = executor.getOutputStream()) {
int len;
while ((len = in.read(buffer)) != -1) {
if (len > 0) {
out.write(buffer, 0, len);
}
}
}
ret = new ByteArrayInputStream(out.toByteArray());
} catch (Exception exp) {
LOGGER.log(Level.WARNING, "Failed to get history", exp);
}
return ret;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class ClearCaseHistoryParser method parse.
History parse(File file, Repository repos) throws HistoryException {
repository = (ClearCaseRepository) repos;
try {
Executor executor = repository.getHistoryLogExecutor(file);
int status = executor.exec(true, this);
if (status != 0) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
}
return history;
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
}
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevRepository method getHistoryGet.
@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
ArrayList<String> cmd = new ArrayList<>();
File directory = new File(parent);
/*
* Only way to guarantee getting the contents of a file is to fire off
* an AccuRev 'stat'us command to get the element ID number for the
* subsequent 'cat' command. (Element ID's are unique for a file, unless
* evil twins are present) This is because it is possible that the file
* may have been moved to a different place in the depot. The 'stat'
* command will produce a line with the format:
*
* <filePath> <elementID> <virtualVersion> (<realVersion>) (<status>)
*
* /./myFile e:17715 CP.73_Depot/2 (3220/2) (backed)
*/
cmd.add(RepoCommand);
cmd.add("stat");
cmd.add("-fe");
cmd.add(basename);
Executor executor = new Executor(cmd, directory);
executor.exec();
String elementID = null;
try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
String line = info.readLine();
String[] statInfo = line.split("\\s+");
// skip over 'e:'
elementID = statInfo[1].substring(2);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not obtain status for {0}", basename);
}
if (elementID != null) {
/*
* This really gets the contents of the file.
*/
cmd.clear();
cmd.add(RepoCommand);
cmd.add("cat");
cmd.add("-v");
cmd.add(rev.trim());
cmd.add("-e");
cmd.add(elementID);
executor = new Executor(cmd, directory);
executor.exec();
try {
copyBytes(out::write, executor.getOutputStream());
return true;
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to obtain content for {0}", basename);
}
}
return false;
}
Aggregations