You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/09/09 13:22:44 UTC
svn commit: r1807896 - in /sling/trunk/bundles/extensions/bundleresource/src:
main/java/org/apache/sling/bundleresource/impl/
test/java/org/apache/sling/bundleresource/impl/
Author: cziegeler
Date: Sat Sep 9 13:22:44 2017
New Revision: 1807896
URL: http://svn.apache.org/viewvc?rev=1807896&view=rev
Log:
SLING-6878 : Bundle resource provider: support mounting of JSON files
Added:
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java
- copied, changed from r1807895, sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/MappedPath.java
sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/PathMappingTest.java
- copied, changed from r1807895, sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
Removed:
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/MappedPath.java
sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
Modified:
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java?rev=1807896&r1=1807895&r2=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java Sat Sep 9 13:22:44 2017
@@ -120,12 +120,13 @@ public class Activator implements Bundle
new Object[] { prefixes, bundle.getSymbolicName(), bundle.getVersion(),
bundle.getBundleId() });
- final MappedPath[] roots = MappedPath.getRoots(prefixes);
+ final PathMapping[] roots = PathMapping.getRoots(prefixes);
providers = new BundleResourceProvider[roots.length];
int index = 0;
- for(final MappedPath path : roots) {
- final BundleResourceProvider brp = new BundleResourceProvider(bundle, path);
+ final BundleResourceCache cache = new BundleResourceCache(bundle);
+ for(final PathMapping path : roots) {
+ final BundleResourceProvider brp = new BundleResourceProvider(cache, path);
providers[index] = brp;
index++;
Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java?rev=1807896&r1=1807895&r2=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java Sat Sep 9 13:22:44 2017
@@ -56,7 +56,7 @@ public class BundleResource extends Abst
private final BundleResourceCache cache;
- private final MappedPath mappedPath;
+ private final PathMapping mappedPath;
private final String path;
@@ -71,7 +71,7 @@ public class BundleResource extends Abst
@SuppressWarnings("unchecked")
public BundleResource(final ResourceResolver resourceResolver,
final BundleResourceCache cache,
- final MappedPath mappedPath,
+ final PathMapping mappedPath,
final String resourcePath,
final Map<String, Object> readProps,
final boolean isFolder) {
@@ -306,7 +306,7 @@ public class BundleResource extends Abst
return cache;
}
- MappedPath getMappedPath() {
+ PathMapping getMappedPath() {
return mappedPath;
}
Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java?rev=1807896&r1=1807895&r2=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java Sat Sep 9 13:22:44 2017
@@ -48,7 +48,7 @@ class BundleResourceIterator implements
/** Bundle providing the entry resources */
private final BundleResourceCache cache;
- private final MappedPath mappedPath;
+ private final PathMapping mappedPath;
/** Underlying bundle entry path enumeration */
private final Iterator<String> entries;
@@ -81,7 +81,7 @@ class BundleResourceIterator implements
}
BundleResourceIterator(ResourceResolver resourceResolver, BundleResourceCache bundle,
- MappedPath mappedPath, String parentPath) {
+ PathMapping mappedPath, String parentPath) {
// trailing slash to enumerate children
if (!parentPath.endsWith("/")) {
Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java?rev=1807896&r1=1807895&r2=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java Sat Sep 9 13:22:44 2017
@@ -40,7 +40,7 @@ public class BundleResourceProvider exte
private final BundleResourceCache cache;
/** The root path */
- private final MappedPath root;
+ private final PathMapping root;
@SuppressWarnings("rawtypes")
private volatile ServiceRegistration<ResourceProvider> serviceRegistration;
@@ -50,8 +50,8 @@ public class BundleResourceProvider exte
* supporting resources below root paths given by the rootList which is a
* comma (and whitespace) separated list of absolute paths.
*/
- public BundleResourceProvider(final Bundle bundle, final MappedPath root) {
- this.cache = new BundleResourceCache(bundle);
+ public BundleResourceProvider(final BundleResourceCache cache, final PathMapping root) {
+ this.cache = cache;
this.root = root;
}
@@ -72,7 +72,11 @@ public class BundleResourceProvider exte
void unregisterService() {
if (serviceRegistration != null) {
- serviceRegistration.unregister();
+ try {
+ serviceRegistration.unregister();
+ } catch ( final IllegalStateException ise ) {
+ // this might happen on shutdown, so ignore
+ }
serviceRegistration = null;
}
}
@@ -88,7 +92,7 @@ public class BundleResourceProvider exte
final String resourcePath,
final ResourceContext resourceContext,
final Resource parent) {
- final MappedPath mappedPath = getMappedPath(resourcePath);
+ final PathMapping mappedPath = getMappedPath(resourcePath);
if (mappedPath != null) {
final String entryPath = mappedPath.getEntryPath(resourcePath);
@@ -159,7 +163,7 @@ public class BundleResourceProvider exte
// ensure this provider may have children of the parent
String parentPath = parent.getPath();
- MappedPath mappedPath = getMappedPath(parentPath);
+ PathMapping mappedPath = getMappedPath(parentPath);
if (mappedPath != null) {
return new BundleResourceIterator(parent.getResourceResolver(),
cache, mappedPath, parentPath);
@@ -177,13 +181,13 @@ public class BundleResourceProvider exte
return cache;
}
- MappedPath getMappedPath() {
+ PathMapping getMappedPath() {
return root;
}
// ---------- internal
- private MappedPath getMappedPath(final String resourcePath) {
+ private PathMapping getMappedPath(final String resourcePath) {
if (this.root.isChild(resourcePath)) {
return root;
}
Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java?rev=1807896&r1=1807895&r2=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java Sat Sep 9 13:22:44 2017
@@ -93,7 +93,7 @@ class BundleResourceWebConsolePlugin ext
for (BundleResourceProvider bundleResourceProvider : brp) {
BundleResourceCache cache = bundleResourceProvider.getBundleResourceCache();
- MappedPath path = bundleResourceProvider.getMappedPath();
+ PathMapping path = bundleResourceProvider.getMappedPath();
pw.println("<tr class='content'>");
Copied: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java (from r1807895, sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/MappedPath.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java?p2=sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java&p1=sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/MappedPath.java&r1=1807895&r2=1807896&rev=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/MappedPath.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java Sat Sep 9 13:22:44 2017
@@ -23,7 +23,7 @@ import java.util.List;
import org.apache.sling.commons.osgi.ManifestHeader;
-class MappedPath {
+class PathMapping {
public static final String DIR_PATH = "path";
public static final String DIR_JSON = "propsJSON";
@@ -36,8 +36,8 @@ class MappedPath {
private final String jsonExpandExtension;
- public static MappedPath[] getRoots(final String rootList) {
- List<MappedPath> prefixList = new ArrayList<>();
+ public static PathMapping[] getRoots(final String rootList) {
+ List<PathMapping> prefixList = new ArrayList<>();
final ManifestHeader header = ManifestHeader.parse(rootList);
for (final ManifestHeader.Entry entry : header.getEntries()) {
@@ -45,16 +45,16 @@ class MappedPath {
final String pathDirective = entry.getDirectiveValue(DIR_PATH);
final String expandDirective = entry.getDirectiveValue(DIR_JSON);
if (pathDirective != null) {
- prefixList.add(new MappedPath(resourceRoot, pathDirective, expandDirective));
+ prefixList.add(new PathMapping(resourceRoot, pathDirective, expandDirective));
} else {
- prefixList.add(MappedPath.create(resourceRoot, expandDirective));
+ prefixList.add(PathMapping.create(resourceRoot, expandDirective));
}
}
- return prefixList.toArray(new MappedPath[prefixList.size()]);
+ return prefixList.toArray(new PathMapping[prefixList.size()]);
}
- static MappedPath create(final String configPath,
+ static PathMapping create(final String configPath,
final String expandDirective) {
String resourceRoot;
String entryRoot;
@@ -66,10 +66,10 @@ class MappedPath {
resourceRoot = configPath;
entryRoot = null;
}
- return new MappedPath(resourceRoot, entryRoot, expandDirective);
+ return new PathMapping(resourceRoot, entryRoot, expandDirective);
}
- MappedPath(final String resourceRoot,
+ PathMapping(final String resourceRoot,
final String entryRoot,
final String expandDirective) {
this.resourceRoot = ensureNoTrailingSlash(resourceRoot);
Modified: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java?rev=1807896&r1=1807895&r2=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java Sat Sep 9 13:22:44 2017
@@ -121,9 +121,9 @@ public class BundleResourceProviderTest
final Bundle bundle = getBundle();
addContent(bundle, "/libs/foo/test.json", "HELLOWORLD");
- final MappedPath path = new MappedPath("/libs/foo", null, null);
+ final PathMapping path = new PathMapping("/libs/foo", null, null);
- final BundleResourceProvider provider = new BundleResourceProvider(bundle, path);
+ final BundleResourceProvider provider = new BundleResourceProvider(new BundleResourceCache(bundle), path);
assertNotNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test.json", mock(ResourceContext.class), null));
assertNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test", mock(ResourceContext.class), null));
}
@@ -133,9 +133,9 @@ public class BundleResourceProviderTest
final Bundle bundle = getBundle();
addContent(bundle, "/libs/foo/test.json", Collections.singletonMap("test", (Object)"foo"));
- final MappedPath path = new MappedPath("/libs/foo", null, "json");
+ final PathMapping path = new PathMapping("/libs/foo", null, "json");
- final BundleResourceProvider provider = new BundleResourceProvider(bundle, path);
+ final BundleResourceProvider provider = new BundleResourceProvider(new BundleResourceCache(bundle), path);
assertNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test.json", mock(ResourceContext.class), null));
final Resource rsrc = provider.getResource(mock(ResolveContext.class), "/libs/foo/test", mock(ResourceContext.class), null);
assertNotNull(rsrc);
@@ -151,9 +151,9 @@ public class BundleResourceProviderTest
addContent(bundle, "/libs/foo/test", "HELLOWORLD");
addContent(bundle, "/libs/foo/test.json", Collections.singletonMap("test", (Object)"foo"));
- final MappedPath path = new MappedPath("/libs/foo", null, "json");
+ final PathMapping path = new PathMapping("/libs/foo", null, "json");
- final BundleResourceProvider provider = new BundleResourceProvider(bundle, path);
+ final BundleResourceProvider provider = new BundleResourceProvider(new BundleResourceCache(bundle), path);
assertNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test.json", mock(ResourceContext.class), null));
final Resource rsrc = provider.getResource(mock(ResolveContext.class), "/libs/foo/test", mock(ResourceContext.class), null);
assertNotNull(rsrc);
@@ -178,9 +178,9 @@ public class BundleResourceProviderTest
finishContent(bundle);
- final MappedPath path = new MappedPath("/libs/foo", null, "json");
+ final PathMapping path = new PathMapping("/libs/foo", null, "json");
- final BundleResourceProvider provider = new BundleResourceProvider(bundle, path);
+ final BundleResourceProvider provider = new BundleResourceProvider(new BundleResourceCache(bundle), path);
assertContent(provider, "/libs/foo/a", "A");
assertContent(provider, "/libs/foo/b", "B");
@@ -273,9 +273,9 @@ public class BundleResourceProviderTest
finishContent(bundle);
- final MappedPath path = new MappedPath("/libs/foo", null, "json");
+ final PathMapping path = new PathMapping("/libs/foo", null, "json");
- final BundleResourceProvider provider = new BundleResourceProvider(bundle, path);
+ final BundleResourceProvider provider = new BundleResourceProvider(new BundleResourceCache(bundle), path);
assertContent(provider, "/libs/foo/a", "A");
assertContent(provider, "/libs/foo/b", "B");
Modified: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java?rev=1807896&r1=1807895&r2=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java Sat Sep 9 13:22:44 2017
@@ -72,7 +72,7 @@ public class BundleResourceTest {
final BundleResourceCache cache = getBundleResourceCache();
when(cache.getEntry("/libs/foo/test.json")).thenReturn(new URL("file:/libs/foo/test.json"));
final BundleResource rsrc = new BundleResource(null, cache,
- new MappedPath("/libs/foo", null, null), "/libs/foo/test.json", null, false);
+ new PathMapping("/libs/foo", null, null), "/libs/foo/test.json", null, false);
assertEquals(JcrConstants.NT_FILE, rsrc.getResourceType());
assertNull(rsrc.getResourceSuperType());
final ValueMap vm = rsrc.getValueMap();
@@ -83,7 +83,7 @@ public class BundleResourceTest {
final BundleResourceCache cache = getBundleResourceCache();
addContent(cache, "/libs/foo/test.json", Collections.singletonMap("test", (Object)"foo"));
final BundleResource rsrc = new BundleResource(null, cache,
- new MappedPath("/libs/foo", null, "json"), "/libs/foo/test", null, false);
+ new PathMapping("/libs/foo", null, "json"), "/libs/foo/test", null, false);
assertEquals(JcrConstants.NT_FILE, rsrc.getResourceType());
assertNull(rsrc.getResourceSuperType());
final ValueMap vm = rsrc.getValueMap();
Copied: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/PathMappingTest.java (from r1807895, sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/PathMappingTest.java?p2=sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/PathMappingTest.java&p1=sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java&r1=1807895&r2=1807896&rev=1807896&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/PathMappingTest.java Sat Sep 9 13:22:44 2017
@@ -23,10 +23,10 @@ import static org.junit.Assert.assertNul
import org.junit.Test;
-public class MappedPathTest {
+public class PathMappingTest {
@Test public void testSimpleRoot() {
- final MappedPath[] paths = MappedPath.getRoots("/libs/foo");
+ final PathMapping[] paths = PathMapping.getRoots("/libs/foo");
assertEquals(1, paths.length);
assertNull(paths[0].getEntryRoot());
assertNull(paths[0].getEntryRootPrefix());
@@ -36,7 +36,7 @@ public class MappedPathTest {
}
@Test public void testSimpleRootWithJSON() {
- final MappedPath[] paths = MappedPath.getRoots("/libs/foo;" + MappedPath.DIR_JSON + ":=json");
+ final PathMapping[] paths = PathMapping.getRoots("/libs/foo;" + PathMapping.DIR_JSON + ":=json");
assertEquals(1, paths.length);
assertNull(paths[0].getEntryRoot());
assertNull(paths[0].getEntryRootPrefix());