This is an automated email from the ASF dual-hosted git repository. kwin pushed a commit to branch bugfix/SLING-11001 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git
commit edeee4d27eb0bc4dfdb38231420abff2f44ea89d Author: Konrad Windszus <[email protected]> AuthorDate: Wed Dec 15 18:46:00 2021 +0100 SLING-11001 for single file source path replace the target node Update mocking libraries to latest versions --- pom.xml | 162 +++++++++++++++------ .../internal/BundleContentLoader.java | 10 +- .../internal/BundleContentLoaderTest.java | 23 ++- 3 files changed, 138 insertions(+), 57 deletions(-) diff --git a/pom.xml b/pom.xml index af14a2d..269be33 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,14 @@ </reporting> <dependencies> + <!-- this dependency must come first to make sure Oak 1.40.0 is used for testing and not older versions being provided by other dependencies (oak-api, oak-security-spi) --> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId> + <version>3.1.2-1.40.0</version> + <scope>test</scope> + </dependency> + <!-- OSGi --> <dependency> <groupId>org.osgi</groupId> @@ -111,17 +119,17 @@ </dependency> <dependency> <groupId>org.osgi</groupId> - <artifactId>org.osgi.service.component.annotations</artifactId> + <artifactId>org.osgi.annotation.bundle</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> - <artifactId>org.osgi.service.metatype.annotations</artifactId> + <artifactId>org.osgi.service.component.annotations</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> - <artifactId>org.osgi.annotation.bundle</artifactId> + <artifactId>org.osgi.service.metatype.annotations</artifactId> <scope>provided</scope> </dependency> <!-- JetBrains annotations for null-analysis (SLING-7798) --> @@ -131,11 +139,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>javax.jcr</groupId> - <artifactId>jcr</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.serviceusermapper</artifactId> <version>1.3.4</version> @@ -144,7 +147,7 @@ <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.jcr.api</artifactId> - <version>2.3.0</version> + <version>2.4.0</version> <scope>provided</scope> </dependency> <dependency> @@ -167,9 +170,35 @@ </dependency> <dependency> <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-api</artifactId> + <version>2.16.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-jcr-commons</artifactId> + <version>2.16.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>oak-api</artifactId> + <version>1.8.0</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.apache.jackrabbit</groupId> <artifactId>oak-security-spi</artifactId> <version>1.8.0</version> + <scope>provided</scope> <optional>true</optional> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.sling</groupId> @@ -180,7 +209,7 @@ <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.commons.osgi</artifactId> - <version>2.3.0</version> + <version>2.4.0</version> <scope>provided</scope> </dependency> <dependency> @@ -190,23 +219,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.apache.jackrabbit</groupId> - <artifactId>jackrabbit-api</artifactId> - <version>2.12.1</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.jackrabbit</groupId> - <artifactId>jackrabbit-jcr-commons</artifactId> - <version>2.12.1</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>net.sf.kxml</groupId> <artifactId>kxml2</artifactId> <version>2.2.2</version> @@ -245,7 +257,7 @@ <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.api</artifactId> - <version>2.11.0</version> + <version>2.16.4</version> <scope>provided</scope> </dependency> <!-- Apache Felix --> @@ -282,21 +294,71 @@ </dependency> <dependency> <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.osgi-mock</artifactId> - <version>2.3.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.jcr-mock</artifactId> - <version>1.3.0</version> + <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId> + <version>3.2.2</version> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.sling-mock</artifactId> - <version>2.2.12</version> + <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId> + <version>3.2.2</version> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>oak-store-spi</artifactId> + </exclusion> + <exclusion> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.service.component.annotations</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.service.metatype.annotations</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>oak-query-spi</artifactId> + </exclusion> + <exclusion> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>oak-core-spi</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + <exclusion> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>oak-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-jcr-commons</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>oak-commons</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> @@ -311,12 +373,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId> - <version>2.1.2</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>junit-addons</groupId> <artifactId>junit-addons</artifactId> <version>1.4</version> @@ -338,6 +394,12 @@ <artifactId>pax-exam</artifactId> <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.ops4j.pax.exam</groupId> @@ -350,6 +412,12 @@ <artifactId>pax-exam-container-forked</artifactId> <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.ops4j.pax.exam</groupId> @@ -362,6 +430,12 @@ <artifactId>pax-exam-link-mvn</artifactId> <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> </dependency> </dependencies> diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoader.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoader.java index 9881e52..71bd020 100644 --- a/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoader.java +++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoader.java @@ -367,14 +367,8 @@ public class BundleContentLoader extends BaseImportLoader { log.info("install: No initial content entries at {} in bundle {}", path, bundle.getSymbolicName()); return; } - // we have a single file content, let's check if this has an content reader - // extension - for (String ext : contentCreator.getContentReaders().keySet()) { - if (path.endsWith(ext)) { - - } - } - handleFile(path, bundle, processedEntries, configuration, parent, createdNodes, contentCreator); + // we have a single file content -> this should replace the target node fully, i.e. parent is one level above + handleFile(path, bundle, processedEntries, configuration, parent.getParent(), createdNodes, contentCreator); return; } 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 4c8a58e..40b5a41 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 @@ -22,10 +22,9 @@ import static java.util.Collections.singletonMap; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.lang.annotation.Annotation; @@ -52,11 +51,9 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.jcr.contentloader.internal.readers.JsonReader; import org.apache.sling.jcr.contentloader.internal.readers.XmlReader; import org.apache.sling.jcr.contentloader.internal.readers.ZipReader; -import org.apache.sling.jcr.resource.internal.helper.JcrResourceUtil; 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; -import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Ignore; @@ -132,7 +129,7 @@ public class BundleContentLoaderTest { AccessControlManager acMgr = session.getAccessControlManager(); AccessControlList acl = (AccessControlList)acMgr.getPolicies(path)[0]; AccessControlEntry[] aces = acl.getAccessControlEntries(); - MatcherAssert.assertThat(aces, Matchers.arrayContaining(expectedAces)); + assertThat(aces, Matchers.arrayContaining(expectedAces)); } @Test @@ -186,6 +183,22 @@ public class BundleContentLoaderTest { } @Test + public void loadContentFromFilePathEntry() throws Exception { + + BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard, null); + + Bundle mockBundle = newBundleWithInitialContent(context, "initial-content/i18n/en.json;path:=/apps/i18n/en"); + + contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false); + + Resource imported = context.resourceResolver().getResource("/apps/i18n/en"); + + assertThat("Resource was not imported", imported, notNullValue()); + assertEquals("i18n-message", imported.getValueMap().get("i18n-key")); + assertThat("sling:resourceType was not properly set", imported.getResourceType(), equalTo("sling:Folder")); + } + + @Test public void loadContentWithExcludes() throws Exception { BundleContentLoader contentLoader = new BundleContentLoader(bundleHelper, whiteboard,
