Search in sources :

Example 1 with Packages

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

the class AppRestoreUtils method checkApps.

/**
 * Inspects the apps contained in the backup against installed apps in the database
 * and return a set of symbolic backup paths pointing to the collection of those
 * apps for which newer versions are installed within the database. The returned
 * paths may then be ignored during a restore.
 *
 * The method attempts to be fail safe to make sure even bad backups can be restored. Errors
 * reading package descriptors are thus only logged and should not abort the process.
 *
 * @param broker the broker used for reading the backup and retrieving the expath repo
 * @param descriptors a queue of backup descriptors to inspect
 * @return a set of paths for which newer versions exist in the database. may be empty.
 */
public static Set<String> checkApps(final DBBroker broker, final Deque<BackupDescriptor> descriptors) {
    final List<AppDetail> apps = getAppsFromBackup(broker, descriptors);
    final Set<String> paths = new HashSet<>();
    final Optional<ExistRepository> repo = broker.getBrokerPool().getExpathRepo();
    if (repo.isPresent()) {
        for (final AppDetail app : apps) {
            final Packages packages = repo.get().getParentRepo().getPackages(app.name);
            if (packages != null) {
                final Package latest = packages.latest();
                try {
                    final Semver version = Semver.parse(latest.getVersion());
                    if (version.compareTo(app.version) > 0) {
                        paths.add(app.path);
                    }
                } catch (PackageException e) {
                    LOG.warn("Invalid semver in expath repository for {}", app.name, e);
                }
            }
        }
    }
    return paths;
}
Also used : Packages(org.expath.pkg.repo.Packages) PackageException(org.expath.pkg.repo.PackageException) Package(org.expath.pkg.repo.Package) Semver(org.expath.pkg.repo.deps.Semver) ExistRepository(org.exist.repo.ExistRepository)

Example 2 with Packages

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

the class ListFunction method eval.

public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    ValueSequence result = new ValueSequence();
    Optional<ExistRepository> repo = getContext().getRepository();
    if (repo.isPresent()) {
        try {
            Repository parent_repo = repo.get().getParentRepo();
            for (Packages pkg : parent_repo.listPackages()) {
                String name = pkg.name();
                result.add(new StringValue(name));
            }
        } catch (Exception ex) {
            throw new XPathException("Problem listing packages in expath repository ", ex);
        }
        return result;
    } else {
        throw new XPathException("expath repository not available");
    }
}
Also used : Repository(org.expath.pkg.repo.Repository) ExistRepository(org.exist.repo.ExistRepository) XPathException(org.exist.xquery.XPathException) Packages(org.expath.pkg.repo.Packages) ValueSequence(org.exist.xquery.value.ValueSequence) StringValue(org.exist.xquery.value.StringValue) XPathException(org.exist.xquery.XPathException) ExistRepository(org.exist.repo.ExistRepository)

Example 3 with Packages

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

the class GetResource method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    String pkgName = args[0].getStringValue();
    String path = args[1].getStringValue();
    Optional<ExistRepository> repo = context.getRepository();
    if (repo.isPresent()) {
        try {
            for (Packages pp : repo.get().getParentRepo().listPackages()) {
                final Package pkg = pp.latest();
                if (pkg.getName().equals(pkgName)) {
                    try {
                        // FileSystemResolver already returns an input stream
                        StreamSource source = (StreamSource) pkg.getResolver().resolveResource(path);
                        return Base64BinaryDocument.getInstance(context, source.getInputStream());
                    } catch (Storage.NotExistException e) {
                        throw new XPathException(ErrorCodes.FODC0002, "Resource " + path + " does not exist.", e);
                    }
                }
            }
        } catch (PackageException e) {
            throw new XPathException(this, ErrorCodes.FOER0000, "Caught package error while reading expath package");
        }
    } else {
        throw new XPathException("expath repository not available");
    }
    return Sequence.EMPTY_SEQUENCE;
}
Also used : Storage(org.expath.pkg.repo.Storage) XPathException(org.exist.xquery.XPathException) Packages(org.expath.pkg.repo.Packages) StreamSource(javax.xml.transform.stream.StreamSource) PackageException(org.expath.pkg.repo.PackageException) Package(org.expath.pkg.repo.Package) ExistRepository(org.exist.repo.ExistRepository)

Example 4 with Packages

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

the class ClasspathHelper method scanPackages.

private static void scanPackages(BrokerPool pool, Classpath classpath) {
    try {
        final Optional<ExistRepository> repo = pool.getExpathRepo();
        if (repo.isPresent()) {
            for (final Packages pkgs : repo.get().getParentRepo().listPackages()) {
                final Package pkg = pkgs.latest();
                if (!isCompatible(pkg)) {
                    LOG.warn("Package {} is not compatible with this version of eXist. To avoid conflicts, Java libraries shipping with this package are not loaded.", pkg.getName());
                } else {
                    try {
                        final FileSystemStorage.FileSystemResolver resolver = (FileSystemStorage.FileSystemResolver) pkg.getResolver();
                        final Path packageDir = resolver.resolveResourceAsFile(".");
                        scanPackageDir(classpath, packageDir);
                    } catch (final IOException e) {
                        LOG.warn("An error occurred while updating classpath for package {}", pkg.getName(), e);
                    }
                }
            }
        }
    } catch (final Exception e) {
        LOG.warn("An error occurred while updating classpath for packages", e);
    }
}
Also used : Path(java.nio.file.Path) Packages(org.expath.pkg.repo.Packages) FileSystemStorage(org.expath.pkg.repo.FileSystemStorage) Package(org.expath.pkg.repo.Package) IOException(java.io.IOException) IOException(java.io.IOException) PackageException(org.expath.pkg.repo.PackageException)

Aggregations

Packages (org.expath.pkg.repo.Packages)4 ExistRepository (org.exist.repo.ExistRepository)3 Package (org.expath.pkg.repo.Package)3 PackageException (org.expath.pkg.repo.PackageException)3 XPathException (org.exist.xquery.XPathException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 StreamSource (javax.xml.transform.stream.StreamSource)1 StringValue (org.exist.xquery.value.StringValue)1 ValueSequence (org.exist.xquery.value.ValueSequence)1 FileSystemStorage (org.expath.pkg.repo.FileSystemStorage)1 Repository (org.expath.pkg.repo.Repository)1 Storage (org.expath.pkg.repo.Storage)1 Semver (org.expath.pkg.repo.deps.Semver)1