Search in sources :

Example 6 with PackageException

use of org.expath.pkg.repo.PackageException 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 PackageException

use of org.expath.pkg.repo.PackageException in project exist by eXist-db.

the class AutoDeploymentTrigger method execute.

@Override
public void execute(final DBBroker sysBroker, final Txn transaction, final Map<String, List<? extends Object>> params) {
    final boolean ignoreAutodeploySystemProperty = Optional.ofNullable(getFirstParamValue(params, IGNORE_AUTODEPLOY_SYSTEM_PROPERTY_PARAM, v -> Boolean.valueOf(v.toString()))).orElse(false);
    if (!ignoreAutodeploySystemProperty) {
        // do not execute if the system property exist.autodeploy=off
        final String property = System.getProperty(AUTODEPLOY_PROPERTY, "on");
        if (property.equalsIgnoreCase("off")) {
            return;
        }
    }
    Path autodeployDir = Optional.ofNullable(System.getProperty(AUTODEPLOY_DIRECTORY_PROPERTY)).map(Paths::get).orElse(null);
    if (autodeployDir == null) {
        final String dir = getFirstParamValue(params, AUTODEPLOY_DIRECTORY_PARAM, Object::toString);
        if (dir != null) {
            autodeployDir = Paths.get(dir);
        } else {
            final Optional<Path> homeDir = sysBroker.getConfiguration().getExistHome();
            autodeployDir = FileUtils.resolve(homeDir, AUTODEPLOY_DIRECTORY);
        }
    }
    if (!Files.isReadable(autodeployDir) && Files.isDirectory(autodeployDir)) {
        LOG.warn("Unable to read autodeploy directory: {}", autodeployDir);
        return;
    }
    try (Stream<Path> xarsStream = Files.find(autodeployDir, 1, (path, attrs) -> (!attrs.isDirectory()) && FileUtils.fileName(path).endsWith(".xar")).sorted(Comparator.comparing(Path::getFileName))) {
        final List<Path> xars = xarsStream.collect(Collectors.toList());
        LOG.info("Scanning autodeploy directory. Found {} app packages.", xars.size());
        final Deployment deployment = new Deployment();
        // build a map with uri -> file so we can resolve dependencies
        final Map<String, Path> packages = new HashMap<>();
        for (final Path xar : xars) {
            try {
                final Optional<String> name = deployment.getNameFromDescriptor(sysBroker, new XarFileSource(xar));
                if (name.isPresent()) {
                    packages.put(name.get(), xar);
                } else {
                    LOG.error("No descriptor name for: {}", xar.toAbsolutePath().toString());
                }
            } catch (final IOException | PackageException e) {
                LOG.error("Caught exception while reading app package {}", xar.toAbsolutePath().toString(), e);
            }
        }
        final PackageLoader loader = (name, version) -> {
            // TODO: enforce version check
            final Path p = packages.get(name);
            if (p == null) {
                return null;
            }
            return new XarFileSource(p);
        };
        for (final Path xar : xars) {
            try {
                deployment.installAndDeploy(sysBroker, transaction, new XarFileSource(xar), loader, false);
            } catch (final PackageException | IOException e) {
                LOG.error("Exception during deployment of app {}: {}", FileUtils.fileName(xar), e.getMessage(), e);
                sysBroker.getBrokerPool().reportStatus("An error occurred during app deployment: " + e.getMessage());
            }
        }
    } catch (final IOException ioe) {
        LOG.error(ioe);
    }
}
Also used : Path(java.nio.file.Path) Txn(org.exist.storage.txn.Txn) Files(java.nio.file.Files) StartupTrigger(org.exist.storage.StartupTrigger) IOException(java.io.IOException) HashMap(java.util.HashMap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) FileUtils(org.exist.util.FileUtils) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) PackageException(org.expath.pkg.repo.PackageException) Paths(java.nio.file.Paths) DBBroker(org.exist.storage.DBBroker) Map(java.util.Map) XarFileSource(org.expath.pkg.repo.XarFileSource) Optional(java.util.Optional) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) XarFileSource(org.expath.pkg.repo.XarFileSource) HashMap(java.util.HashMap) IOException(java.io.IOException) PackageException(org.expath.pkg.repo.PackageException)

Example 8 with PackageException

use of org.expath.pkg.repo.PackageException in project exist by eXist-db.

the class ExistPkgExtension method setupPackage.

// TODO: Must not be here (in the parsing class).  See the comment at the
// end of parseDescriptor().
private void setupPackage(Package pkg, ExistPkgInfo info) throws PackageException {
    // TODO: FIXME: Bad, BAD design!  But will be resolved naturally by moving the
    // install code within the storage class (because we are writing on disk)...
    final FileSystemResolver res = (FileSystemResolver) pkg.getResolver();
    final Path classpath = res.resolveResourceAsFile(".exist/classpath.txt");
    // create [pkg_dir]/.exist/classpath.txt if not already
    final Path exist = classpath.getParent();
    if (!Files.exists(exist)) {
        try {
            Files.createDirectories(exist);
        } catch (final IOException e) {
            throw new PackageException("Impossible to create directory: " + exist);
        }
    }
    final Set<String> jars = info.getJars();
    try (final Writer out = Files.newBufferedWriter(classpath)) {
        for (final String jar : jars) {
            StreamSource jar_src;
            try {
                jar_src = res.resolveComponent(jar);
            } catch (final NotExistException ex) {
                final String msg = "Inconsistent package descriptor, the JAR file is not in the package: ";
                throw new PackageException(msg + jar, ex);
            }
            final URI uri = URI.create(jar_src.getSystemId());
            final Path file = Paths.get(uri);
            out.write(file.normalize().toString());
            out.write("\n");
        }
    } catch (final IOException ex) {
        throw new PackageException("Error writing the eXist classpath file: " + classpath, ex);
    }
}
Also used : Path(java.nio.file.Path) StreamSource(javax.xml.transform.stream.StreamSource) PackageException(org.expath.pkg.repo.PackageException) NotExistException(org.expath.pkg.repo.Storage.NotExistException) IOException(java.io.IOException) URI(java.net.URI) Writer(java.io.Writer) FileSystemResolver(org.expath.pkg.repo.FileSystemStorage.FileSystemResolver)

Example 9 with PackageException

use of org.expath.pkg.repo.PackageException in project exist by eXist-db.

the class ExistPkgExtension method handleXQuery.

private void handleXQuery(XMLStreamReader parser, Package pkg, ExistPkgInfo info) throws PackageException, XMLStreamException {
    if (!myXSHelper.isNextElement(parser, "import-uri")) {
        myXSHelper.ensureElement(parser, "namespace");
    }
    final String href = myXSHelper.getElementValue(parser);
    myXSHelper.ensureNextElement(parser, "file");
    final String file = myXSHelper.getElementValue(parser);
    // position to </xquery>
    parser.next();
    try {
        info.addXQuery(new URI(href), file);
    } catch (final URISyntaxException ex) {
        throw new PackageException("Invalid URI: " + href, ex);
    }
}
Also used : PackageException(org.expath.pkg.repo.PackageException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 10 with PackageException

use of org.expath.pkg.repo.PackageException in project exist by eXist-db.

the class ExistPkgExtension method handleJava.

private void handleJava(XMLStreamReader parser, ExistPkgInfo info) throws PackageException, XMLStreamException {
    myXSHelper.ensureNextElement(parser, "namespace");
    final String href = myXSHelper.getElementValue(parser);
    myXSHelper.ensureNextElement(parser, "class");
    final String clazz = myXSHelper.getElementValue(parser);
    // position to </java>
    parser.next();
    try {
        info.addJava(new URI(href), clazz);
    } catch (final URISyntaxException ex) {
        throw new PackageException("Invalid URI: " + href, ex);
    }
}
Also used : PackageException(org.expath.pkg.repo.PackageException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

PackageException (org.expath.pkg.repo.PackageException)12 IOException (java.io.IOException)6 URI (java.net.URI)3 Deployment (org.exist.repo.Deployment)3 ExistRepository (org.exist.repo.ExistRepository)3 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 StreamSource (javax.xml.transform.stream.StreamSource)2 Txn (org.exist.storage.txn.Txn)2 XPathException (org.exist.xquery.XPathException)2 Package (org.expath.pkg.repo.Package)2 Packages (org.expath.pkg.repo.Packages)2 NotExistException (org.expath.pkg.repo.Storage.NotExistException)2 XarSource (org.expath.pkg.repo.XarSource)2 Writer (java.io.Writer)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1