in src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoader.java [260:360]
private List<String> installContent(final Session defaultSession, final Bundle bundle,
final Iterator<PathEntry> pathIter, final boolean contentAlreadyLoaded) throws RepositoryException, ContentReaderUnavailableException {
final List<String> createdNodes = new ArrayList<>();
final Map<String, Session> createdSessions = new HashMap<>();
log.debug("Installing initial content from bundle {}", bundle.getSymbolicName());
final DefaultContentCreator contentCreator = new DefaultContentCreator(this.bundleHelper);
try {
while (pathIter.hasNext()) {
final PathEntry pathEntry = pathIter.next();
boolean skip = false;
if (!pathFilter.test(pathEntry.getTarget())) {
log.debug("Path {} excluded by configuration", pathEntry.getPath());
skip = true;
}
if (pathEntry.isOverwrite() && (pathEntry.getTarget() == null || "/".equals(pathEntry.getTarget()))) {
log.error("Path {} tries to overwrite on the repository root level which is not allowed, only use overwrite with a dedicated path directive having any value but '/'", pathEntry.getPath());
skip = true;
}
if (skip) {
continue;
}
if (!contentAlreadyLoaded || pathEntry.isOverwrite()) {
String workspace = pathEntry.getWorkspace();
final Session targetSession;
if (workspace != null) {
if (createdSessions.containsKey(workspace)) {
targetSession = createdSessions.get(workspace);
} else {
targetSession = createSession(workspace);
createdSessions.put(workspace, targetSession);
}
} else {
targetSession = defaultSession;
}
final Node targetNode = getTargetNode(targetSession, pathEntry.getTarget(), pathEntry.isOverwrite());
if (targetNode != null) {
installFromPath(bundle, pathEntry.getPath(), pathEntry, targetNode,
pathEntry.isUninstall() ? createdNodes : null, contentCreator);
}
}
}
// now optimize created nodes list
Collections.sort(createdNodes);
if (createdNodes.size() > 1) {
final Iterator<String> i = createdNodes.iterator();
String previous = i.next() + '/';
while (i.hasNext()) {
final String current = i.next();
if (current.startsWith(previous)) {
i.remove();
} else {
previous = current + '/';
}
}
}
// persist modifications now
defaultSession.refresh(true);
defaultSession.save();
for (Session session : createdSessions.values()) {
session.refresh(true);
session.save();
}
// finally check in versionable nodes
for (final Node versionable : contentCreator.getVersionables()) {
VersionManager versionManager = versionable.getSession().getWorkspace().getVersionManager();
versionManager.checkin(versionable.getPath());
}
} finally {
try {
if (defaultSession.hasPendingChanges()) {
defaultSession.refresh(false);
}
for (Session session : createdSessions.values()) {
if (session.hasPendingChanges()) {
session.refresh(false);
}
}
} catch (RepositoryException re) {
log.warn("Failure to rollback partial initial content for bundle {}", bundle.getSymbolicName(), re);
}
contentCreator.clear();
for (Session session : createdSessions.values()) {
session.logout();
}
}
log.debug("Done installing initial content from bundle {}", bundle.getSymbolicName());
return createdNodes;
}