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

[sling-org-apache-sling-repoinit-parser] branch master updated: SLING-11571 repoinit: allow add or remove mixin types (#25)

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

enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git


The following commit(s) were added to refs/heads/master by this push:
     new 73864a9  SLING-11571 repoinit: allow add or remove mixin types (#25)
73864a9 is described below

commit 73864a995df3ffa860d9e2b281bc153d154afc06
Author: Eric Norman <en...@apache.org>
AuthorDate: Fri Sep 9 11:12:33 2022 -0700

    SLING-11571 repoinit: allow add or remove mixin types (#25)
---
 bnd.bnd                                            |  2 +-
 .../{package-info.java => AddMixins.java}          | 39 +++++++++++--
 .../parser/operations/BaseMixinsOperation.java     | 64 ++++++++++++++++++++++
 .../parser/operations/OperationVisitor.java        |  3 +
 .../{package-info.java => RemoveMixins.java}       | 39 +++++++++++--
 .../repoinit/parser/operations/package-info.java   |  2 +-
 src/main/javacc/RepoInitGrammar.jjt                | 34 ++++++++++++
 .../parser/test/OperationToStringVisitor.java      | 13 +++++
 src/test/resources/testcases/test-72-output.txt    |  6 ++
 src/test/resources/testcases/test-72.txt           |  7 +++
 10 files changed, 199 insertions(+), 10 deletions(-)

diff --git a/bnd.bnd b/bnd.bnd
index f090de5..2ba76fa 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -1,4 +1,4 @@
 -includeresource:\
   @jackrabbit-jcr-commons-*.jar!/org/apache/jackrabbit/util/ISO8601.*
 
-Provide-Capability: org.apache.sling.repoinit.language;version:Version="8.5"
+Provide-Capability: org.apache.sling.repoinit.language;version:Version="8.6"
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/AddMixins.java
similarity index 52%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
copy to src/main/java/org/apache/sling/repoinit/parser/operations/AddMixins.java
index 034cab1..b93281b 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/AddMixins.java
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
  * 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.
@@ -6,15 +6,46 @@
  * (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
+ *      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.
- ******************************************************************************/
+ */
 
-@org.osgi.annotation.versioning.Version("6.0.0")
 package org.apache.sling.repoinit.parser.operations;
 
+
+import java.util.List;
+
+import org.jetbrains.annotations.NotNull;
+import org.osgi.annotation.versioning.ProviderType;
+
+@ProviderType
+public class AddMixins extends BaseMixinsOperation {
+
+    private static final String TO = "to";
+
+    public AddMixins(List<String> mixins, List<String> paths) {
+        super(mixins, paths);
+    }
+
+    @Override
+    public void accept(OperationVisitor v) {
+        v.visitAddMixins(this);
+    }
+
+    @Override
+    protected String getParametersDescription() {
+        return getParametersDescription(TO);
+    }
+
+    @NotNull
+    @Override
+    public String asRepoInitString() {
+        return asRepoInitString("add", TO);
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/BaseMixinsOperation.java b/src/main/java/org/apache/sling/repoinit/parser/operations/BaseMixinsOperation.java
new file mode 100644
index 0000000..29d46be
--- /dev/null
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/BaseMixinsOperation.java
@@ -0,0 +1,64 @@
+/*
+ * 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.Collections;
+import java.util.Formatter;
+import java.util.List;
+
+import org.jetbrains.annotations.NotNull;
+
+public abstract class BaseMixinsOperation extends Operation {
+    private final List<String> paths;
+    private final List<String> mixins;
+
+    protected BaseMixinsOperation(List<String> mixins, List<String> paths) {
+        this.mixins = mixins != null ? mixins : Collections.emptyList();
+        this.paths = paths != null ? paths : Collections.emptyList();
+    }
+
+    protected String getParametersDescription(String operator) {
+        final StringBuilder sb = new StringBuilder();
+        sb.append(listToString(getMixins()));
+        sb.append(" ").append(operator).append(" ");
+        sb.append(pathsToString(getPaths()));
+        return sb.toString();
+    }
+
+    @NotNull
+    protected String asRepoInitString(String action, String operator) {
+        try (Formatter formatter = new Formatter()) {
+            formatter.format("%s mixin %s %s %s%n",
+                    action,
+                    listToString(getMixins()),
+                    operator,
+                    pathsToString(getPaths()));
+            return formatter.toString();
+        }
+    }
+
+    public List<String> getPaths() {
+        return paths;
+    }
+
+    public List<String> getMixins () {
+        return mixins;
+    }
+
+}
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 e59f8ea..f2a3919 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
@@ -45,4 +45,7 @@ public interface OperationVisitor {
     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/RemoveMixins.java
similarity index 51%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
copy to src/main/java/org/apache/sling/repoinit/parser/operations/RemoveMixins.java
index 034cab1..dfddb80 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveMixins.java
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
  * 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.
@@ -6,15 +6,46 @@
  * (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
+ *      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.
- ******************************************************************************/
+ */
 
-@org.osgi.annotation.versioning.Version("6.0.0")
 package org.apache.sling.repoinit.parser.operations;
 
+
+import java.util.List;
+
+import org.jetbrains.annotations.NotNull;
+import org.osgi.annotation.versioning.ProviderType;
+
+@ProviderType
+public class RemoveMixins extends BaseMixinsOperation {
+
+    private static final String FROM = "from";
+
+    public RemoveMixins(List<String> mixins, List<String> paths) {
+        super(mixins, paths);
+    }
+
+    @Override
+    public void accept(OperationVisitor v) {
+        v.visitRemoveMixins(this);
+    }
+
+    @Override
+    protected String getParametersDescription() {
+        return getParametersDescription(FROM);
+    }
+
+    @NotNull
+    @Override
+    public String asRepoInitString() {
+        return asRepoInitString("remove", FROM);
+    }
+
+}
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 034cab1..3904b7c 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.0.0")
+@org.osgi.annotation.versioning.Version("6.1.0")
 package org.apache.sling.repoinit.parser.operations;
 
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index e46346e..d068f57 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -152,6 +152,8 @@ List<Operation> parse() :
         | removeAcePrincipals(result)
         | removeAcePrincipalBased(result)
         | createPathStatement(result)
+        | addMixins(result)
+        | removeMixins(result)
         | registerNamespaceStatement(result)
         | registerNodetypesStatement(result)
         | registerPrivilegeStatement(result)
@@ -333,6 +335,38 @@ void createPathStatement(List<Operation> result) :
     { if(cp != null) result.add(cp); }
 }
 
+void addMixins(List<Operation> result) :
+{
+    List<String> mixins = null;
+    List<String> paths = null;
+}
+{
+    <ADD> <MIXIN>
+    mixins = namespacedItemsList()
+    <TO>
+    paths = pathsList()
+
+    {
+        result.add(new AddMixins(mixins, paths));
+    }
+}
+
+void removeMixins(List<Operation> result) :
+{
+    List<String> mixins = null;
+    List<String> paths = null;
+}
+{
+    <REMOVE> <MIXIN>
+    mixins = namespacedItemsList()
+    <FROM>
+    paths = pathsList()
+
+    {
+        result.add(new RemoveMixins(mixins, paths));
+    }
+}
+
 void setAclPaths(List<Operation> result) :
 {
     List<String> paths;
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 78b34fa..0a17b17 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
@@ -44,7 +44,9 @@ import org.apache.sling.repoinit.parser.operations.SetAclPaths;
 import org.apache.sling.repoinit.parser.operations.SetAclPrincipalBased;
 import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
 import org.apache.sling.repoinit.parser.operations.AddGroupMembers;
+import org.apache.sling.repoinit.parser.operations.AddMixins;
 import org.apache.sling.repoinit.parser.operations.RemoveGroupMembers;
+import org.apache.sling.repoinit.parser.operations.RemoveMixins;
 import org.apache.sling.repoinit.parser.operations.SetProperties;
 import org.apache.sling.repoinit.parser.operations.PropertyLine;
 
@@ -307,4 +309,15 @@ class OperationToStringVisitor implements OperationVisitor {
             out.println(p);
         }
     }
+
+    @Override
+    public void visitAddMixins(AddMixins am) {
+        out.println(am.toString());
+    }
+
+    @Override
+    public void visitRemoveMixins(RemoveMixins rm) {
+        out.println(rm.toString());
+    }
+
 }
diff --git a/src/test/resources/testcases/test-72-output.txt b/src/test/resources/testcases/test-72-output.txt
new file mode 100644
index 0000000..5ce581d
--- /dev/null
+++ b/src/test/resources/testcases/test-72-output.txt
@@ -0,0 +1,6 @@
+AddMixins mix:one to /thePath1
+AddMixins mix:one,mix:two to /thePath1,/thePath2
+AddMixins mix:three,mix:four to /thePath3,/thePath4
+RemoveMixins mix:one from /thePath1
+RemoveMixins mix:one,mix:two from /thePath1,/thePath2
+RemoveMixins mix:three,mix:four from /thePath3,/thePath4
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-72.txt b/src/test/resources/testcases/test-72.txt
new file mode 100644
index 0000000..051962d
--- /dev/null
+++ b/src/test/resources/testcases/test-72.txt
@@ -0,0 +1,7 @@
+add mixin mix:one to /thePath1
+add mixin mix:one,mix:two to /thePath1,/thePath2
+add mixin mix:three, mix:four to /thePath3, /thePath4
+
+remove mixin mix:one from /thePath1
+remove mixin mix:one,mix:two from /thePath1,/thePath2
+remove mixin mix:three, mix:four from /thePath3, /thePath4
\ No newline at end of file