You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2016/09/02 08:43:30 UTC

svn commit: r1758901 - in /aries/trunk/blueprint: blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ blueprint-core/src/test/java/org/apache/aries/blueprint/ext/ blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/ blueprint-noosgi/...

Author: gnodet
Date: Fri Sep  2 08:43:30 2016
New Revision: 1758901

URL: http://svn.apache.org/viewvc?rev=1758901&view=rev
Log:
ARIES-1601 - Fix support for nested property placeholders

Added:
    aries/trunk/blueprint/blueprint-noosgi/src/test/java/org/apache/aries/blueprint/ext/
    aries/trunk/blueprint/blueprint-noosgi/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java
      - copied, changed from r1758793, aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java
Modified:
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java
    aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java
    aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java?rev=1758901&r1=1758900&r2=1758901&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java Fri Sep  2 08:43:30 2016
@@ -434,6 +434,12 @@ public abstract class AbstractPropertyPl
         // TODO: we need to handle escapes on the prefix / suffix
         Matcher matcher = getPattern().matcher(str);
         while (matcher.find()) {
+            String n = matcher.group(1);
+            int idx = n.indexOf(placeholderPrefix);
+            if (idx >= 0) {
+                matcher.region(matcher.start(1) + idx, str.length());
+                continue;
+            }
             String rep = retrieveValue(matcher.group(1));
             if (rep != null) {
                 str = str.replace(matcher.group(0), rep);

Modified: aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java?rev=1758901&r1=1758900&r2=1758901&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java Fri Sep  2 08:43:30 2016
@@ -38,6 +38,17 @@ public class PropertyPlaceholderTest ext
         bind("prop2","world");
         bind("prop3","10");
         bind("prop4","20");
+        bind("prop5","nested");
+        bind("prop-nested","hello nested world!");
+        bind("prop-recursive-1","${prop-recursive-2}");
+        bind("prop-recursive-2","${prop-recursive-3}");
+        bind("prop-recursive-3","recursive-3");
+
+        bind("animal", "quick brown fox");
+        bind("target", "lazy dog");
+        bind("animal.1", "fox");
+        bind("animal.2", "mouse");
+        bind("species", "2");
     }
     
     @Test
@@ -51,6 +62,37 @@ public class PropertyPlaceholderTest ext
         sut = makeProperty("say ${prop1} ${prop2}");
         assertEquals("say hello world", sut.getStringValue());
     }
+
+    @Test
+    public void nestedProps() {
+        sut = makeProperty("${prop-${prop5}}");
+        assertEquals("hello nested world!", sut.getStringValue());
+    }
+
+    @Test
+    public void nestedProps2() {
+        sut = makeProperty("The ${animal.${species}} jumps over the ${target}.");
+        assertEquals("The mouse jumps over the lazy dog.", sut.getStringValue());
+    }
+
+    @Test
+    public void nestedProps3() {
+        sut = makeProperty("The ${animal.${species}} jumps over the ${target}.");
+        bind("species", "1");
+        assertEquals("The fox jumps over the lazy dog.", sut.getStringValue());
+    }
+
+    @Test
+    public void recursiveProps() {
+        sut = makeProperty("${prop-recursive-1}");
+        assertEquals("recursive-3", sut.getStringValue());
+    }
+
+    @Test
+    public void plainText() {
+        sut = makeProperty("plain text");
+        assertEquals("plain text", sut.getStringValue());
+    }
     
 //    @Test
 //    public void evaluateStringProps() {

Modified: aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java?rev=1758901&r1=1758900&r2=1758901&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java (original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java Fri Sep  2 08:43:30 2016
@@ -318,6 +318,12 @@ public abstract class AbstractPropertyPl
         // TODO: we need to handle escapes on the prefix / suffix
         Matcher matcher = getPattern().matcher(str);
         while (matcher.find()) {
+            String n = matcher.group(1);
+            int idx = n.indexOf(placeholderPrefix);
+            if (idx >= 0) {
+                matcher.region(matcher.start(1) + idx, str.length());
+                continue;
+            }
             String rep = retrieveValue(matcher.group(1));
             if (rep != null) {
                 str = str.replace(matcher.group(0), rep);

Copied: aries/trunk/blueprint/blueprint-noosgi/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java (from r1758793, aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java?p2=aries/trunk/blueprint/blueprint-noosgi/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java&p1=aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java&r1=1758793&r2=1758901&rev=1758901&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java (original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/test/java/org/apache/aries/blueprint/ext/PropertyPlaceholderTest.java Fri Sep  2 08:43:30 2016
@@ -30,7 +30,7 @@ import org.osgi.service.blueprint.reflec
 public class PropertyPlaceholderTest extends PropertyPlaceholder {
     private final Map<String,String> values = new HashMap<String,String>();
     private LateBindingValueMetadata sut;
-    
+
     @Before
     public void setup() {
         values.clear();
@@ -38,53 +38,95 @@ public class PropertyPlaceholderTest ext
         bind("prop2","world");
         bind("prop3","10");
         bind("prop4","20");
+        bind("prop5","nested");
+        bind("prop-nested","hello nested world!");
+        bind("prop-recursive-1","${prop-recursive-2}");
+        bind("prop-recursive-2","${prop-recursive-3}");
+        bind("prop-recursive-3","recursive-3");
+
+        bind("animal", "quick brown fox");
+        bind("target", "lazy dog");
+        bind("animal.1", "fox");
+        bind("animal.2", "mouse");
+        bind("species", "2");
     }
-    
+
     @Test
     public void singleProp() {
         sut = makeProperty("${prop1}");
         assertEquals("hello", sut.getStringValue());
     }
-    
+
     @Test
     public void multipleProps() {
         sut = makeProperty("say ${prop1} ${prop2}");
         assertEquals("say hello world", sut.getStringValue());
     }
-    
+
+    @Test
+    public void nestedProps() {
+        sut = makeProperty("${prop-${prop5}}");
+        assertEquals("hello nested world!", sut.getStringValue());
+    }
+
+    @Test
+    public void nestedProps2() {
+        sut = makeProperty("The ${animal.${species}} jumps over the ${target}.");
+        assertEquals("The mouse jumps over the lazy dog.", sut.getStringValue());
+    }
+
+    @Test
+    public void nestedProps3() {
+        sut = makeProperty("The ${animal.${species}} jumps over the ${target}.");
+        bind("species", "1");
+        assertEquals("The fox jumps over the lazy dog.", sut.getStringValue());
+    }
+
+    @Test
+    public void recursiveProps() {
+        sut = makeProperty("${prop-recursive-1}");
+        assertEquals("recursive-3", sut.getStringValue());
+    }
+
+    @Test
+    public void plainText() {
+        sut = makeProperty("plain text");
+        assertEquals("plain text", sut.getStringValue());
+    }
+
 //    @Test
 //    public void evaluateStringProps() {
 //        sut = makeProperty("${prop1+prop2}");
 //        assertEquals("helloworld", sut.getStringValue());
 //    }
-//    
+//
 //    @Test
 //    public void evaluateIntProps() {
 //        sut = makeProperty("${prop3+prop4}");
 //        assertEquals("30", sut.getStringValue());
 //    }
-    
-    
-    
+
+
+
     /*
      * Test helper methods
      */
-    
+
     // Override to simulate actual property retrieval
     protected String getProperty(String prop) {
         return values.get(prop);
     }
-    
+
     private void bind(String prop, String val) {
         values.put(prop, val);
     }
-    
+
     private LateBindingValueMetadata makeProperty(final String prop) {
         return new LateBindingValueMetadata(new ValueMetadata() {
             public String getType() {
                 return null;
             }
-            
+
             public String getStringValue() {
                 return prop;
             }