You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/02/05 17:21:28 UTC

[sling-org-apache-sling-repoinit-parser] 01/01: SLING-10126 - Added [] as a postfix to Type to force a multi-value

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

andysch pushed a commit to branch feature/SLING-10126
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git

commit a82569f30c55b97bb46daa8d0b87893a4546be17
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Fri Feb 5 09:19:40 2021 -0800

    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
---
 .../org/apache/sling/repoinit/parser/operations/PropertyLine.java  | 4 ++++
 src/main/javacc/RepoInitGrammar.jjt                                | 5 +++--
 src/test/resources/testcases/test-67-output.txt                    | 7 ++++++-
 src/test/resources/testcases/test-67.txt                           | 7 +++++++
 4 files changed, 20 insertions(+), 3 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 6bc5156..e65d7ba 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
@@ -54,6 +54,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("[]");
+        if(forceList) {
+            typeString = typeString.substring(0, typeString.length() - 2);
+        }
         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 4718111..3d57d51 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -89,6 +89,7 @@ TOKEN:
 |   < RPAREN: ")" >
 |   < LCURLY: "{" >
 |   < RCURLY: "}" >
+|   < MULTI: "[]" >
 |   < COMMA: "," >
 |   < DQUOTE: "\"" >
 |   < COLON: ":" >
@@ -738,7 +739,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; }
 }
@@ -754,7 +755,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 3a0165d..cec00e4 100644
--- a/src/test/resources/testcases/test-67-output.txt
+++ b/src/test/resources/testcases/test-67-output.txt
@@ -17,4 +17,9 @@ SetProperties on /test/curly/brackets
   PropertyLine curlyBracketsAndSingleQuotes{String}=[{String}{'five, six':'seven,eight'}]
 SetProperties on /endkeyword
   PropertyLine endS{String}=[{String}one]
-  PropertyLine two{String}=[{String}endS]
\ No newline at end of file
+  PropertyLine two{String}=[{String}endS]
+SetProperties on /forcedMultiValue
+  PropertyLine singleMultiValue{String}=[{String}single]
+  PropertyLine emptyMultiValue{String}=[]
+  PropertyLine singleLongMultiValue{Long}=[{Long}1243]
+  PropertyLine emptyLongMultiValue{Long}=[]
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-67.txt b/src/test/resources/testcases/test-67.txt
index 35c2046..6acc11f 100644
--- a/src/test/resources/testcases/test-67.txt
+++ b/src/test/resources/testcases/test-67.txt
@@ -26,4 +26,11 @@ set properties on /endkeyword
   # using "end" instead of "endS" below causes parsing to fail
   set endS to one
   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
\ No newline at end of file