You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2022/01/27 16:10:44 UTC

[sling-org-apache-sling-repoinit-parser] branch master updated: SLING-10126 - Added [] as a postfix to Type to force a multi-value (#6)

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

dklco 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 d85fda3  SLING-10126 - Added [] as a postfix to Type to force a multi-value (#6)
d85fda3 is described below

commit d85fda3e9ba95ea6de3fa5ad13e8ce840677ae6d
Author: Andreas Schaefer <sc...@me.com>
AuthorDate: Thu Jan 27 08:09:19 2022 -0800

    SLING-10126 - Added [] as a postfix to Type to force a multi-value (#6)
    
    * SLING-10126 - Added [] as a postfix to Type to force a multi-value
    
    Allowed an empty value list to create an empty multi-value list
    
    * Addressing PR feedback
    
    Co-authored-by: Andreas Schaefer <sc...@iMac.local>
    Co-authored-by: Dan Klco <kl...@adobe.com>
---
 .../org/apache/sling/repoinit/parser/operations/PropertyLine.java  | 5 +++++
 src/main/javacc/RepoInitGrammar.jjt                                | 5 +++--
 src/test/resources/testcases/test-67-output.txt                    | 5 +++++
 src/test/resources/testcases/test-67.txt                           | 7 +++++++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/PropertyLine.java b/src/main/java/org/apache/sling/repoinit/parser/operations/PropertyLine.java
index 7a2b375..e3802fe 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/PropertyLine.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/PropertyLine.java
@@ -34,6 +34,7 @@ public class PropertyLine {
     private final PropertyType propertyType;
     private final List<Object> values;
     private boolean isDefault = false;
+    private static final String MULTI_TOKEN = "[]";
 
     /** Valid types for these properties */
     public enum PropertyType {
@@ -54,6 +55,10 @@ public class PropertyLine {
      */
     public PropertyLine(String name, String typeString, List<String> values, boolean isDefault) throws ParseException {
         this.name = name;
+        boolean forceList = typeString != null && typeString.endsWith(MULTI_TOKEN);
+        if(forceList) {
+            typeString = typeString.substring(0, typeString.length() - MULTI_TOKEN.length());
+        }
         this.propertyType = typeString == null ? PropertyType.String : parseType(typeString);
         this.values = parseList(this.propertyType, values);
         this.isDefault = isDefault;
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index 3b035d6..1cf53e4 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -90,6 +90,7 @@ TOKEN:
 |   < RPAREN: ")" >
 |   < LCURLY: "{" >
 |   < RCURLY: "}" >
+|   < MULTI: "[]" >
 |   < COMMA: "," >
 |   < DQUOTE: "\"" >
 |   < COLON: ":" >
@@ -800,7 +801,7 @@ List<String> propertyValuesList() :
     List<String> values = new ArrayList<String>();
 }
 {
-    ( t = propertyValue() ) { values.add(t.image); }
+    (( t = propertyValue() ) { values.add(t.image); })?
     ( <COMMA> ( t = propertyValue() ) { values.add(t.image); } )*
     { return values; }
 }
@@ -816,7 +817,7 @@ void propertyLine(List<PropertyLine> lines) :
 {
     (t = <SET> | t = <SETDEF> {isDefault = true;} )
     ( name = <STRING> | name = <NAMESPACED_ITEM>)
-    ( <LCURLY> ( type = <STRING> ) <RCURLY> )?
+    ( <LCURLY> ( type = <STRING> ) <RCURLY> | <LCURLY> ( type = <STRING> ) <MULTI> <RCURLY> )?
     <TO> ( values = propertyValuesList() )
     <EOL>
     {
diff --git a/src/test/resources/testcases/test-67-output.txt b/src/test/resources/testcases/test-67-output.txt
index 333e7da..39ee7ed 100644
--- a/src/test/resources/testcases/test-67-output.txt
+++ b/src/test/resources/testcases/test-67-output.txt
@@ -19,6 +19,11 @@ SetProperties on /test/curly/brackets
 SetProperties on /endkeyword
   PropertyLine endS{String}=[{String}one]
   PropertyLine two{String}=[{String}endS]
+SetProperties on /forcedMultiValue
+  PropertyLine singleMultiValue{String}=[{String}single]
+  PropertyLine emptyMultiValue{String}=[]
+  PropertyLine singleLongMultiValue{Long}=[{Long}1243]
+  PropertyLine emptyLongMultiValue{Long}=[]
 SetProperties on /blankLinesInList
   PropertyLine one{String}=[{String}two]
   PropertyLine two{String}=[{String}four]
diff --git a/src/test/resources/testcases/test-67.txt b/src/test/resources/testcases/test-67.txt
index af97b05..b1e94c3 100644
--- a/src/test/resources/testcases/test-67.txt
+++ b/src/test/resources/testcases/test-67.txt
@@ -29,6 +29,13 @@ set properties on /endkeyword
   set two to endS
 end
 
+set properties on /forcedMultiValue
+  set singleMultiValue{String[]} to "single"
+  set emptyMultiValue{String[]} to
+  set singleLongMultiValue{Long[]} to 1243
+  set emptyLongMultiValue{Long[]} to
+end
+
 set properties on /blankLinesInList
   set one to two