use of org.exist.repo.ExistPkgInfo in project exist by eXist-db.
the class InstallFunction method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Sequence removed = BooleanValue.FALSE;
boolean force = true;
UserInteractionStrategy interact = new BatchUserInteraction();
String pkgOrPath = args[0].getStringValue();
Optional<ExistRepository> repo = getContext().getRepository();
try {
if (repo.isPresent()) {
Repository parent_repo = repo.get().getParentRepo();
Package pkg;
if (isCalledAs("install")) {
// download .xar from a URI
URI uri = _getURI(pkgOrPath);
pkg = parent_repo.installPackage(uri, force, interact);
repo.get().reportAction(ExistRepository.Action.INSTALL, pkg.getName());
} else {
// .xar is stored as a binary resource
try (final LockedDocument lockedDoc = getBinaryDoc(pkgOrPath);
final Txn transaction = context.getBroker().continueOrBeginTransaction()) {
final DocumentImpl doc = lockedDoc.getDocument();
LOG.debug("Installing file: {}", doc.getURI());
pkg = parent_repo.installPackage(new BinaryDocumentXarSource(context.getBroker().getBrokerPool(), transaction, (BinaryDocument) doc), force, interact);
repo.get().reportAction(ExistRepository.Action.INSTALL, pkg.getName());
transaction.commit();
}
}
ExistPkgInfo info = (ExistPkgInfo) pkg.getInfo("exist");
if (info != null && !info.getJars().isEmpty())
ClasspathHelper.updateClasspath(context.getBroker().getBrokerPool(), pkg);
// TODO: expath libs do not provide a way to see if there were any XQuery modules installed at all
context.getBroker().getBrokerPool().getXQueryPool().clear();
removed = BooleanValue.TRUE;
} else {
throw new XPathException("expath repository not available");
}
} catch (PackageException | TransactionException ex) {
logger.error(ex.getMessage(), ex);
return removed;
// /TODO: _repo.removePackage seems to throw PackageException
// throw new XPathException("Problem installing package " + pkg + " in expath repository, check that eXist-db has access permissions to expath repository file directory ", ex);
} catch (XPathException xpe) {
logger.error(xpe.getMessage());
return removed;
}
return removed;
}
Aggregations