in vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageImpl.java [753:817]
private void installDependencies(Set<PackageId> processed, ImportOptions opts, boolean createSnapshot, boolean replaceSnapshot)
throws PackageException, RepositoryException, IOException {
if (def == null) {
return;
}
List<Dependency> unresolved = new LinkedList<>();
List<RegisteredPackage> uninstalled = new LinkedList<>();
try {
for (Dependency dep: def.getDependencies()) {
// resolve to installed and uninstalled packages
PackageId id = mgr.resolve(dep, false);
if (id == null) {
unresolved.add(dep);
} else {
RegisteredPackage pack = mgr.open(id);
if (pack != null) {
if (!pack.isInstalled()) {
unresolved.add(dep);
uninstalled.add(pack);
} else {
pack.close();
}
}
}
}
// if non unresolved, then we're good
if (unresolved.isEmpty()) {
return;
}
// if the package is not installed at all, abort for required and strict handling
if ((opts.getDependencyHandling() == DependencyHandling.STRICT && unresolved.size() > 0)
|| (opts.getDependencyHandling() == DependencyHandling.REQUIRED && unresolved.size() > uninstalled.size())) {
String msg = String.format(Locale.ENGLISH, "Refusing to install package %s: required dependencies missing: %s", def.getId(), unresolved);
log.error(msg);
throw new DependencyException(msg);
}
for (RegisteredPackage pack: uninstalled) {
if (pack.isInstalled()) {
continue;
}
PackageId packageId = pack.getId();
if (processed.contains(packageId)) {
if (opts.getDependencyHandling() == DependencyHandling.BEST_EFFORT) {
continue;
}
String msg = String.format(Locale.ENGLISH, "Unable to install package %s. dependency has as cycling reference to %s", def.getId(), packageId);
log.error(msg);
throw new CyclicDependencyException(msg);
}
if (pack instanceof JcrRegisteredPackage) {
JcrPackage jcrPackage = ((JcrRegisteredPackage)pack).getJcrPackage();
((JcrPackageImpl)jcrPackage).extract(processed, opts, createSnapshot, replaceSnapshot);
} else {
String msg = String.format(Locale.ENGLISH, "Unable to install package %s. dependency not found in JcrPackageRegistry %s", def.getId(), packageId);
log.error(msg);
throw new DependencyException(msg);
}
}
} finally {
for (RegisteredPackage pack: uninstalled) {
pack.close();
}
}
}