use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BitKeeperRepository method determineParent.
/**
* Return the first listed pull parent of this repository BitKeeper can have multiple push parents and pul parents.
*
* @return parent a string denoting the parent, or null.
*/
@Override
String determineParent(CommandTimeoutType cmdType) throws IOException {
final File directory = new File(getDirectoryName());
final ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("parent");
argv.add("-1il");
final Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
final int rc = executor.exec(false);
final String parent = executor.getOutputString().trim();
if (rc == 0) {
return parent;
} else if (parent.equals("This repository has no pull parent.")) {
return null;
} else {
throw new IOException(executor.getErrorString());
}
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BitKeeperRepository method ensureVersion.
/**
* Updates working and version member variables by running {@code bk --version}.
*/
private void ensureVersion() {
if (working == null) {
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
final Executor exec = new Executor(new String[] { RepoCommand, "--version" });
if (exec.exec(false) == 0) {
working = Boolean.TRUE;
final Matcher matcher = VERSION_PATTERN.matcher(exec.getOutputString());
if (matcher.find()) {
try {
version = new Version(matcher.group(1));
} catch (final InvalidVersionNumberException e) {
assert false : "Failed to parse a version number.";
}
}
} else {
working = Boolean.FALSE;
}
if (version == null) {
version = new Version(0, 0);
}
}
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevHistoryParser method parse.
/**
* Parse the history for the specified file.
*
* @param file the file to parse history for
* @param repos Pointer to the {@code AccuRevRepository}
* @return object representing the file's history
* @throws HistoryException if a problem occurs while executing p4 command
*/
History parse(File file, Repository repos) throws HistoryException {
repository = (AccuRevRepository) repos;
history = null;
String relPath = repository.getDepotRelativePath(file);
/*
* When the path given is really just the root to the source
* workarea, no history is available, create fake.
*/
String rootRelativePath = File.separator + "." + File.separator;
if (relPath.equals(rootRelativePath)) {
List<HistoryEntry> entries = new ArrayList<>();
entries.add(new HistoryEntry("", new Date(), "OpenGrok", "Workspace Root", true));
history = new History(entries);
} else {
try {
/*
* Errors will be logged, so not bothering to add to the output.
*/
Executor executor = repository.getHistoryLogExecutor(file);
executor.exec(true, this);
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"" + e);
}
}
return history;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class IndexerTest method testBug11896.
/**
* Test that named pipes are not indexed.
* @throws Exception
*/
@Test
@EnabledIf("mkfifoInPath")
void testBug11896() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setSourceRoot(repository.getSourceRoot());
env.setDataRoot(repository.getDataRoot());
Executor executor;
executor = new Executor(new String[] { "mkdir", "-p", repository.getSourceRoot() + "/testBug11896" });
executor.exec(true);
executor = new Executor(new String[] { "mkfifo", repository.getSourceRoot() + "/testBug11896/FIFO" });
executor.exec(true);
Project project = new Project("testBug11896");
project.setPath("/testBug11896");
IndexDatabase idb = new IndexDatabase(project);
assertNotNull(idb);
MyIndexChangeListener listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
System.out.println("Trying to index a special file - FIFO in this case.");
idb.update();
assertEquals(0, listener.files.size());
}
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;
}
Aggregations