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;
}
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");
}
}
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;
}
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);
}
}
Aggregations