You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2014/05/16 13:59:49 UTC

svn commit: r1595170 - in /sling/trunk/contrib/crankstart/core/src: main/java/org/apache/sling/crankstart/core/CrankstartParserImpl.java test/java/org/apache/sling/crankstart/CrankstartParserImplTest.java test/resources/parser-test.txt

Author: bdelacretaz
Date: Fri May 16 11:59:48 2014
New Revision: 1595170

URL: http://svn.apache.org/r1595170
Log:
Support variables in property names and values as well

Modified:
    sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartParserImpl.java
    sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/CrankstartParserImplTest.java
    sling/trunk/contrib/crankstart/core/src/test/resources/parser-test.txt

Modified: sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartParserImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartParserImpl.java?rev=1595170&r1=1595169&r2=1595170&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartParserImpl.java (original)
+++ sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartParserImpl.java Fri May 16 11:59:48 2014
@@ -74,10 +74,13 @@ class CmdIterator implements Iterator<Cr
         while(line != null && ignore(line)) {
             line = input.readLine();
         }
-        return result;
+        return injectVariables(result);
     }
     
     private String injectVariables(String line) {
+        if(line == null) {
+            return null;
+        }
         final StringBuffer b = new StringBuffer();
         final Matcher m = varPattern.matcher(line);
         while(m.find()) {
@@ -140,7 +143,7 @@ class CmdIterator implements Iterator<Cr
                 }
                 addProperty(props, takeLine());
             }
-            result = new CrankstartCommandLine(verb, injectVariables(qualifier.toString()), props);
+            result = new CrankstartCommandLine(verb, qualifier.toString(), props);
         } catch(IOException ioe) {
             line = null;
             throw new ParserException("IOException in takeLine()", ioe);

Modified: sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/CrankstartParserImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/CrankstartParserImplTest.java?rev=1595170&r1=1595169&r2=1595170&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/CrankstartParserImplTest.java (original)
+++ sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/CrankstartParserImplTest.java Fri May 16 11:59:48 2014
@@ -46,8 +46,8 @@ public class CrankstartParserImplTest {
 
             @Override
             protected String getVariable(String name) {
-                if("another.var".equals(name)) {
-                    return "Another Var";
+                if(name.startsWith("ok.")) {
+                    return name.toUpperCase() + "_" + name.length();
                 }
                 
                 return super.getVariable(name);
@@ -82,21 +82,22 @@ public class CrankstartParserImplTest {
         final CrankstartCommandLine config = it.next();
         assertCommand("config", "the.pid.goes.here", config);
         final Dictionary<String, Object> props = config.getProperties();
-        assertEquals("Expecting 3 properties", 3, props.size());
+        assertEquals("Expecting 4 properties", 4, props.size());
         assertEquals("Expecting correct foo value", "bar", props.get("foo"));
         final Object o = props.get("array");
         assertTrue("Expecting array property", o instanceof String[]);
         final String [] a = (String[])o;
         assertEquals("Expecting two entries in array", 2, a.length);
-        assertEquals("Expecting one for first array value", "one", a[0]);
-        assertEquals("Expecting two for second array value", "two", a[1]);
+        assertEquals("Expecting correct first array value", "one that has a OK.VAR1_7 variable", a[0]);
+        assertEquals("Expecting correct second array value", "two", a[1]);
         assertEquals("Expecting correct another value", "property with several words", props.get("another"));
+        assertEquals("Expecting correct variable value", "This is OK.VARB_7 now", props.get("OK.VARA_7"));
         
         assertCommand("another", "command", it.next());
         assertCommand("last.command", "", it.next());
         
         assertCommand("var1", "this is CRANKSTART_VAR_NOT_FOUND(some.var) here", it.next());
-        assertCommand("var2", "and now Another Var here", it.next());
+        assertCommand("var2", "and now OK.VAR2_7 here", it.next());
         
         assertFalse("Expecting no more commands", it.hasNext());
     }

Modified: sling/trunk/contrib/crankstart/core/src/test/resources/parser-test.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/test/resources/parser-test.txt?rev=1595170&r1=1595169&r2=1595170&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/test/resources/parser-test.txt (original)
+++ sling/trunk/contrib/crankstart/core/src/test/resources/parser-test.txt Fri May 16 11:59:48 2014
@@ -8,12 +8,13 @@ verb2 single_qualifier
 # repeating the same property name creates an array
 config the.pid.goes.here
   foo = bar
-  array = one
+  array = one that has a ${ok.var1} variable
   array = two
   another=property with several words
+  ${ok.varA} = This is ${ok.varB} now 
 another command
 last.command  
 
 # variables
 var1 this is ${some.var} here
-var2 and now ${another.var} here
\ No newline at end of file
+var2 and now ${ok.var2} here
\ No newline at end of file