You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2016/03/07 09:54:41 UTC

svn commit: r1733882 - in /jackrabbit/oak/branches/1.4: ./ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ oak-jcr/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/ oak-jcr/src/test/resources/org/apache/jackrabbit/...

Author: mreutegg
Date: Mon Mar  7 08:54:41 2016
New Revision: 1733882

URL: http://svn.apache.org/viewvc?rev=1733882&view=rev
Log:
OAK-4085: Malformed node type definition when reregistered after upgrade

Merge revision 1733875 from trunk

Added:
    jackrabbit/oak/branches/1.4/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/UpgradeTest.java
      - copied unchanged from r1733875, jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/UpgradeTest.java
    jackrabbit/oak/branches/1.4/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/nodetype/
      - copied from r1733875, jackrabbit/oak/trunk/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/nodetype/
Modified:
    jackrabbit/oak/branches/1.4/   (props changed)
    jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java
    jackrabbit/oak/branches/1.4/oak-jcr/pom.xml

Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Mar  7 08:54:41 2016
@@ -1,2 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
+/jackrabbit/oak/trunk:1733875
 /jackrabbit/trunk:1345480

Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java?rev=1733882&r1=1733881&r2=1733882&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java Mon Mar  7 08:54:41 2016
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype.write;
 
+import static com.google.common.collect.Iterables.filter;
 import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION;
 import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES;
 import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
@@ -46,6 +47,7 @@ import javax.jcr.nodetype.NodeTypeTempla
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 
+import com.google.common.base.Predicate;
 import com.google.common.collect.Lists;
 
 import org.apache.jackrabbit.oak.api.Tree;
@@ -178,12 +180,16 @@ class NodeTypeTemplateImpl extends Named
 
     private static void writeItemDefinitions(@Nonnull Tree nodeTypeTree, @CheckForNull List<? extends ItemDefinitionTemplate> itemDefTemplates,
                                              @Nonnull String nodeName, @Nonnull String primaryTypeName) throws RepositoryException {
-        Tree tree;
+        // first remove existing
+        for (Tree t : filter(nodeTypeTree.getChildren(), new SameNamePredicate(nodeName))) {
+            t.remove();
+        }
+        // now write definitions
         int index = 1;
         if (itemDefTemplates != null) {
             for (ItemDefinitionTemplate template : itemDefTemplates) {
                 String name = nodeName(nodeName, index);
-                tree = nodeTypeTree.getChild(name);
+                Tree tree = nodeTypeTree.getChild(name);
                 if (!tree.exists()) {
                     tree = nodeTypeTree.addChild(name);
                     tree.setProperty(
@@ -193,17 +199,27 @@ class NodeTypeTemplateImpl extends Named
                 index++;
             }
         }
-        tree = nodeTypeTree.getChild(nodeName(nodeName, index++));
-        while (tree.exists()) {
-            tree.remove();
-            tree = nodeTypeTree.getChild(nodeName(nodeName, index++));
-        }
     }
 
     private static String nodeName(String name, int index) {
         return (index == 1) ? name : name + '[' + index + ']';
     }
 
+    private static final class SameNamePredicate implements Predicate<Tree> {
+
+        private final String name;
+
+        private SameNamePredicate(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public boolean apply(Tree t) {
+            String s = t.getName();
+            return s.equals(name) || s.startsWith(name + "[");
+        }
+    }
+
     //------------------------------------------------------------< public >--
 
     @Override

Modified: jackrabbit/oak/branches/1.4/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-jcr/pom.xml?rev=1733882&r1=1733881&r2=1733882&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/branches/1.4/oak-jcr/pom.xml Mon Mar  7 08:54:41 2016
@@ -366,5 +366,11 @@
       <artifactId>commons-lang</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>net.lingala.zip4j</groupId>
+      <artifactId>zip4j</artifactId>
+      <version>1.3.2</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>