You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/04/13 08:17:24 UTC
[sling-org-apache-sling-jcr-contentloader] branch
feature/expose-pathentry-as-api created (now 0f40d76)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a change to branch feature/expose-pathentry-as-api
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git.
at 0f40d76 SLING-10297 expose PathEntry as API
This branch includes the following new commits:
new 0f40d76 SLING-10297 expose PathEntry as API
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-jcr-contentloader] 01/01: SLING-10297
expose PathEntry as API
Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch feature/expose-pathentry-as-api
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git
commit 0f40d76db7efbc403c5bc4b90cc6abfeb80c85ca
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Apr 13 10:17:08 2021 +0200
SLING-10297 expose PathEntry as API
---
pom.xml | 6 +++
.../contentloader/{internal => }/PathEntry.java | 60 ++++++++++++++++++----
.../contentloader/hc/BundleContentLoadedCheck.java | 2 +-
.../contentloader/internal/BaseImportLoader.java | 1 +
.../internal/BundleContentLoader.java | 1 +
.../sling/jcr/contentloader/package-info.java | 2 +-
.../jcr/contentloader/internal/PathEntryTest.java | 1 +
7 files changed, 62 insertions(+), 11 deletions(-)
diff --git a/pom.xml b/pom.xml
index da1ecde..59cbe7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -136,6 +136,12 @@
<artifactId>org.osgi.annotation.bundle</artifactId>
</dependency>
+ <!-- JetBrains annotations for null-analysis (SLING-7798) -->
+ <dependency>
+ <groupId>org.jetbrains</groupId>
+ <artifactId>annotations</artifactId>
+ </dependency>
+
<!-- -->
<dependency>
<groupId>javax.jcr</groupId>
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java b/src/main/java/org/apache/sling/jcr/contentloader/PathEntry.java
similarity index 77%
rename from src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
rename to src/main/java/org/apache/sling/jcr/contentloader/PathEntry.java
index 38898ae..2713085 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/PathEntry.java
@@ -16,15 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.jcr.contentloader.internal;
+package org.apache.sling.jcr.contentloader;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
+import java.util.function.Function;
+import java.util.jar.Manifest;
+import java.util.stream.Collectors;
import org.apache.sling.commons.osgi.ManifestHeader;
-import org.apache.sling.jcr.contentloader.ImportOptions;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.osgi.framework.Bundle;
/**
@@ -129,14 +136,43 @@ public class PathEntry extends ImportOptions {
private long lastModified;
- public static Iterator<PathEntry> getContentPaths(final Bundle bundle) {
+ /**
+ * Parses the "Sling-Initial-Content" header from the given manifest and returns the resolved PathEntries
+ *
+ * @param manifest the manifest
+ * @param bundleLastModified the timestamp when the bundle has been last modified or -1 if not known
+ * @return an iterator over the parsed {@code PathEntry} items or {@code null} in case no "Sling-Initial-Content" header was found in the manifest
+ */
+ public static @Nullable Iterator<PathEntry> getContentPaths(@NotNull final Manifest manifest, long bundleLastModified) {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ Map<String, String> headers = (Map)manifest.getMainAttributes();
+ return getContentPaths(headers, bundleLastModified);
+ }
+
+ /**
+ * Parses the "Sling-Initial-Content" header from the given bundle and returns the resolved PathEntries
+ *
+ * @param bundle the bundle
+ * @return an iterator over the parsed {@code PathEntry} items or {@code null} in case no "Sling-Initial-Content" header was found in the bundle's manifest
+ */
+ public static @Nullable Iterator<PathEntry> getContentPaths(final Bundle bundle) {
+ return getContentPaths(toMap(bundle.getHeaders()), bundle.getLastModified());
+ }
+
+ /**
+ * Parses the "Sling-Initial-Content" header from the given headers and returns the resolved PathEntries
+ *
+ * @param headers the manifest headers
+ * @param bundleLastModified the timestamp when the bundle has been last modified or -1 if not known
+ * @return an iterator over the parsed {@code PathEntry} items or {@code null} in case no "Sling-Initial-Content" header was found
+ */
+ public static @Nullable Iterator<PathEntry> getContentPaths(final Map<String, String> headers, long bundleLastModified) {
final List<PathEntry> entries = new ArrayList<>();
- String bundleLastModifiedStamp = bundle.getHeaders().get("Bnd-LastModified");
- long bundleLastModified = bundle.getLastModified(); // time last modified inside the container
+ String bundleLastModifiedStamp = headers.get("Bnd-LastModified");
if ( bundleLastModifiedStamp != null ) {
bundleLastModified = Math.min(bundleLastModified, Long.parseLong(bundleLastModifiedStamp));
}
- final String root = bundle.getHeaders().get(CONTENT_HEADER);
+ final String root = headers.get(CONTENT_HEADER);
if (root != null) {
final ManifestHeader header = ManifestHeader.parse(root);
for (final ManifestHeader.Entry entry : header.getEntries()) {
@@ -151,6 +187,12 @@ public class PathEntry extends ImportOptions {
return entries.iterator();
}
+ private static Map<String, String> toMap(Dictionary<String, String> dict) {
+ List<String> keys = Collections.list(dict.keys());
+ return keys.stream()
+ .collect(Collectors.toMap(Function.identity(), dict::get));
+ }
+
public PathEntry(ManifestHeader.Entry entry, long bundleLastModified) {
this.path = entry.getValue();
this.lastModified = bundleLastModified;
@@ -250,7 +292,7 @@ public class PathEntry extends ImportOptions {
}
/* (non-Javadoc)
- * @see org.apache.sling.jcr.contentloader.internal.ImportOptions#isOverwrite()
+ * @see org.apache.sling.jcr.contentloader.ImportOptions#isOverwrite()
*/
public boolean isOverwrite() {
return this.overwrite;
@@ -269,7 +311,7 @@ public class PathEntry extends ImportOptions {
}
/* (non-Javadoc)
- * @see org.apache.sling.jcr.contentloader.internal.ImportOptions#isCheckin()
+ * @see org.apache.sling.jcr.contentloader.ImportOptions#isCheckin()
*/
public boolean isCheckin() {
return this.checkin;
@@ -284,7 +326,7 @@ public class PathEntry extends ImportOptions {
}
/* (non-Javadoc)
- * @see org.apache.sling.jcr.contentloader.internal.ImportOptions#isIgnoredImportProvider(java.lang.String)
+ * @see org.apache.sling.jcr.contentloader.ImportOptions#isIgnoredImportProvider(java.lang.String)
*/
public boolean isIgnoredImportProvider(String extension) {
if ( extension.startsWith(".") ) {
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java b/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java
index 10a3692..b032bc6 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java
@@ -31,8 +31,8 @@ import org.apache.felix.hc.api.HealthCheck;
import org.apache.felix.hc.api.Result;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.contentloader.internal.BundleHelper;
+import org.apache.sling.jcr.contentloader.PathEntry;
import org.apache.sling.jcr.contentloader.internal.BundleContentLoaderListener;
-import org.apache.sling.jcr.contentloader.internal.PathEntry;
import org.apache.sling.serviceusermapping.ServiceUserMapped;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/BaseImportLoader.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/BaseImportLoader.java
index 4a9dd52..39c9473 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/BaseImportLoader.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/BaseImportLoader.java
@@ -25,6 +25,7 @@ import java.util.Map.Entry;
import org.apache.sling.jcr.contentloader.ContentReader;
import org.apache.sling.jcr.contentloader.ImportOptions;
+import org.apache.sling.jcr.contentloader.PathEntry;
/**
* Base class that takes care of the details that are common to bundle content
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 9bb7f71..8bbb26e 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
@@ -50,6 +50,7 @@ import javax.jcr.version.VersionManager;
import org.apache.commons.io.IOUtils;
import org.apache.sling.jcr.contentloader.ContentReader;
+import org.apache.sling.jcr.contentloader.PathEntry;
import org.osgi.framework.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/package-info.java b/src/main/java/org/apache/sling/jcr/contentloader/package-info.java
index 7bb87b6..569304a 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/package-info.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/package-info.java
@@ -17,6 +17,6 @@
* under the License.
*/
-@org.osgi.annotation.versioning.Version("0.4.0")
+@org.osgi.annotation.versioning.Version("0.5.0")
package org.apache.sling.jcr.contentloader;
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/PathEntryTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/PathEntryTest.java
index 6f3ea61..5eb02b3 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/PathEntryTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/PathEntryTest.java
@@ -31,6 +31,7 @@ import java.util.Iterator;
import java.util.Map;
import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.jcr.contentloader.PathEntry;
import org.jmock.Expectations;
import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Rule;