use of org.exist.repo.ExistRepository in project exist by eXist-db.
the class RemoveFunction method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Sequence removed = BooleanValue.TRUE;
boolean force = false;
UserInteractionStrategy interact = new BatchUserInteraction();
String pkg = args[0].getStringValue();
try {
Optional<ExistRepository> repo = getContext().getRepository();
if (repo.isPresent()) {
Repository parent_repo = repo.get().getParentRepo();
parent_repo.removePackage(pkg, force, interact);
repo.get().reportAction(ExistRepository.Action.UNINSTALL, pkg);
context.getBroker().getBrokerPool().getXQueryPool().clear();
} else {
throw new XPathException("expath repository not available");
}
} catch (PackageException | XPathException pe) {
return BooleanValue.FALSE;
// /TODO: _repo.removePackage seems to throw PackageException
// throw new XPathException("Problem removing package " + pkg + " in expath repository, check that eXist-db has access permissions to expath repository file directory ", pe);
}
return removed;
}
use of org.exist.repo.ExistRepository in project exist by eXist-db.
the class XQueryContext method resolveInEXPathRepository.
/**
* Resolve a Module from the EXPath Repository.
*
* @param namespace namespace URI
* @param prefix namespace prefix
*
* @return the module or null
*
* @throws XPathException if the namespace URI is invalid (XQST0046),
* if the module could not be loaded (XQST0059) or compiled (XPST0003)
*/
private Module resolveInEXPathRepository(final String namespace, final String prefix) throws XPathException {
// the repo and its eXist handler
final Optional<ExistRepository> repo = getRepository();
// try an internal module
if (repo.isPresent()) {
final Module jMod = repo.get().resolveJavaModule(namespace, this);
if (jMod != null) {
return jMod;
}
}
// try an eXist-specific module
Path resolved = null;
if (repo.isPresent()) {
resolved = repo.get().resolveXQueryModule(namespace);
// use the resolved file or return null
if (resolved == null) {
return null;
}
}
// build a module object from the file
final Source src = new FileSource(resolved, false);
return compileOrBorrowModule(prefix, namespace, "", src);
}
use of org.exist.repo.ExistRepository in project exist by eXist-db.
the class RestoreAppsTest method createAndInstallApp.
private void createAndInstallApp(String version, String repoDescriptor) throws IOException, PackageException, EXistException {
String descriptor = "<package xmlns=\"http://expath.org/ns/pkg\" name=\"http://existsolutions.com/apps/backup-test\"\n" + " abbrev=\"backup-test\" version=\"" + version + "\" spec=\"1.0\">\n" + " <title>Backup Test App</title>\n" + " <dependency processor=\"http://exist-db.org\" semver-min=\"5.0.0-RC8\"/>\n" + "</package>";
Path xarFile = temporaryFolder.newFile().toPath();
try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(xarFile, StandardOpenOption.WRITE))) {
ZipEntry entry = new ZipEntry("expath-pkg.xml");
zos.putNextEntry(entry);
byte[] bytes = descriptor.getBytes(StandardCharsets.UTF_8);
zos.write(bytes);
zos.closeEntry();
entry = new ZipEntry("repo.xml");
zos.putNextEntry(entry);
bytes = repoDescriptor.getBytes(StandardCharsets.UTF_8);
zos.write(bytes);
zos.closeEntry();
}
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
Optional<ExistRepository> repo = pool.getExpathRepo();
if (!repo.isPresent()) {
throw new EXistException("expath repository not available for test");
}
XarSource xar = new XarFileSource(xarFile);
Deployment deployment = new Deployment();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
deployment.installAndDeploy(broker, transaction, xar, null);
transaction.commit();
}
Packages pkgs = repo.get().getParentRepo().getPackages("http://existsolutions.com/apps/backup-test");
assertEquals(1, pkgs.packages().size());
}
use of org.exist.repo.ExistRepository in project exist by eXist-db.
the class RestoreAppsTest method removePackage.
private void removePackage(BrokerPool pool) throws PackageException {
Optional<ExistRepository> repo = pool.getExpathRepo();
Repository parent_repo = repo.get().getParentRepo();
parent_repo.removePackage("http://existsolutions.com/apps/backup-test", true, new BatchUserInteraction());
}
use of org.exist.repo.ExistRepository 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