You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2015/02/16 12:24:47 UTC

svn commit: r1660070 - in /sling/trunk/tooling/ide: eclipse-test/src/org/apache/sling/ide/test/impl/JcrContentContentProviderTest.java eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java

Author: rombert
Date: Mon Feb 16 11:24:47 2015
New Revision: 1660070

URL: http://svn.apache.org/r1660070
Log:
SLING-4332 - Malformed .content.xml files cause unhandled errors and
break the content navigator

Modified:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrContentContentProviderTest.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrContentContentProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrContentContentProviderTest.java?rev=1660070&r1=1660069&r2=1660070&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrContentContentProviderTest.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrContentContentProviderTest.java Mon Feb 16 11:24:47 2015
@@ -18,6 +18,7 @@ package org.apache.sling.ide.test.impl;
 
 import static org.junit.Assert.assertThat;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 
 import org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider;
@@ -130,6 +131,42 @@ public class JcrContentContentProviderTe
 
     }
 
+    @Test
+    public void listChildrenWhenContentXmlIsBroken() throws Exception {
+        // 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");
+
+        // create .content.xml structure
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/.content.xml"), new ByteArrayInputStream(
+                "invalid".getBytes()));
+
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/child1.txt"), new ByteArrayInputStream(
+                "hello, world".getBytes()));
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/child2.txt"), new ByteArrayInputStream(
+                "hello, world".getBytes()));
+
+        // instantiate the content provider
+        JcrContentContentProvider contentProvider = new JcrContentContentProvider();
+
+        // directly create the root node
+        SyncDir syncDirNode = new SyncDir((IFolder) contentProject.findMember("jcr_root"));
+
+        // test children of '/'
+        Object[] children = contentProvider.getChildren(syncDirNode);
+        assertChildrenHavePaths(children, "/content");
+
+        // test children of '/content'
+        JcrNode contentNode = (JcrNode) children[0];
+        Object[] children2 = contentProvider.getChildren(contentNode);
+        assertChildrenHavePaths(children2, "/content/child1.txt", "/content/child2.txt");
+    }
+
     private void assertChildrenHavePaths(Object[] children, String... paths) {
         assertThat("Unexpected number of children found", children.length, CoreMatchers.equalTo(paths.length));
         for (int i = 0; i < children.length; i++) {

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1660070&r1=1660069&r2=1660070&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java Mon Feb 16 11:24:47 2015
@@ -98,6 +98,7 @@ import de.pdark.decentxml.Element;
 import de.pdark.decentxml.Namespace;
 import de.pdark.decentxml.Node;
 import de.pdark.decentxml.Text;
+import de.pdark.decentxml.XMLParseException;
 import de.pdark.decentxml.XMLTokenizer.Type;
 
 /** WIP: model object for a jcr node shown in the content package view in project explorer **/
@@ -347,10 +348,16 @@ public class JcrNode implements IAdaptab
                             continue;
                         }
 						if (isVaultFile(iResource)) {
-							GenericJcrRootFile gjrf = new GenericJcrRootFile(this, (IFile)iResource);
+							GenericJcrRootFile gjrf;
+                            try {
+                                gjrf = new GenericJcrRootFile(this, (IFile)iResource);
+                                // gjrf.getChildren();
+                                gjrf.pickResources(membersList);
+                            } catch (XMLParseException e) {
+                                // don't try to parse it
+                                // errors will be reported by the XML validation infrastructure
+                            }
 							it.remove();
-							//gjrf.getChildren();
-							gjrf.pickResources(membersList);
 							
 							// as this might have added some new children, go through the children again and
 							// add them if they're not already added