in vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java [428:588]
public void run(Archive archive, Session session, String parentPath)
throws IOException, RepositoryException, ConfigurationException {
this.archive = archive;
// init tracker
if (opts.getListener() == null) {
tracker = null;
} else {
if (tracker == null) {
tracker = new ProgressTracker();
}
tracker.setListener(opts.getListener());
}
// check format version
int version = archive.getMetaInf().getPackageFormatVersion();
if (version > MetaInf.FORMAT_VERSION_2) {
String msg = "Content format version not supported (" + version + " > " + MetaInf.FORMAT_VERSION_2 + ")";
log.warn(msg);
throw new IOException(msg);
}
// init autosave
if (opts.getAutoSaveThreshold() >= 0) {
autoSave.setThreshold(opts.getAutoSaveThreshold());
}
autoSave.setDryRun(opts.isDryRun());
autoSave.setTracker(tracker);
// enable this to test auto-recovery of batch saves
// autoSave.setDebugFailEach(1);
// autoSave.setThreshold(4);
// propagate access control handling
if (opts.getAccessControlHandling() == null) {
opts.setAccessControlHandling(AccessControlHandling.IGNORE);
}
fileHandler.setAcHandling(opts.getAccessControlHandling());
fileHandler.setCugHandling(opts.getCugHandling());
genericHandler.setAcHandling(opts.getAccessControlHandling());
genericHandler.setCugHandling(opts.getCugHandling());
folderHandler.setAcHandling(opts.getAccessControlHandling());
folderHandler.setCugHandling(opts.getCugHandling());
folderHandler.setOverwritePrimaryTypesOfFolders(opts.overwritePrimaryTypesOfFolders(overwritePrimaryTypesOfFoldersByDefault));
filter = opts.getFilter();
if (filter == null) {
filter = archive.getMetaInf().getFilter();
}
if (filter == null) {
filter = new DefaultWorkspaceFilter();
}
// check path remapping
PathMapping pathMapping = opts.getPathMapping();
if (pathMapping != null) {
filter = filter.translate(pathMapping);
this.archive = archive = new MappedArchive(archive, pathMapping);
this.archive.open(true);
}
// set import mode if possible
if (opts.getImportMode() != null) {
if (filter instanceof DefaultWorkspaceFilter) {
((DefaultWorkspaceFilter) filter).setImportMode(opts.getImportMode());
} else {
log.warn("Unable to override import mode, incompatible filter: {}", filter.getClass().getName());
}
}
// build filter tree
for (PathFilterSet set: filter.getFilterSets()) {
filterTree.put(set.getRoot(), set);
}
if ("/".equals(parentPath)) {
parentPath = "";
}
track("Collecting import information...", "");
TxInfo root = prepare(archive.getJcrRoot(), parentPath, new SessionNamespaceResolver(session));
if (filter!=null && filter.getFilterSets() != null && filter.getFilterSets().size() > 0 ) {
root = postFilter(root);
}
log.debug("Access control handling set to {}", opts.getAccessControlHandling());
log.debug("CUG handling set to {}", opts.getCugHandling());
if (opts.isDryRun()) {
track("Dry Run: Skipping node types installation (might lead to errors).", "");
track("Simulating content import...", "");
} else {
track("Installing node types...", "");
installNodeTypes(session);
track("Installing privileges...", "");
registerPrivileges(session);
log.debug("Starting content import. autosave is {}", autoSave);
track("Importing content...", "");
if (tracker != null) {
tracker.setMode(ProgressTrackerListener.Mode.PATHS);
}
}
cpAutosave = autoSave.copy();
LinkedList<TxInfo> skipList = new LinkedList<>();
while (recoveryRetryCounter++ < 10) {
try {
commit(session, root, skipList);
autoSave.save(session, false);
break;
} catch (RepositoryException e) {
if (autoSave.isDisabled() || recoveryRetryCounter == 10) {
log.error("Error while committing changes. Aborting.");
throw e;
} else {
log.warn("Error while committing changes: Retrying import from checkpoint at {}. Retries {}/10. {}",
cpTxInfo == null ? "/" : cpTxInfo.path, recoveryRetryCounter, getExtendedThrowableMessage(e));
autoSave = cpAutosave.copy();
// build skip list
skipList.clear();
TxInfo info = cpTxInfo;
while (info != null && info.parent != null) {
skipList.addFirst(info);
info = info.parent;
}
// reset any intermediate changes in this run
intermediates.putAll(removedIntermediates);
for (TxInfo i: removedIntermediates.values()) {
i.isIntermediate = 1;
}
removedIntermediates.clear();
processedInfos.clear();
session.refresh(false);
}
}
}
if (tracker != null) {
tracker.setMode(ProgressTrackerListener.Mode.TEXT);
}
restorePrincipalAcls(session, shouldStashPrincipalPoliciesForArchive(archive));
checkinNodes(session);
applyMemberships(session);
applyPatches();
if (opts.isDryRun()) {
if (hasErrors) {
track("Package import simulation finished. (with errors, check logs!)", "");
log.error("There were errors during package install simulation. Please check the logs for details.");
track("First error was " + getExtendedThrowableMessage(firstException), "");
} else {
track("Package import simulation finished.", "");
}
} else {
if (hasErrors) {
track("Package imported (with errors, check logs!)", "");
if (isStrict) {
throw new RepositoryException("Some errors occurred while installing packages. Please check the logs for details. First exception is logged as cause.", firstException);
}
log.error("There were errors during package install. Please check the logs for details.");
track("First error was " + getExtendedThrowableMessage(firstException), "");
} else {
track("Package imported.", "");
}
}
}