if (this.getDefinition().getBoolean(JcrPackageDefinition.PN_DISABLE_INTERMEDIATE_SAVE) ) {
// MAX_VALUE disables saving completely, therefore we have to use a lower value!
opts.setAutoSaveThreshold(Integer.MAX_VALUE - 1);
}
InstallContextImpl ctx = pack.prepareExtract(node.getSession(), opts);
JcrPackage snap = null;
if (!opts.isDryRun() && createSnapshot) {
ExportOptions eOpts = new ExportOptions();
eOpts.setListener(opts.getListener());
snap = snapshot(eOpts, replaceSnapshot, opts.getAccessControlHandling());
}
List<String> subPackages = new ArrayList<String>();
pack.extract(ctx, subPackages);
getDefinition();
if (def != null && !opts.isDryRun()) {
def.touchLastUnpacked(null, true);
}
// process sub packages
Session s = node.getSession();
List<JcrPackageImpl> subPacks = new LinkedList<JcrPackageImpl>();
for (String path: subPackages) {
if (s.nodeExists(path)) {
JcrPackageImpl p = new JcrPackageImpl(s.getNode(path));
if (!p.isValid()) {
// check if package was included as pure .zip or .jar
try {
p.tryUnwrap();
} catch (Exception e) {
log.info("Sub package {} not valid: " + e, path);
}
}
if (p.isValid()) {
subPacks.add(p);
}
}
}
// don't extract sub packages if not recursive
if (!opts.isNonRecursive() && !subPacks.isEmpty()) {
try {
DependencyUtil.sortPackages(subPacks);
} catch (CyclicDependencyException e) {
if (opts.isStrict()) {
throw e;
}
}
List<String> subIds = new LinkedList<String>();
SubPackageHandling sb = pack.getSubPackageHandling();
for (JcrPackageImpl p: subPacks) {
boolean skip = false;
PackageId id = p.getPackage().getId();
SubPackageHandling.Option option = sb.getOption(id);
String msg;
if (option == SubPackageHandling.Option.ADD || option == SubPackageHandling.Option.IGNORE) {
msg = "skipping installation of subpackage " + id + " due to option " + option;
skip = true;
} else if (option == SubPackageHandling.Option.INSTALL) {
msg = "Starting installation of subpackage " + id;
} else {
msg = "Starting extraction of subpackage " + id;
}
if (options.isDryRun()) {
msg = "Dry run: " + msg;
}
if (options.getListener() != null) {
options.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, msg, "");
} else {
log.info(msg);
}
if (!skip) {
if (createSnapshot && option == SubPackageHandling.Option.INSTALL) {
p.extract(options, true, true);
subIds.add(id.toString());
} else {
p.extract(options, false, true);
}
}
p.close();
}
// register sub packages in snapshot for uninstall
if (snap != null) {
snap.getDefinition().getNode().setProperty(JcrPackageDefinition.PN_SUB_PACKAGES, subIds.toArray(new String[subIds.size()]));
snap.getDefinition().getNode().save();
}
}
}