You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2020/09/08 15:02:51 UTC

[sling-org-apache-sling-feature] branch master updated (a1b8ecd -> 8990dc2)

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

rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git.


    from a1b8ecd  Update docs about prototypes
     new 4d71eb2  SLING-9684 - Support resolving variables within variables
     new 8990dc2  SLING-9684 - Support resolving variables within variables

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/sling/feature/builder/FeatureBuilder.java  | 10 ++++++----
 .../org/apache/sling/feature/builder/FeatureBuilderTest.java   |  2 ++
 2 files changed, 8 insertions(+), 4 deletions(-)


[sling-org-apache-sling-feature] 01/02: SLING-9684 - Support resolving variables within variables

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4d71eb2effe2ce267883ef93769953cb7774632e
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 4 16:47:00 2020 +0200

    SLING-9684 - Support resolving variables within variables
    
    Recursively replace variables in FeatureBuilder.replaceVariables
---
 src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java   | 5 +++--
 .../java/org/apache/sling/feature/builder/FeatureBuilderTest.java    | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
index 56012d0..8f412d7 100644
--- a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
+++ b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
@@ -278,8 +278,9 @@ public abstract class FeatureBuilder {
                     val = feature.getVariables().get(name);
                 }
 
-                if (val != null) {
-                    m.appendReplacement(sb, Matcher.quoteReplacement(val));
+                if (val != null) { 
+                    String replaced = replaceVariables(val, additionalVariables, feature);
+                    m.appendReplacement(sb, Matcher.quoteReplacement(replaced));
                 }
                 else {
                     throw new IllegalStateException("Undefined variable: " + name);
diff --git a/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java b/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
index 11ab945..9e8357a 100644
--- a/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
+++ b/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
@@ -911,6 +911,7 @@ public class FeatureBuilderTest {
         kvMap.put("varvariable", "${myvar}");
         kvMap.put("var.2", "2");
         kvMap.put("var-3", "3");
+        kvMap.put("var-4", "${var1}");
 
 
         assertEquals("foobarfoo", FeatureBuilder.replaceVariables("foo${var1}foo", null, feature));
@@ -918,6 +919,7 @@ public class FeatureBuilderTest {
         assertEquals("${}test${myvar}2", FeatureBuilder.replaceVariables("${}test${varvariable}${var.2}", null, feature ));
         assertEquals("${undefined}",FeatureBuilder.replaceVariables("${undefined}", null, feature));
         assertEquals("var-3",FeatureBuilder.replaceVariables("var-${var-3}", null, feature));
+        assertEquals("bar", FeatureBuilder.replaceVariables("${var-4}", null, feature));
     }
 
     @Test public void testHandleVarsWithConflict() throws Exception {


[sling-org-apache-sling-feature] 02/02: SLING-9684 - Support resolving variables within variables

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8990dc2c302f60eb79e6c545de9ad2d37c9107df
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 4 16:53:29 2020 +0200

    SLING-9684 - Support resolving variables within variables
    
    Simplify FeatureBuilder.replaceVariables
---
 src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
index 8f412d7..21e08b1 100644
--- a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
+++ b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
@@ -270,10 +270,11 @@ public abstract class FeatureBuilder {
 
             final int len = var.length();
             final String name = var.substring(2, len - 1);
-            if (BuilderUtil.contains(name, feature.getVariables().entrySet())) {
+            
+            if (feature.getVariables().containsKey(name)) {
                 String val = null;
                 if (additionalVariables != null)
-                    val = BuilderUtil.get(name, additionalVariables.entrySet());
+                    val = additionalVariables.get(name);
                 if (val == null) {
                     val = feature.getVariables().get(name);
                 }