You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2022/03/09 13:07:25 UTC

[sling-org-apache-sling-jcr-contentloader] 01/01: SLING-11189 ensure all built-in content readers are registered before processing any bundle in this listener

This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch feature/SLING-11189-content-reader-listener-dependency
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git

commit f76b5f6494e188a5e213c7766409453a6aaf0da1
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Wed Mar 9 14:02:13 2022 +0100

    SLING-11189 ensure all built-in content readers are registered before processing any bundle in this listener
---
 .../internal/BundleContentLoaderListener.java        | 11 +++++++++++
 .../internal/BundleContentLoaderListenerTest.java    | 18 ++++++++++++++----
 .../internal/BundleContentLoaderTest.java            | 20 +++++++++++---------
 .../internal/hc/BundleContentLoadedCheckTest.java    |  8 +++++---
 4 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListener.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListener.java
index 1df747b..5792f15 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListener.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListener.java
@@ -35,6 +35,7 @@ import javax.jcr.lock.LockManager;
 
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.contentloader.ContentReader;
 import org.apache.sling.serviceusermapping.ServiceUserMapped;
 import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.Bundle;
@@ -122,6 +123,16 @@ public class BundleContentLoaderListener implements SynchronousBundleListener, B
     @Reference
     protected SlingSettingsService settingsService;
 
+    // SLING-11189: ensure all built-in content readers are registered before processing any bundle in this listener
+    @Reference(target = "(component.name=org.apache.sling.jcr.contentloader.internal.readers.JsonReader)")
+    private ContentReader mandatoryContentReader1;
+    @Reference(target = "(component.name=org.apache.sling.jcr.contentloader.internal.readers.OrderedJsonReader)")
+    private ContentReader mandatoryContentReader2;
+    @Reference(target = "(component.name=org.apache.sling.jcr.contentloader.internal.readers.XmlReader)")
+    private ContentReader mandatoryContentReader3;
+    @Reference(target = "(component.name=org.apache.sling.jcr.contentloader.internal.readers.ZipReader)")
+    private ContentReader mandatoryContentReader4;
+
     // ---------- BundleListener -----------------------------------------------
 
     /**
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListenerTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListenerTest.java
index 0bdef08..ca0a497 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListenerTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderListenerTest.java
@@ -41,6 +41,10 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.lock.LockManager;
 
+import org.apache.sling.jcr.contentloader.internal.readers.JsonReader;
+import org.apache.sling.jcr.contentloader.internal.readers.OrderedJsonReader;
+import org.apache.sling.jcr.contentloader.internal.readers.XmlReader;
+import org.apache.sling.jcr.contentloader.internal.readers.ZipReader;
 import org.apache.sling.testing.mock.osgi.MockBundle;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
@@ -67,6 +71,12 @@ public class BundleContentLoaderListenerTest {
 
     @Before
     public void setup() throws Exception {
+        // prepare content readers
+        context.registerInjectActivateService(JsonReader.class);
+        context.registerInjectActivateService(OrderedJsonReader.class);
+        context.registerInjectActivateService(XmlReader.class);
+        context.registerInjectActivateService(ZipReader.class);
+
         // whiteboard which holds readers
         context.registerInjectActivateService(new ContentReaderWhiteboard());
 
@@ -112,10 +122,10 @@ public class BundleContentLoaderListenerTest {
         bcNode.addNode(bundle.getSymbolicName()).addMixin("mix:lockable");
         session.save();
         LockManager lockManager = session.getWorkspace().getLockManager();
-        lockManager.lock(bcNode.getNode(bundle.getSymbolicName()).getPath(), 
-        		false, // isDeep 
-        		true, // isSessionScoped 
-        		Long.MAX_VALUE, // timeoutHint 
+        lockManager.lock(bcNode.getNode(bundle.getSymbolicName()).getPath(),
+        		false, // isDeep
+        		true, // isSessionScoped
+        		Long.MAX_VALUE, // timeoutHint
         		null); // ownerInfo
 
         assertNull(underTest.getBundleContentInfo(session, bundle, false));
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
index 40b5a41..ce5ce7f 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
@@ -49,6 +49,7 @@ import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.jcr.contentloader.internal.readers.JsonReader;
+import org.apache.sling.jcr.contentloader.internal.readers.OrderedJsonReader;
 import org.apache.sling.jcr.contentloader.internal.readers.XmlReader;
 import org.apache.sling.jcr.contentloader.internal.readers.ZipReader;
 import org.apache.sling.testing.mock.osgi.MockBundle;
@@ -74,9 +75,10 @@ public class BundleContentLoaderTest {
     @Before
     public void prepareContentLoader() throws Exception {
         // prepare content readers
-        context.registerInjectActivateService(new JsonReader());
-        context.registerInjectActivateService(new XmlReader());
-        context.registerInjectActivateService(new ZipReader());
+        context.registerInjectActivateService(JsonReader.class);
+        context.registerInjectActivateService(OrderedJsonReader.class);
+        context.registerInjectActivateService(XmlReader.class);
+        context.registerInjectActivateService(ZipReader.class);
 
         // whiteboard which holds readers
         context.registerInjectActivateService(new ContentReaderWhiteboard());
@@ -109,14 +111,14 @@ public class BundleContentLoaderTest {
         Privilege[] customPrivilegeSingleItemArray = new Privilege[]{ customPrivilege };
 
         JcrUtils.getOrCreateByPath(path, NodeType.NT_FOLDER, session);
-        
+
         AccessControlManager acMgr = session.getAccessControlManager();
         AccessControlList acl = (AccessControlList)acMgr.getApplicablePolicies(path).nextAccessControlPolicy();
         Principal everyone = EveryonePrincipal.getInstance();
         assertTrue(acl.addAccessControlEntry(everyone, customPrivilegeSingleItemArray));
         AccessControlEntry[] expectedAces = acl.getAccessControlEntries();
         acMgr.setPolicy(path, acl);
-        
+
         session.save();
         return expectedAces;
     }
@@ -131,7 +133,7 @@ public class BundleContentLoaderTest {
         AccessControlEntry[] aces = acl.getAccessControlEntries();
         assertThat(aces, Matchers.arrayContaining(expectedAces));
     }
- 
+
     @Test
     public void loadContentOverwriteWithoutPath() throws Exception {
         AccessControlEntry[] expectedAces = createFolderNodeAndACL("/apps/child");
@@ -220,7 +222,7 @@ public class BundleContentLoaderTest {
 
                 });
 
-        Bundle mockBundle = newBundleWithInitialContent(context, 
+        Bundle mockBundle = newBundleWithInitialContent(context,
                 "SLING-INF/libs/app;path:=/libs/app,SLING-INF/content/app;path:=/content/app");
 
         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
@@ -282,7 +284,7 @@ public class BundleContentLoaderTest {
 
                 });
 
-        Bundle mockBundle = newBundleWithInitialContent(context, 
+        Bundle mockBundle = newBundleWithInitialContent(context,
                 "SLING-INF/libs/app;path:=/libs/app");
 
         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
@@ -313,7 +315,7 @@ public class BundleContentLoaderTest {
 
         dumpRepo("/", 2);
 
-        Bundle mockBundle = newBundleWithInitialContent(context, 
+        Bundle mockBundle = newBundleWithInitialContent(context,
                 "SLING-INF/libs/app;path:=/libs/app;ignoreImportProviders:=xml");
 
         contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
index cddbd68..5726157 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/hc/BundleContentLoadedCheckTest.java
@@ -34,6 +34,7 @@ import org.apache.sling.jcr.contentloader.internal.BundleContentLoaderTest;
 import org.apache.sling.jcr.contentloader.internal.BundleHelper;
 import org.apache.sling.jcr.contentloader.internal.ContentReaderWhiteboard;
 import org.apache.sling.jcr.contentloader.internal.readers.JsonReader;
+import org.apache.sling.jcr.contentloader.internal.readers.OrderedJsonReader;
 import org.apache.sling.jcr.contentloader.internal.readers.XmlReader;
 import org.apache.sling.jcr.contentloader.internal.readers.ZipReader;
 import org.apache.sling.testing.mock.osgi.MockBundle;
@@ -61,9 +62,10 @@ public class BundleContentLoadedCheckTest {
         bundle = BundleContentLoaderTest.newBundleWithInitialContent(context, "SLING-INF/libs/app;path:=/libs/app");
 
         // prepare content readers
-        context.registerInjectActivateService(new JsonReader());
-        context.registerInjectActivateService(new XmlReader());
-        context.registerInjectActivateService(new ZipReader());
+        context.registerInjectActivateService(JsonReader.class);
+        context.registerInjectActivateService(OrderedJsonReader.class);
+        context.registerInjectActivateService(XmlReader.class);
+        context.registerInjectActivateService(ZipReader.class);
 
         // whiteboard which holds readers
         context.registerInjectActivateService(new ContentReaderWhiteboard());