use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SubversionRepository method getInfoDocument.
/**
* Get {@code Document} corresponding to the parsed XML output from
* {@code svn info} command.
* @return document with data from {@code info} or null if the {@code svn}
* command failed
*/
private Document getInfoDocument() {
Document document = null;
List<String> cmd = new ArrayList<>();
cmd.add(RepoCommand);
cmd.add("info");
cmd.add(XML_OPTION);
File directory = new File(getDirectoryName());
Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
if (executor.exec() == 0) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Prohibit the use of all protocols by external entities:
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(executor.getOutputStream());
} catch (SAXException saxe) {
LOGGER.log(Level.WARNING, "Parser error parsing svn output", saxe);
} catch (ParserConfigurationException pce) {
LOGGER.log(Level.WARNING, "Parser configuration error parsing svn output", pce);
} catch (IOException ioe) {
LOGGER.log(Level.WARNING, "IOException reading from svn process", ioe);
}
} else {
LOGGER.log(Level.WARNING, "Failed to execute svn info for [{0}]. Repository disabled.", getDirectoryName());
}
return document;
}
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());
}
Aggregations