use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SubversionRepository method getHistoryGet.
@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
File directory = new File(getDirectoryName());
String filepath;
try {
filepath = (new File(parent, basename)).getCanonicalPath();
} catch (IOException exp) {
LOGGER.log(Level.SEVERE, "Failed to get canonical path: {0}", exp.getClass().toString());
return false;
}
String filename = filepath.substring(getDirectoryName().length() + 1);
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("cat");
cmd.add(NON_INTERACT_OPTION);
cmd.addAll(getAuthCommandLineParams());
cmd.add("-r");
cmd.add(rev);
cmd.add(escapeFileName(filename));
Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
if (executor.exec() == 0) {
try {
copyBytes(out::write, executor.getOutputStream());
return true;
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to get content for {0}", basename);
}
}
return false;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SubversionRepository 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 revision number immediately preceding the first
* revision we want, or {@code null} to fetch the entire
* history
* @param numEntries number of entries to return. If 0, return all.
* @param cmdType command timeout type
* @return An Executor ready to be started
*/
Executor getHistoryLogExecutor(final File file, String sinceRevision, int numEntries, CommandTimeoutType cmdType) throws IOException {
String filename = getRepoRelativePath(file);
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("log");
cmd.add(NON_INTERACT_OPTION);
cmd.addAll(getAuthCommandLineParams());
cmd.add(XML_OPTION);
cmd.add("-v");
if (numEntries > 0) {
cmd.add("-l" + numEntries);
}
if (sinceRevision != null) {
cmd.add("-r");
// We would like to use sinceRevision+1 here, but if no new
// revisions have been added after sinceRevision, it would fail
// because there is no such revision as sinceRevision+1. Instead,
// fetch the unneeded revision and remove it later.
cmd.add("BASE:" + sinceRevision);
}
if (filename.length() > 0) {
cmd.add(escapeFileName(filename));
}
return new Executor(cmd, new File(getDirectoryName()), RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SCCSget method getRevision.
public static InputStream getRevision(String command, File file, String revision) throws IOException {
InputStream ret = null;
ArrayList<String> argv = new ArrayList<>();
argv.add(command);
argv.add("get");
argv.add("-p");
if (revision != null) {
argv.add("-r" + revision);
}
argv.add(file.getCanonicalPath());
Executor executor = new Executor(argv);
if (executor.exec() == 0) {
ret = executor.getOutputStream();
}
return ret;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SSCMRepository method annotate.
/**
* Annotate the specified file/revision.
*
* @param file file to annotate
* @param revision revision to annotate
* @return file annotation
*/
@Override
Annotation annotate(File file, String revision) throws IOException {
ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("annotate");
argv.add(file.getName());
Properties props = getProperties(file);
String branch = props.getProperty(BRANCH_PROPERTY);
if (branch != null && !branch.isEmpty()) {
argv.add("-b" + branch);
}
String repo = props.getProperty(REPOSITORY_PROPERTY);
if (repo != null && !repo.isEmpty()) {
argv.add("-p" + repo);
}
if (revision != null) {
argv.add("-aV:" + revision);
}
Executor exec = new Executor(argv, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
int status = exec.exec();
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed annotate for: {2} \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status), revision });
}
return parseAnnotation(exec.getOutputReader(), file.getName());
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SCCSRepository 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 occurs
*/
@Override
public Annotation annotate(File file, String revision) throws IOException {
Map<String, String> authors = getAuthors(file);
ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("get");
argv.add("-m");
argv.add("-p");
if (revision != null) {
argv.add("-r" + revision);
}
argv.add(file.getCanonicalPath());
Executor executor = new Executor(argv, file.getCanonicalFile().getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
SCCSRepositoryAnnotationParser parser = new SCCSRepositoryAnnotationParser(file, authors);
executor.exec(true, parser);
return parser.getAnnotation();
}
Aggregations