sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject svn commit: r1603925 - in /sling/trunk/tooling/ide: eclipse-test/src/org/apache/sling/ide/test/impl/ impl-vlt/src/org/apache/sling/ide/impl/vlt/
Date Thu, 19 Jun 2014 15:37:07 GMT
Author: rombert
Date: Thu Jun 19 15:37:06 2014
New Revision: 1603925

URL: http://svn.apache.org/r1603925
Log:
SLING-3658 - Could not publish to the server.
java.util.NoSuchElementException

Correct the reordering implementation and make it more resilient.

Added:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children-reordered.xml
  (with props)
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children.xml
  (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java
    sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java?rev=1603925&r1=1603924&r2=1603925&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java
(original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java
Thu Jun 19 15:37:06 2014
@@ -17,11 +17,13 @@
 package org.apache.sling.ide.test.impl;
 
 import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasChildrenCount;
+import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasChildrenNames;
 import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPath;
 import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPrimaryType;
 import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPropertyValue;
 import static org.hamcrest.CoreMatchers.allOf;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.util.concurrent.Callable;
 
@@ -41,6 +43,7 @@ import org.eclipse.core.resources.IProje
 import org.eclipse.core.runtime.Path;
 import org.hamcrest.Matcher;
 import org.junit.After;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.RuleChain;
@@ -176,6 +179,64 @@ public class JcrPartialCoverageAggregate
         }, allOf(hasPath("/content/test-root/nested"), hasChildrenCount(1), hasPropertyValue("jcr:title",
"Some Folder")));
     }
 
+    @Test
+    public void deploySlingOrderedFolderWithJcrContentNode() throws Exception {
+
+        wstServer.waitForServerToStart();
+
+        // create faceted project
+        IProject contentProject = projectRule.getProject();
+
+        ProjectAdapter project = new ProjectAdapter(contentProject);
+        project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
+
+        // install content facet
+        project.installFacet("sling.content", "1.0");
+
+        ServerAdapter server = new ServerAdapter(wstServer.getServer());
+        server.installModule(contentProject);
+
+        // create a nt:file at /content/test-root/file.txt
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/file.txt"),
+                new ByteArrayInputStream("hello, world".getBytes()));
+
+        // create a sling:OrderedFolder at /content/test-root
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"),
getClass()
+                .getResourceAsStream("sling-ordered-folder-with-children.xml"));
+
+        Matcher<Node> postConditions = allOf(hasPath("/content/test-root"), hasPrimaryType("sling:OrderedFolder"),
+                hasChildrenNames("file.txt", "jcr:content"));
+
+        final RepositoryAccessor repo = new RepositoryAccessor(config);
+        Poller poller = new Poller();
+        poller.pollUntil(new Callable<Node>() {
+            @Override
+            public Node call() throws RepositoryException {
+                return repo.getNode("/content/test-root");
+
+            }
+        }, postConditions);
+
+        // reorder the children of the /content/test-root node
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"),
getClass()
+                .getResourceAsStream("sling-ordered-folder-with-children-reordered.xml"));
+
+        postConditions = allOf(hasPath("/content/test-root"), hasPrimaryType("sling:OrderedFolder"),
+                hasChildrenNames("jcr:content", "file.txt"));
+
+        poller.pollUntil(new Callable<Node>() {
+            @Override
+            public Node call() throws RepositoryException {
+                return repo.getNode("/content/test-root");
+
+            }
+        }, postConditions);
+    }
+
+    @Before
+    public void ensureCleanState() throws Exception {
+        new RepositoryAccessor(config).tryDeleteResource("/content/test-root");
+    }
 
     @After
     public void cleanup() throws Exception {

Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children-reordered.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children-reordered.xml?rev=1603925&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children-reordered.xml
(added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children-reordered.xml
Thu Jun 19 15:37:06 2014
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root 
+    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+    xmlns:jcr="http://www.jcp.org/jcr/1.0"
+    jcr:primaryType="sling:OrderedFolder">
+    <jcr:content jcr:primaryType="nt:unstructured">
+        <child jcr:primaryType="nt:unstructured"/>
+    </jcr:content>
+    <file.txt/>          
+</jcr:root>
\ No newline at end of file

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children-reordered.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children-reordered.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children.xml?rev=1603925&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children.xml
(added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children.xml
Thu Jun 19 15:37:06 2014
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root 
+    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+    xmlns:jcr="http://www.jcp.org/jcr/1.0"
+    jcr:primaryType="sling:OrderedFolder">
+    <file.txt/>
+    <jcr:content jcr:primaryType="nt:unstructured">
+        <child jcr:primaryType="nt:unstructured"/>
+    </jcr:content>      
+</jcr:root>
\ No newline at end of file

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-ordered-folder-with-children.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java?rev=1603925&r1=1603924&r2=1603925&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
(original)
+++ sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
Thu Jun 19 15:37:06 2014
@@ -156,47 +156,77 @@ public class AddOrUpdateNodeCommand exte
         }
     }
 
-    private void reorderChildNodes(Node node, ResourceProxy resource2) throws RepositoryException
{
+    private void reorderChildNodes(Node nodeToReorder, ResourceProxy resourceToReorder) throws
RepositoryException {
 
-        ListIterator<ResourceProxy> coveredResourceChildren = resource2.getCoveredChildren().listIterator();
+        List<ResourceProxy> children = resourceToReorder.getChildren();
+        ListIterator<ResourceProxy> childrenIterator = children.listIterator();
 
         // do not process
-        if (!coveredResourceChildren.hasNext()) {
+        if (!childrenIterator.hasNext()) {
             Activator.getDefault().getPluginLogger()
-                    .trace("Resource at {0} has no covered children, child node reordering",
resource2.getPath());
+                    .trace("Resource at {0} has no children, skipping child node reordering",
+                            resourceToReorder.getPath());
             return;
         }
         List<Node> nodeChildren = new LinkedList<Node>();
-        NodeIterator nodeChildrenIt = node.getNodes();
+        NodeIterator nodeChildrenIt = nodeToReorder.getNodes();
         while (nodeChildrenIt.hasNext()) {
             nodeChildren.add(nodeChildrenIt.nextNode());
         }
         ListIterator<Node> nodeChildrenListIt = nodeChildren.listIterator();
 
-        // in here we should really have equal count of elements, but allow a NSEE
-        // to be raised if one of the iterators has too many
+        // it is possible for the repository and the local workspace to have a different
types of elements
+        // for instance if the repository has been changed independently of the local workspace
modifications
+        // therefore allow for the
         boolean changed = false;
-        while (coveredResourceChildren.hasNext() || nodeChildrenListIt.hasNext()) {
 
-            ResourceProxy rp = coveredResourceChildren.next();
-            Node n = nodeChildrenListIt.next();
+        traceResourcesAndNodes(children, nodeChildren);
 
-            // descend into covered child resources and perform reordering
-            reorderChildNodes(n, rp);
+        if (children.size() != nodeChildren.size()) {
+            Activator.getDefault().getPluginLogger()
+                    .warn("Different number of children between the local workspace and the
repository for path "
+                            + resourceToReorder.getPath() + ". Reordering will not be performed");
+            return;
+        }
+
+        while (childrenIterator.hasNext() || nodeChildrenListIt.hasNext()) {
+
+            ResourceProxy childResource = childrenIterator.next();
+            Node childNode = nodeChildrenListIt.next();
 
             // order is as expected, skip reordering
-            if (Text.getName(rp.getPath()).equals(n.getName())) {
+            if (Text.getName(childResource.getPath()).equals(childNode.getName())) {
+                // descend into covered child resources once they are properly arranged and
perform reordering
+                if (resourceToReorder.covers(childResource.getPath())) {
+                    reorderChildNodes(childNode, childResource);
+                }
                 continue;
             }
 
             // don't perform any reordering if this particular node does not have reorderable
children
-            if (!n.getPrimaryNodeType().hasOrderableChildNodes()) {
+            if (!nodeToReorder.getPrimaryNodeType().hasOrderableChildNodes()) {
+                Activator
+                        .getDefault()
+                        .getPluginLogger()
+                        .trace("Node at {0} does not have orderable child nodes, skipping
reordering of {1}",
+                                nodeToReorder.getPath(), childResource.getPath());
                 continue;
             }
 
-            String expectedParentName = coveredResourceChildren.hasPrevious() ? Text.getName(coveredResourceChildren
-                    .previous().getPath()) : null;
-            node.orderBefore(expectedParentName, n.getName());
+            String expectedParentName;
+            if (childrenIterator.hasNext()) {
+                expectedParentName = Text.getName(childrenIterator.next().getPath());
+                childrenIterator.previous(); // move back
+            } else {
+                expectedParentName = null;
+            }
+
+            Activator.getDefault().getPluginLogger()
+                    .trace("For node at {0} ordering {1} before {2}", nodeToReorder.getPath(),
+                            Text.getName(childResource.getPath()),
+                            expectedParentName);
+
+            nodeToReorder.orderBefore(Text.getName(childResource.getPath()), expectedParentName);
             changed = true;
             break;
         }
@@ -204,9 +234,28 @@ public class AddOrUpdateNodeCommand exte
         // re-read the data and run the ordering again
         // this makes sure that we don't have inconsistent data in the node list
         if (changed) {
-            reorderChildNodes(node, resource2);
+            reorderChildNodes(nodeToReorder, resourceToReorder);
+        }
+
+    }
+
+    private void traceResourcesAndNodes(List<ResourceProxy> children, List<Node>
nodeChildren)
+            throws RepositoryException {
+        
+        StringBuilder out = new StringBuilder();
+        out.append("Comparison of nodes and resources before reordering \n");
+        
+        out.append(" === Resources === \n");
+        for (int i = 0; i < children.size(); i++) {
+            out.append(String.format("%3d. %s%n", i, children.get(i).getPath()));
+        }
+
+        out.append(" === Nodes === \n");
+        for (int i = 0; i < nodeChildren.size(); i++) {
+            out.append(String.format("%3d. %s%n", i, nodeChildren.get(i).getPath()));
         }
 
+        Activator.getDefault().getPluginLogger().trace(out.toString());
     }
 
     private Node createNode(ResourceProxy resource, Session session) throws RepositoryException,
FileNotFoundException {



Mime
View raw message