You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2022/12/16 08:05:08 UTC

[sling-org-apache-sling-repoinit-parser] 01/01: SLING-11736 Add "createNode" as replacement of "createPath" with stricter semantics of adjusting types of existing nodes

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

kwin pushed a commit to branch feature/create-node-statement
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git

commit 96f6bb6a29fa9b8fabff14c964b6b7019a0f82ac
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Fri Dec 16 09:05:00 2022 +0100

    SLING-11736 Add "createNode" as replacement of "createPath" with
    stricter semantics of adjusting types of existing nodes
---
 .../{CreatePath.java => CreateNode.java}           |  6 ++--
 .../repoinit/parser/operations/CreatePath.java     |  5 +++
 .../parser/operations/OperationVisitor.java        |  2 +-
 .../repoinit/parser/operations/package-info.java   |  2 +-
 src/main/javacc/RepoInitGrammar.jjt                | 39 ++++++++++++++++++++++
 .../parser/test/OperationToStringVisitor.java      | 11 ++++++
 6 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java b/src/main/java/org/apache/sling/repoinit/parser/operations/CreateNode.java
similarity index 97%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
copy to src/main/java/org/apache/sling/repoinit/parser/operations/CreateNode.java
index d40ddba..8bec2b0 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/CreateNode.java
@@ -26,12 +26,12 @@ import org.jetbrains.annotations.NotNull;
 import org.osgi.annotation.versioning.ProviderType;
 
 @ProviderType
-public class CreatePath extends Operation {
+public class CreateNode extends Operation {
     private List<PathSegmentDefinition> pathDef;
     private final String defaultPrimaryType;
     private List<PropertyLine> lines = Collections.emptyList();
 
-    public CreatePath(String defaultPrimaryType) {
+    public CreateNode(String defaultPrimaryType) {
         this.pathDef = new ArrayList<>();
         this.defaultPrimaryType = defaultPrimaryType;
     }
@@ -90,7 +90,7 @@ public class CreatePath extends Operation {
 
     @Override
     public void accept(OperationVisitor v) {
-        v.visitCreatePath(this);
+        v.visitCreateNode(this);
     }
 
     public void addSegment(String path, String primaryType) {
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java b/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
index d40ddba..b79b1f0 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
@@ -25,7 +25,12 @@ import java.util.List;
 import org.jetbrains.annotations.NotNull;
 import org.osgi.annotation.versioning.ProviderType;
 
+/**
+ * @deprecate Use {@link CreateNode} instead.
+ *
+ */
 @ProviderType
+@Deprecated
 public class CreatePath extends Operation {
     private List<PathSegmentDefinition> pathDef;
     private final String defaultPrimaryType;
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java b/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
index f2a3919..e98b1d9 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
@@ -34,6 +34,7 @@ public interface OperationVisitor {
     default void visitRemoveAcePaths(RemoveAcePaths s) { throw new UnsupportedOperationException(); }
     default void visitRemoveAcePrincipalBased(RemoveAcePrincipalBased s) { throw new UnsupportedOperationException(); }
     void visitCreatePath(CreatePath cp);
+    void visitCreateNode(CreateNode cn);
     void visitRegisterNamespace(RegisterNamespace rn);
     void visitRegisterNodetypes(RegisterNodetypes b);
     void visitRegisterPrivilege(RegisterPrivilege rp);
@@ -44,7 +45,6 @@ public interface OperationVisitor {
     default void visitDeleteAclPrincipals(DeleteAclPrincipals s) { throw new UnsupportedOperationException(); }
     default void visitDeleteAclPaths(DeleteAclPaths s) { throw new UnsupportedOperationException(); }
     default void visitDeleteAclPrincipalBased(DeleteAclPrincipalBased s) { throw new UnsupportedOperationException(); }
-
     default void visitAddMixins(AddMixins s) { throw new UnsupportedOperationException(); }
     default void visitRemoveMixins(RemoveMixins s) { throw new UnsupportedOperationException(); }
 
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java b/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
index 3904b7c..8e43410 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
@@ -15,6 +15,6 @@
  * limitations under the License.
  ******************************************************************************/
 
-@org.osgi.annotation.versioning.Version("6.1.0")
+@org.osgi.annotation.versioning.Version("6.2.0")
 package org.apache.sling.repoinit.parser.operations;
 
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index d068f57..6c23527 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -73,6 +73,7 @@ TOKEN:
 |   < ADD: "add" >
 |   < MIXIN: "mixin" >
 |   < PATH: "path" >
+|   < NODE: "node" >
 |   < END: "end" >
 |   < REPOSITORY: "repository" >
 |   < PRINCIPAL: "principal" >
@@ -335,6 +336,44 @@ void createPathStatement(List<Operation> result) :
     { if(cp != null) result.add(cp); }
 }
 
+// same as createPath but with stricter semantics of also changing types of existing nodes
+void createNodeStatement(List<Operation> result) :
+{
+    CreateNode cn = null;
+    String defaultPrimaryType = null;
+    Token t1 = null;
+    Token t2 = null;
+    List<String> t3 = null;
+    List<PropertyLine> lines = new ArrayList<PropertyLine>();
+}
+{
+    <CREATE> <NODE> 
+    ( <LPAREN> t1 = <NAMESPACED_ITEM> <RPAREN> { defaultPrimaryType = t1.image; } ) ?
+    
+    ( t1 = <PATH_STRING> ( <LPAREN> t2 = <NAMESPACED_ITEM> <RPAREN> ) ?
+                         ( <LPAREN> <MIXIN> t3 = namespacedItemsList() <RPAREN>) ?
+                         ( <LPAREN> t2 = <NAMESPACED_ITEM> <MIXIN> t3 = namespacedItemsList() <RPAREN>) ?
+        {
+            if(cn == null) {
+                cn = new CreateNode(defaultPrimaryType);
+            } 
+            cn.addSegment(t1.image, t2 == null ? null : t2.image, t3);
+            t2 = null;
+            t3 = null;
+        }
+    ) +
+    ( <WITH> <PROPERTIES> <EOL>
+      ( propertyLine(lines) | blankLine() ) +
+      {
+        cn.setPropertyLines(lines);
+      }
+      <END>
+    )?
+    (<EOL> | <EOF>)
+    
+    { if(cn != null) result.add(cn); }
+}
+
 void addMixins(List<Operation> result) :
 {
     List<String> mixins = null;
diff --git a/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java b/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
index 0a17b17..42978ea 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.sling.repoinit.parser.operations.AclLine;
 import org.apache.sling.repoinit.parser.operations.CreateGroup;
+import org.apache.sling.repoinit.parser.operations.CreateNode;
 import org.apache.sling.repoinit.parser.operations.CreatePath;
 import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
 import org.apache.sling.repoinit.parser.operations.CreateUser;
@@ -223,6 +224,16 @@ class OperationToStringVisitor implements OperationVisitor {
         }
     }
 
+    @Override
+    public void visitCreateNode(CreateNode cn) {
+        out.println(cn.toString());
+        List<PropertyLine> propLines = cn.getPropertyLines();
+        for(PropertyLine p : propLines) {
+            out.print("  ");
+            out.println(p);
+        }
+    }
+
     @Override
     public void visitRegisterNamespace(RegisterNamespace rn) {
         out.println(rn.toString());