You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2016/05/17 14:12:23 UTC

svn commit: r1744274 - in /sling/trunk/bundles/commons/repoinit: oak-jcr/src/main/java/org/apache/sling/repoinit/jcr/ parser/src/main/java/org/apache/sling/repoinit/parser/operations/ parser/src/main/javacc/ parser/src/test/java/org/apache/sling/repoin...

Author: bdelacretaz
Date: Tue May 17 14:12:23 2016
New Revision: 1744274

URL: http://svn.apache.org/viewvc?rev=1744274&view=rev
Log:
SLING-5449 - initial base tree creation language, see test-20.txt for examples

Added:
    sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
    sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
    sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20-output.txt
    sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20.txt
Modified:
    sling/trunk/bundles/commons/repoinit/oak-jcr/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java
    sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
    sling/trunk/bundles/commons/repoinit/parser/src/main/javacc/RepoInitGrammar.jjt
    sling/trunk/bundles/commons/repoinit/parser/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
    sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99-output.txt
    sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99.txt

Modified: sling/trunk/bundles/commons/repoinit/oak-jcr/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/oak-jcr/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java?rev=1744274&r1=1744273&r2=1744274&view=diff
==============================================================================
--- sling/trunk/bundles/commons/repoinit/oak-jcr/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java (original)
+++ sling/trunk/bundles/commons/repoinit/oak-jcr/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java Tue May 17 14:12:23 2016
@@ -27,6 +27,7 @@ import javax.jcr.Session;
 import org.apache.sling.repoinit.jcr.impl.AclUtil;
 import org.apache.sling.repoinit.jcr.impl.ServiceUserUtil;
 import org.apache.sling.repoinit.parser.operations.AclLine;
+import org.apache.sling.repoinit.parser.operations.CreatePath;
 import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
 import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
 import org.apache.sling.repoinit.parser.operations.OperationVisitor;
@@ -113,4 +114,9 @@ public class JcrRepoInitOpVisitor implem
             setAcl(line, session, require(line, PROP_PRINCIPALS), paths, require(line, PROP_PRIVILEGES), isAllow); 
         }
     }
+
+    @Override
+    public void visitCreatePath(CreatePath cp) {
+        throw new UnsupportedOperationException("visitCreatePath is not implemented yet");
+    }
 }

Added: sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java?rev=1744274&view=auto
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java (added)
+++ sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java Tue May 17 14:12:23 2016
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.repoinit.parser.operations;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class CreatePath extends Operation {
+    private List<PathSegmentDefinition> pathDef;
+    private final String defaultPrimaryType;
+    
+    public CreatePath(String defaultPrimaryType) {
+        this.pathDef = new ArrayList<PathSegmentDefinition>();
+        this.defaultPrimaryType = defaultPrimaryType;
+    }
+    
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + " " + pathDef;
+    }
+    
+    @Override
+    protected String getParametersDescription() {
+        return pathDef.toString();
+    }
+
+    @Override
+    public void accept(OperationVisitor v) {
+        v.visitCreatePath(this);
+    }
+    
+    public void addSegment(String path, String primaryType) {
+        // We might get a path like /var/discovery, in which case
+        // the specified primary type applies to the last
+        // segment only
+        final String [] segments = path.split("/");
+        for(int i=0; i < segments.length; i++) {
+            if(segments[i].length() == 0) {
+                continue;
+            }
+            String pt = defaultPrimaryType;
+            if(i == segments.length -1 && primaryType != null) {
+                pt = primaryType;
+            }
+            pathDef.add(new PathSegmentDefinition(segments[i], pt));
+        }
+    }
+    
+    public Iterator<PathSegmentDefinition> getDefinitions() {
+        return pathDef.iterator();
+    }
+}

Modified: sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java?rev=1744274&r1=1744273&r2=1744274&view=diff
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java (original)
+++ sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java Tue May 17 14:12:23 2016
@@ -22,4 +22,5 @@ public interface OperationVisitor {
     void visitDeleteServiceUser(DeleteServiceUser s);
     void visitSetAclPrincipal(SetAclPrincipals s);
     void visitSetAclPaths(SetAclPaths s);
+    void visitCreatePath(CreatePath cp);
 }

Added: sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java?rev=1744274&view=auto
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java (added)
+++ sling/trunk/bundles/commons/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java Tue May 17 14:12:23 2016
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.repoinit.parser.operations;
+
+/** Defines a segment of a path to be created, 
+ *  with its name and an optional primary type
+ */
+public class PathSegmentDefinition {
+    private final String segment;
+    private final String primaryType;
+    
+    public PathSegmentDefinition(String segment, String primaryType) {
+        this.segment = segment;
+        this.primaryType = primaryType;
+    }
+
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append(segment);
+        if(primaryType != null) {
+            sb.append("(").append(primaryType).append(")");
+        }
+        return sb.toString();
+    }
+    
+    public String getSegment() {
+        return segment;
+    }
+
+    public String getPrimaryType() {
+        return primaryType;
+    }
+}

Modified: sling/trunk/bundles/commons/repoinit/parser/src/main/javacc/RepoInitGrammar.jjt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/main/javacc/RepoInitGrammar.jjt?rev=1744274&r1=1744273&r2=1744274&view=diff
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/main/javacc/RepoInitGrammar.jjt (original)
+++ sling/trunk/bundles/commons/repoinit/parser/src/main/javacc/RepoInitGrammar.jjt Tue May 17 14:12:23 2016
@@ -5,8 +5,9 @@
  
 options
 {
-    LOOKAHEAD=3;
     STATIC=false;
+    LOOKAHEAD=3;
+    //FORCE_LA_CHECK=true;
 }
 
 PARSER_BEGIN(RepoInitParserImpl)
@@ -63,6 +64,9 @@ TOKEN:
 |   < END: "end" >
 |   < USER: "user" >
 |   < NODETYPES: "nodetypes" >
+|   < CREATE_PATH: "create_path" >
+|   < LPAREN: "(" >
+|   < RPAREN: ")" >
 |   < PRINCIPAL: (["a"-"z"] | ["A"-"Z"] | ["0"-"9"] | "_" | "-")+ >
 |   < COMMA: "," >
 |   < STAR: "*" >
@@ -79,7 +83,8 @@ List<Operation> parse() :
     ( 
         serviceUserStatement(result) 
         | setAclPaths(result) 
-        | setAclPrincipals(result) 
+        | setAclPrincipals(result)
+        | createPathStatement(result)
         | blankLine() 
     ) * 
     <EOF>
@@ -141,8 +146,7 @@ List<String> namespacedItemsList() :
 List<String> pathsList() :
 {
     Token t = null;
-    List<String> paths = new ArrayList<String>(); 
-    
+    List<String> paths = new ArrayList<String>();
 }
 {
     t = <PATH> { paths.add(t.image); } 
@@ -150,6 +154,32 @@ List<String> pathsList() :
     { return paths; }
 }
 
+void createPathStatement(List<Operation> result) :
+{
+    CreatePath cp = null;
+    String defaultPrimaryType = null;
+    Token t1 = null;
+    Token t2 = null;
+}
+{
+    <CREATE_PATH> 
+    ( <LPAREN> t1 = <NAMESPACED_ITEM> <RPAREN> { defaultPrimaryType = t1.image; } ) ?
+    
+    ( t1 = <PATH> ( <LPAREN> t2 = <NAMESPACED_ITEM> <RPAREN> ) ?
+        {
+            if(cp == null) {
+                cp = new CreatePath(defaultPrimaryType);
+            } 
+            cp.addSegment(t1.image, t2 == null ? null : t2.image); 
+            t2 = null; 
+        }
+    ) +
+    
+    (<EOL> | <EOF>)
+    
+    { if(cp != null) result.add(cp); }
+}
+
 void setAclPaths(List<Operation> result) :
 {
     List<String> paths;

Modified: sling/trunk/bundles/commons/repoinit/parser/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java?rev=1744274&r1=1744273&r2=1744274&view=diff
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java (original)
+++ sling/trunk/bundles/commons/repoinit/parser/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java Tue May 17 14:12:23 2016
@@ -21,6 +21,7 @@ import java.io.PrintWriter;
 import java.util.Collection;
 
 import org.apache.sling.repoinit.parser.operations.AclLine;
+import org.apache.sling.repoinit.parser.operations.CreatePath;
 import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
 import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
 import org.apache.sling.repoinit.parser.operations.OperationVisitor;
@@ -72,6 +73,11 @@ class OperationToStringVisitor implement
         dumpAclLines(s.getLines());
     }
     
+    @Override
+    public void visitCreatePath(CreatePath cp) {
+        out.println(cp.toString());
+    }
+
     private void dumpAclLines(Collection<AclLine> c) {
         for(AclLine line : c) {
             out.print("  ");

Added: sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20-output.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20-output.txt?rev=1744274&view=auto
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20-output.txt (added)
+++ sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20-output.txt Tue May 17 14:12:23 2016
@@ -0,0 +1,4 @@
+CreatePath [var(sling:Folder), discovery(nt:unstructured), somefolder(sling:Folder)]
+CreatePath [one, two, three]
+CreatePath [three, four(nt:folk), five(nt:jazz), six]
+CreatePath [seven(nt:x), eight(nt:x), nine(nt:x)]
\ No newline at end of file

Added: sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20.txt?rev=1744274&view=auto
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20.txt (added)
+++ sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-20.txt Tue May 17 14:12:23 2016
@@ -0,0 +1,6 @@
+# Various create path tests
+# TODO should use "create path" instead of "create_path"
+create_path (sling:Folder) /var/discovery(nt:unstructured)/somefolder
+create_path /one/two/three
+create_path /three/four(nt:folk)/five(nt:jazz)/six
+create_path (nt:x) /seven/eight/nine

Modified: sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99-output.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99-output.txt?rev=1744274&r1=1744273&r2=1744274&view=diff
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99-output.txt (original)
+++ sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99-output.txt Tue May 17 14:12:23 2016
@@ -9,6 +9,8 @@ SetAclPaths on /libs /apps
 CreateServiceUser bob_the_service
 SetAclPaths on /tmp 
   AclLine ALLOW {principals=[bob_the_service], privileges=[some:otherPrivilege]}
+CreatePath [content, example.com(sling:Folder)]
+CreatePath [var(nt:unstructured)]
 SetAclPrincipals for alice bob fred 
   AclLine REMOVE_ALL {paths=[/]}
   AclLine ALLOW {paths=[/content, /var], privileges=[jcr:read]}

Modified: sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99.txt?rev=1744274&r1=1744273&r2=1744274&view=diff
==============================================================================
--- sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99.txt (original)
+++ sling/trunk/bundles/commons/repoinit/parser/src/test/resources/testcases/test-99.txt Tue May 17 14:12:23 2016
@@ -17,6 +17,9 @@ set ACL on /tmp
 allow some:otherPrivilege for bob_the_service
 end
 
+create_path /content/example.com(sling:Folder)
+create_path (nt:unstructured) /var
+
 set ACL for alice, bob,fred
     remove * on /
     allow jcr:read on /content,/var