You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2018/02/01 15:16:03 UTC

[sling-org-apache-sling-fsresource] branch master updated (1c303f6 -> 6cf2b45)

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

jsedding pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git.


    from 1c303f6  [maven-release-plugin] prepare for next development iteration
     new 2d658ef  SLING-7463 - FS Resource Provider incorrectly deals with vault aggregate files
     new 6cf2b45  SLING-7464 - FS Resource Provider for initial content missing children

The 2 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.


Summary of changes:
 .../internal/mapper/ContentFileResourceMapper.java | 79 ++++++++++------------
 .../internal/mapper/FileVaultResourceMapper.java   | 13 +++-
 .../fsprovider/internal/FileVaultContentTest.java  | 30 +++++++-
 .../sling/fsprovider/internal/JsonContentTest.java |  9 ++-
 .../resources/fs-test/folder2/content/child.json   |  7 ++
 .../fs-test/folder2/content/child/grandchild.json  |  7 ++
 .../content/samples/{ => aggregates}/.content.xml  |  8 +--
 .../samples/aggregates/_sling_aggregate.xml}       | 14 ++--
 8 files changed, 109 insertions(+), 58 deletions(-)
 create mode 100644 src/test/resources/fs-test/folder2/content/child.json
 create mode 100644 src/test/resources/fs-test/folder2/content/child/grandchild.json
 copy src/test/resources/vaultfs-test/jcr_root/content/samples/{ => aggregates}/.content.xml (92%)
 copy src/test/resources/vaultfs-test/jcr_root/{.content.xml => content/samples/aggregates/_sling_aggregate.xml} (83%)

-- 
To stop receiving notification emails like this one, please contact
jsedding@apache.org.

[sling-org-apache-sling-fsresource] 02/02: SLING-7464 - FS Resource Provider for initial content missing children

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsedding pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git

commit 6cf2b45af1e4d8c86648092cff90bcf92812ada7
Author: Julian Sedding <js...@apache.org>
AuthorDate: Thu Feb 1 15:06:53 2018 +0100

    SLING-7464 - FS Resource Provider for initial content missing children
---
 .../internal/mapper/ContentFileResourceMapper.java | 79 ++++++++++------------
 .../sling/fsprovider/internal/JsonContentTest.java |  9 ++-
 .../resources/fs-test/folder2/content/child.json   |  7 ++
 .../fs-test/folder2/content/child/grandchild.json  |  7 ++
 4 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
index bbf2af6..e7daf29 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
@@ -22,7 +22,6 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.commons.collections.IteratorUtils;
 import org.apache.commons.collections.Transformer;
@@ -32,7 +31,6 @@ import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.fsprovider.internal.ContentFileExtensions;
 import org.apache.sling.fsprovider.internal.FsResourceMapper;
-import org.apache.sling.fsprovider.internal.parser.ContentElement;
 import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
 
 public final class ContentFileResourceMapper implements FsResourceMapper {
@@ -45,7 +43,7 @@ public final class ContentFileResourceMapper implements FsResourceMapper {
     
     private final ContentFileExtensions contentFileExtensions;
     private final ContentFileCache contentFileCache;
-    
+
     public ContentFileResourceMapper(String providerRoot, File providerFile,
             ContentFileExtensions contentFileExtensions, ContentFileCache contentFileCache) {
         this.providerRootPrefix = providerRoot.concat("/");
@@ -74,57 +72,52 @@ public final class ContentFileResourceMapper implements FsResourceMapper {
         if (contentFileExtensions.isEmpty()) {
             return null;
         }
+
         final String parentPath = parent.getPath();
-        ContentFile parentContentFile = parent.adaptTo(ContentFile.class);
+        final ContentFile parentContentFile = getFile(parentPath, null);;
+
+
+        final List<Iterator<Resource>> childIterators = new ArrayList<>(2);
+
+        // add children from parsed content
+        if (parentContentFile != null && parentContentFile.hasContent()) {
+            childIterators.add(IteratorUtils.transformedIterator(parentContentFile.getContent().getChildren().keySet().iterator(), new Transformer() {
+                @Override
+                public Object transform(final Object input) {
+                    String name = (String)input;
+                    return new ContentFileResource(resolver, parentContentFile.navigateToRelative(name));
+                }
+            }));
+        }
 
-        // not a FsResource, try to create one from the resource
-        if (parentContentFile == null) {
-            parentContentFile = getFile(parentPath, null);
-            if (parentContentFile == null) {
-                
-                // check if parent is a file resource that contains a file content resource
-                File parentFile = parent.adaptTo(File.class);
-                if (parentFile != null && parentFile.isDirectory()) {
-                    List<Resource> childResources = new ArrayList<>();
-                    for (File file : parentFile.listFiles()) {
+        // add children from filesystem folder
+        File parentDir = new File(providerFile, StringUtils.removeStart(parentPath, providerRootPrefix));
+        if (parentDir.isDirectory()) {
+            File[] files = parentDir.listFiles();
+            if (files != null) {
+                childIterators.add(IteratorUtils.transformedIterator(IteratorUtils.arrayIterator(files), new Transformer() {
+                    @Override
+                    public Object transform(final Object input) {
+                        File file = (File)input;
+                        String path = parentPath + "/" + Escape.fileToResourceName(file.getName());
                         String filenameSuffix = contentFileExtensions.getSuffix(file);
-                        if (filenameSuffix != null && !isNodeDescriptor(file)) {
-                            String path = parentPath + "/" + StringUtils.substringBeforeLast(file.getName(), filenameSuffix);
+                        if (filenameSuffix != null) {
+                            path = StringUtils.substringBeforeLast(path, filenameSuffix);
                             ContentFile contentFile = new ContentFile(file, path, null, contentFileCache);
-                            childResources.add(new ContentFileResource(resolver, contentFile));
+                            return new ContentFileResource(resolver, contentFile);
+                        } else {
+                            return new FileResource(resolver, path, file, contentFileExtensions, contentFileCache);
                         }
                     }
-                    if (!childResources.isEmpty()) {
-                        return childResources.iterator();
-                    }
-                }
-                
-                // no children here
-                return null;
+                }));
             }
         }
 
-        // get child resources from content fragments in content file
-        List<ContentFile> children = new ArrayList<>();
-        if (parentContentFile.hasContent()) {
-            Iterator<Map.Entry<String,ContentElement>> childMaps = parentContentFile.getChildren();
-            while (childMaps.hasNext()) {
-                Map.Entry<String,ContentElement> entry = childMaps.next();
-                children.add(parentContentFile.navigateToRelative(entry.getKey()));
-            }
-        }
-        if (children.isEmpty()) {
+        Iterator children = IteratorUtils.chainedIterator(childIterators);
+        if (!children.hasNext()) {
             return null;
         }
-        else {
-            return IteratorUtils.transformedIterator(children.iterator(), new Transformer() {
-                @Override
-                public Object transform(Object input) {
-                    ContentFile contentFile = (ContentFile)input;
-                    return new ContentFileResource(resolver, contentFile);
-                }
-            });
-        }
+        return children;
     }
     
     private ContentFile getFile(String path, String subPath) {
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
index ce21a72..e33f1d1 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -100,8 +100,10 @@ public class JsonContentTest {
     public void testListChildren() {
         assertThat(root, ResourceMatchers.containsChildren("fs-test"));
         assertThat(fsroot, ResourceMatchers.hasChildren("folder1", "folder2"));
-        assertThat(fsroot.getChild("folder1"), ResourceMatchers.hasChildren("folder11", "file1a.txt", "sling:file1b.txt"));
-        assertThat(fsroot.getChild("folder2"), ResourceMatchers.hasChildren("folder21", "content"));
+        assertThat(fsroot.getChild("folder1"), ResourceMatchers.containsChildrenInAnyOrder("folder11", "file1a.txt", "sling:file1b.txt"));
+        assertThat(fsroot.getChild("folder2"), ResourceMatchers.containsChildrenInAnyOrder("folder21", "content"));
+        assertThat(fsroot.getChild("folder2/content"), ResourceMatchers.containsChildrenInAnyOrder("jcr:content", "toolbar", "child", "file2content.txt", "sling:content2"));
+        assertThat(fsroot.getChild("folder2/content/child"), ResourceMatchers.containsChildrenInAnyOrder("jcr:content", "grandchild"));
     }
 
     @Test
@@ -287,6 +289,9 @@ public class JsonContentTest {
         Resource content2 = fsroot.getChild("folder2/content/sling:content2");
         assertNotNull(content2);
         assertEquals("app:Page", content2.getResourceType());
+
+        Resource content = fsroot.getChild("folder2/content");
+        assertThat(content, ResourceMatchers.hasChildren("sling:content2"));
     }
 
     @Test
diff --git a/src/test/resources/fs-test/folder2/content/child.json b/src/test/resources/fs-test/folder2/content/child.json
new file mode 100644
index 0000000..ec451fb
--- /dev/null
+++ b/src/test/resources/fs-test/folder2/content/child.json
@@ -0,0 +1,7 @@
+{
+  "jcr:primaryType":"app:Page",
+  "jcr:content": {
+    "jcr:title": "Child",
+    "sling:resourceType":"sling/page/base"
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/fs-test/folder2/content/child/grandchild.json b/src/test/resources/fs-test/folder2/content/child/grandchild.json
new file mode 100644
index 0000000..1a50b1e
--- /dev/null
+++ b/src/test/resources/fs-test/folder2/content/child/grandchild.json
@@ -0,0 +1,7 @@
+{
+  "jcr:primaryType":"app:Page",
+  "jcr:content": {
+    "jcr:title": "Grandchild",
+    "sling:resourceType":"sling/page/base"
+  }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
jsedding@apache.org.

[sling-org-apache-sling-fsresource] 01/02: SLING-7463 - FS Resource Provider incorrectly deals with vault aggregate files

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsedding pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git

commit 2d658ef28864b48cca113d709bd38394ddad0d86
Author: Julian Sedding <js...@apache.org>
AuthorDate: Thu Feb 1 13:21:45 2018 +0100

    SLING-7463 - FS Resource Provider incorrectly deals with vault aggregate files
---
 .../internal/mapper/FileVaultResourceMapper.java   | 13 +++++++++-
 .../fsprovider/internal/FileVaultContentTest.java  | 30 +++++++++++++++++++++-
 .../content/samples/aggregates/.content.xml        | 21 +++++++++++++++
 .../samples/aggregates/_sling_aggregate.xml        | 26 +++++++++++++++++++
 4 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
index 77c5554..24dc458 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
@@ -113,7 +113,18 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
         if (parentFile != null && parentFile.isDirectory()) {
             for (File childFile : parentFile.listFiles()) {
                 String childPath = parentPath + "/" + PlatformNameFormat.getRepositoryName(childFile.getName());
-                if (pathMatches(childPath) && !childPaths.contains(childPath)) {
+                File file = getFile(childPath);
+                if (file != null && pathMatches(childPath) && !childPaths.contains(childPath)) {
+                    childPaths.add(childPath);
+                    continue;
+                }
+
+                // strip xml extension unless it's .content.xml - the xml extension is re-added inside getContentFile
+                if (!childPath.endsWith('/' + DOT_CONTENT_XML)) {
+                    childPath = StringUtils.removeEnd(childPath, XML_SUFFIX);
+                }
+                ContentFile contentFile = getContentFile(childPath, null);
+                if (contentFile != null && pathMatches(childPath) && !childPaths.contains(childPath)) {
                     childPaths.add(childPath);
                 }
             }
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
index 35b51d1..16ff018 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
@@ -25,13 +25,18 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import com.google.common.collect.Iterables;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
@@ -163,5 +168,28 @@ public class FileVaultContentTest {
         assertNotNull(binaryFile);
         assertEquals("nt:file", binaryFile.getResourceType());
     }
-    
+
+    @Test
+    public void testAggregateFilesDirectAccess() throws Exception {
+        Resource aggregate = sampleContent.getChild("aggregates/sling:aggregate");
+        assertNotNull("aggregate is null", aggregate);
+        assertEquals("Aggregate Test", aggregate.getValueMap().get("jcr:title", String.class));
+        assertTrue("sling:aggregate has no children", aggregate.hasChildren());
+        Resource child = aggregate.getChild("child");
+        assertNotNull("sling:aggregate has no child called 'child'", child);
+        assertEquals("Child of Aggregate", child.getValueMap().get("jcr:title", String.class));
+    }
+
+    @Test
+    public void testAggregateFilesAccessByChildIteration() throws Exception {
+        Resource aggregates = sampleContent.getChild("aggregates");
+        assertNotNull("aggregates folder is null", aggregates);
+        Map<String, Resource> childrenByName = new HashMap<>();
+        for (final Resource child : aggregates.getChildren()) {
+            childrenByName.put(child.getName(), child);
+        }
+
+        assertEquals("Wrong child count for 'aggregates'",1, childrenByName.size());
+        assertTrue("Child named 'sling:aggregate' does not exist", childrenByName.containsKey("sling:aggregate"));
+    }
 }
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/.content.xml
new file mode 100644
index 0000000..b4ba4f2
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/.content.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+    jcr:primaryType="sling:Folder"/>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/_sling_aggregate.xml b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/_sling_aggregate.xml
new file mode 100644
index 0000000..30637d2
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/_sling_aggregate.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+          jcr:primaryType="sling:Folder"
+          jcr:title="Aggregate Test">
+    <child
+        jcr:primaryType="nt:unstructured"
+        jcr:title="Child of Aggregate"/>
+</jcr:root>

-- 
To stop receiving notification emails like this one, please contact
jsedding@apache.org.