modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
| 15 +++++-----
modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
| 2 -
modules/core/util/src/main/java/org/rhq/core/template/TemplateEngine.java
| 15 +++++-----
modules/core/util/src/test/java/org/rhq/core/template/TemplateEngineTest.java
| 6 ++++
4 files changed, 23 insertions(+), 15 deletions(-)
New commits:
commit a2fc2209301043dd47e29a13851e2571595d85a2
Merge: bab83b6... 6d1d6ca...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri Apr 30 15:07:13 2010 -0400
Merge branch 'gwt' into gwt-jay
commit bab83b63fc4a393be3d4673e67322e7f7443ec58
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri Apr 30 15:05:31 2010 -0400
Fix some isues with replacement variable logic.
File Template recipe parsing still has an issue dealing with
quoted replacement vars, or arguments, (typically for spaces in the value)
including escape backslash characters. They are replaced with the
single char, so we probably need do double escape inside of those
quoted tokens (see RecipeParser.splitCommandLine)
diff --git
a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
index 0ffe9d9..a871e91 100644
---
a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
+++
b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
@@ -168,9 +168,13 @@ public class RecipeParser {
public String replaceReplacementVariables(RecipeContext context, String input) {
+ // since our replacement strings may include \ and $ characters avoid the use of
+ // matcher.appendReplacement and like methods when doing this work.
+
+ String result = input;
Configuration replacementValues = context.getReplacementVariableValues();
TemplateEngine templateEngine = null;
- StringBuffer buffer = new StringBuffer();
+
Matcher matcher = this.replacementVariableDeclarationPattern.matcher(input);
while (matcher.find()) {
String next = matcher.group();
@@ -186,15 +190,12 @@ public class RecipeParser {
value = templateEngine.replaceTokens(next);
}
if (value != null) {
- next = value;
+ result = result.replace(next, value);
}
}
-
- // If we didn't find a replacement for the key then leave the original
value unchanged
- matcher.appendReplacement(buffer, Matcher.quoteReplacement(next));
}
- matcher.appendTail(buffer);
- return buffer.toString();
+
+ return result;
}
protected String[] splitCommandLine(String cmdLine) {
diff --git
a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
index c0cd84b..ba49656 100644
---
a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
+++
b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
@@ -215,7 +215,7 @@ public class RecipeParserTest {
addRecipeCommand("deploy -f jboss2.tar -d
@@rhq.system.sysprop.file.separator@(a)");
//addRecipeCommand("deploy -f jboss3.tar -d
@@rhq.system.sysprop.line.separator@(a)"); // can't test this here
addRecipeCommand("deploy -f jboss4.tar -d
@@rhq.system.sysprop.path.separator@(a)");
- addRecipeCommand("deploy -f jboss5.tar -d
@@rhq.system.sysprop.java.home@(a)");
+ addRecipeCommand("deploy -f jboss5.tar -d
\"@@rhq.system.sysprop.java.home@(a)\"");
addRecipeCommand("deploy -f jboss6.tar -d
@@rhq.system.sysprop.java.version@(a)");
//addRecipeCommand("deploy -f jboss7.tar -d
@@rhq.system.sysprop.user.timezone@(a)"); // sometimes this is empty
//addRecipeCommand("deploy -f jboss8.tar -d
@@rhq.system.sysprop.user.region@(a)"); // sometimes this doesn't exist
diff --git a/modules/core/util/src/main/java/org/rhq/core/template/TemplateEngine.java
b/modules/core/util/src/main/java/org/rhq/core/template/TemplateEngine.java
index b6f39d1..78e56e1 100644
--- a/modules/core/util/src/main/java/org/rhq/core/template/TemplateEngine.java
+++ b/modules/core/util/src/main/java/org/rhq/core/template/TemplateEngine.java
@@ -37,7 +37,12 @@ public class TemplateEngine implements Serializable {
}
public String replaceTokens(String input) {
- StringBuffer buffer = new StringBuffer();
+
+ // since our replacement strings may include \ and $ characters avoid the use of
+ // matcher.appendReplacement and like methods when doing this work.
+
+ String result = input;
+
Matcher matcher = tokenPattern.matcher(input);
while (matcher.find()) {
String next = matcher.group();
@@ -46,14 +51,10 @@ public class TemplateEngine implements Serializable {
String key = keyMatcher.group();
String value = tokens.get(key);
if (value != null) {
- next = value;
+ result = result.replace(next, value);
}
}
- //If we didn't find a replacement for the key
- //We leave the original value unchanged
- matcher.appendReplacement(buffer, next);
}
- matcher.appendTail(buffer);
- return buffer.toString();
+ return result;
}
}
diff --git a/modules/core/util/src/test/java/org/rhq/core/template/TemplateEngineTest.java
b/modules/core/util/src/test/java/org/rhq/core/template/TemplateEngineTest.java
index b68b9df..4402c6c 100644
--- a/modules/core/util/src/test/java/org/rhq/core/template/TemplateEngineTest.java
+++ b/modules/core/util/src/test/java/org/rhq/core/template/TemplateEngineTest.java
@@ -10,6 +10,7 @@ import org.testng.annotations.Test;
public class TemplateEngineTest extends TestCase {
private static final String IPADDR = "192.168.22.153";
private static final String SUCCESSTOKEN1 = "successtoken1";
+ private static final String WINTEMPDIR =
"C:\\Users\\JSHAUG~1\\AppData\\Local\\Temp\\";
String noTokens = "This string should come through unchanged";
String justOneToken = "@@rhq.token1@(a)";
String oneTokenWhiteSpace = "@@ rhq.token1 @@";
@@ -25,6 +26,7 @@ public class TemplateEngineTest extends TestCase {
tokens = new TreeMap<String, String>();
tokens.put("rhq.token1", SUCCESSTOKEN1);
tokens.put("rhq.platform.ethers.eth1.ipaddress", IPADDR);
+ tokens.put("rhq.system.sysprop.java.io.tmpdir", WINTEMPDIR);
}
return tokens;
}
@@ -42,6 +44,10 @@ public class TemplateEngineTest extends TestCase {
assertEquals(SUCCESSTOKEN1, templateEngine.replaceTokens(justOneToken));
}
+ public void testWinToken() {
+ assertEquals(WINTEMPDIR,
templateEngine.replaceTokens("@@rhq.system.sysprop.java.io.tmpdir@(a)"));
+ }
+
public void testOneTokenWhiteSpace() {
assertEquals(SUCCESSTOKEN1, templateEngine.replaceTokens(oneTokenWhiteSpace));
}
Show replies by date