This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.jcr.contentloader-2.0.2-incubator in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git
commit 525d242cd113069a9bba23db3f64afa56bb51841 Author: Carsten Ziegeler <[email protected]> AuthorDate: Mon May 5 10:14:26 2008 +0000 SLING-413: Handle bundle update and correctly handle overwrite flag. git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader@653411 13f79535-47bb-0310-9956-ffa450edef68 --- .../contentloader/internal/ContentLoaderService.java | 15 ++++++++++++++- .../sling/jcr/contentloader/internal/Loader.java | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java index 0091df1..b3c05c6 100644 --- a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java +++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java @@ -20,7 +20,9 @@ package org.apache.sling.jcr.contentloader.internal; import java.util.Calendar; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.StringTokenizer; import javax.jcr.Node; @@ -90,6 +92,11 @@ public class ContentLoaderService implements SynchronousBundleListener { */ private String slingId; + /** + * List of currently updated bundles. + */ + private final Set<String> updatedBundles = new HashSet<String>(); + // ---------- BundleListener ----------------------------------------------- /** @@ -114,7 +121,8 @@ public class ContentLoaderService implements SynchronousBundleListener { // we can safely add the content at this point. try { Session session = getAdminSession(); - initialContentLoader.registerBundle(session, event.getBundle(), false); + final boolean isUpdate = this.updatedBundles.remove(event.getBundle().getSymbolicName()); + initialContentLoader.registerBundle(session, event.getBundle(), isUpdate); } catch (Throwable t) { log.error( "bundleChanged: Problem loading initial content of bundle " @@ -122,6 +130,11 @@ public class ContentLoaderService implements SynchronousBundleListener { + event.getBundle().getBundleId() + ")", t); } break; + case BundleEvent.UPDATED: + // we just add the symbolic name to the list of updated bundles + // we will use this info when the new start event is triggered + this.updatedBundles.add(event.getBundle().getSymbolicName()); + break; case BundleEvent.STOPPED: try { Session session = getAdminSession(); diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java index 7a3355c..0f287cf 100644 --- a/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java +++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java @@ -152,7 +152,7 @@ public class Loader { if ( !isUpdate && contentAlreadyLoaded ) { log.info("Content of bundle already loaded {}.", bundle.getSymbolicName()); } else { - this.installContent(session, bundle, pathIter); + this.installContent(session, bundle, pathIter, contentAlreadyLoaded); if (isRetry) { // log success of retry log.info( @@ -197,20 +197,23 @@ public class Loader { // ---------- internal ----------------------------------------------------- - private void installContent(Session session, Bundle bundle, final Iterator<PathEntry> pathIter) + private void installContent(final Session session, + final Bundle bundle, + final Iterator<PathEntry> pathIter, + final boolean contentAlreadyLoaded) throws RepositoryException { - try { - log.debug("Installing initial content from bundle {}", + log.debug("Installing initial content from bundle {}", bundle.getSymbolicName()); + try { while (pathIter.hasNext() ) { final PathEntry entry = pathIter.next(); - this.installFromPath(bundle, entry.getPath(), entry.isOverwrite(), session.getRootNode()); + if ( !contentAlreadyLoaded || entry.isOverwrite() ) { + this.installFromPath(bundle, entry.getPath(), entry.isOverwrite(), session.getRootNode()); + } } // persist modifications now session.save(); - log.debug("Done installing initial content from bundle {}", - bundle.getSymbolicName()); } finally { try { if (session.hasPendingChanges()) { @@ -222,6 +225,8 @@ public class Loader { bundle.getSymbolicName(), re); } } + log.debug("Done installing initial content from bundle {}", + bundle.getSymbolicName()); } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
