Search in sources :

Example 6 with ExistRepository

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;
}
Also used : Repository(org.expath.pkg.repo.Repository) ExistRepository(org.exist.repo.ExistRepository) UserInteractionStrategy(org.expath.pkg.repo.UserInteractionStrategy) XPathException(org.exist.xquery.XPathException) PackageException(org.expath.pkg.repo.PackageException) BatchUserInteraction(org.expath.pkg.repo.tui.BatchUserInteraction) ExistRepository(org.exist.repo.ExistRepository)

Example 7 with ExistRepository

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);
}
Also used : Path(java.nio.file.Path) ExistRepository(org.exist.repo.ExistRepository)

Example 8 with ExistRepository

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());
}
Also used : Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Deployment(org.exist.repo.Deployment) EXistException(org.exist.EXistException) Txn(org.exist.storage.txn.Txn) DBBroker(org.exist.storage.DBBroker) ZipOutputStream(java.util.zip.ZipOutputStream) BrokerPool(org.exist.storage.BrokerPool) ExistRepository(org.exist.repo.ExistRepository)

Example 9 with ExistRepository

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());
}
Also used : ExistRepository(org.exist.repo.ExistRepository) BatchUserInteraction(org.expath.pkg.repo.tui.BatchUserInteraction) ExistRepository(org.exist.repo.ExistRepository)

Example 10 with ExistRepository

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;
}
Also used : XPathException(org.exist.xquery.XPathException) Sequence(org.exist.xquery.value.Sequence) Txn(org.exist.storage.txn.Txn) XmldbURI(org.exist.xmldb.XmldbURI) URI(java.net.URI) DocumentImpl(org.exist.dom.persistent.DocumentImpl) ExistPkgInfo(org.exist.repo.ExistPkgInfo) ExistRepository(org.exist.repo.ExistRepository) TransactionException(org.exist.storage.txn.TransactionException) LockedDocument(org.exist.dom.persistent.LockedDocument) Package(org.expath.pkg.repo.Package) BatchUserInteraction(org.expath.pkg.repo.tui.BatchUserInteraction) ExistRepository(org.exist.repo.ExistRepository)

Aggregations

ExistRepository (org.exist.repo.ExistRepository)11 XPathException (org.exist.xquery.XPathException)5 EXistException (org.exist.EXistException)4 Path (java.nio.file.Path)3 BrokerPool (org.exist.storage.BrokerPool)3 PackageException (org.expath.pkg.repo.PackageException)3 Packages (org.expath.pkg.repo.Packages)3 Txn (org.exist.storage.txn.Txn)2 XQuery (org.exist.xquery.XQuery)2 Package (org.expath.pkg.repo.Package)2 Repository (org.expath.pkg.repo.Repository)2 BatchUserInteraction (org.expath.pkg.repo.tui.BatchUserInteraction)2 AtomicFSM (com.evolvedbinary.j8fu.fsm.AtomicFSM)1 FSM (com.evolvedbinary.j8fu.fsm.FSM)1 TransitionTable.transitionTable (com.evolvedbinary.j8fu.fsm.TransitionTable.transitionTable)1 AtomicLazyVal (com.evolvedbinary.j8fu.lazy.AtomicLazyVal)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Reference (java.lang.ref.Reference)1