[logback-dev] svn commit: r1617 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/joran/spi main/java/ch/qos/logback/core/util test/java/ch/qos/logback/core/util
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Mon Feb 4 17:43:50 CET 2008
Author: ceki
Date: Mon Feb 4 17:43:50 2008
New Revision: 1617
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java
Log:
- Modified OptionHelper.substVars to accept the property map passed in the context.
The secondary map is no longer supported.
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java Mon Feb 4 17:43:50 2008
@@ -145,7 +145,7 @@
if (value == null) {
return null;
}
- return OptionHelper.substVars(value, context, null);
+ return OptionHelper.substVars(value, context);
}
public void addInPlayListener(InPlayListener ipl) {
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java Mon Feb 4 17:43:50 2008
@@ -74,27 +74,24 @@
/**
* Perform variable substitution in string <code>val</code> from the values
- * of keys found the primary map passed as first parameter, then in the
- * secondary map, and last in the system properties.
+ * of keys found in context property map, and if that fails, then in the
+ * system properties.
*
* <p>
* The variable substitution delimeters are <b>${</b> and <b>}</b>.
*
* <p>
- * For example, if the primary map parameter contains a property "key1" set as
+ * For example, if the context property map contains a property "key1" set as
* "value1", then the call
*
* <pre>
- * String s = OptionConverter.substituteVars("Value of key is ${key1}.", priMap,
- * null);
- * </pre>
- *
+ * String s = OptionConverter.substituteVars("Value of key is ${key1}.", context);</pre>
* will set the variable <code>s</code> to "Value of key is value1.".
*
* <p>
- * If no value could be found for the specified key, then the secondary map is
- * searches, and if that fails, the system properties are searched, if that
- * fails, then substitution defaults to the empty string.
+ * If no value could be found for the specified key in the context map, then
+ * the system properties are searched, if that fails, then substitution defaults
+ * to the empty string.
*
* <p>
* For example, if system properties contains no value for the key
@@ -102,9 +99,7 @@
*
* <pre>
* String s = OptionConverter.subsVars(
- * "Value of inexistentKey is [${inexistentKey}]", priMap, null);
- * </pre>
- *
+ * "Value of inexistentKey is [${inexistentKey}]", context);</pre>
* will set <code>s</code> to "Value of inexistentKey is []".
*
* <p>
@@ -112,9 +107,7 @@
* the ":-" operator. For example, the call
*
* <pre>
- * String s = OptionConverter.subsVars("Value of key is [${key2:-val2}]");
- * </pre>
- *
+ * String s = OptionConverter.subsVars("Value of key is [${key2:-val2}]", context);</pre>
* will set <code>s</code> to "Value of key is [val2]" even if the "key2"
* property is unset.
*
@@ -129,8 +122,7 @@
* @throws IllegalArgumentException
* if <code>val</code> is malformed.
*/
- public static String substVars(String val, Context context,
- Map<String, String> secondaryMap) {
+ public static String substVars(String val, Context context) {
StringBuffer sbuf = new StringBuffer();
@@ -174,10 +166,6 @@
// first try the props passed as parameter
replacement = context.getProperty(key);
- if (replacement == null && secondaryMap != null) {
- replacement = secondaryMap.get(key);
- }
-
// then try in System properties
if (replacement == null) {
replacement = getSystemProperty(key, null);
@@ -195,8 +183,7 @@
// where the properties are
// x1=p1
// x2=${x1}
- String recursiveReplacement = substVars(replacement, context,
- secondaryMap);
+ String recursiveReplacement = substVars(replacement, context);
sbuf.append(recursiveReplacement);
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java Mon Feb 4 17:43:50 2008
@@ -31,7 +31,7 @@
public void testSubstVarsNoSubstitution() {
String noSubst = "testing if it works";
- String result = OptionHelper.substVars(noSubst, null, null);
+ String result = OptionHelper.substVars(noSubst, null);
assertEquals(noSubst, result);
}
@@ -40,7 +40,7 @@
try {
@SuppressWarnings("unused")
- String result = OptionHelper.substVars(noSubst, null, null);
+ String result = OptionHelper.substVars(noSubst, null);
fail();
} catch (IllegalArgumentException e) {
//ok
@@ -51,15 +51,7 @@
context.putProperty("v1", "if");
context.putProperty("v2", "works");
- String result = OptionHelper.substVars(text, context, null);
- assertEquals(expected, result);
- }
-
- public void testSubstVarsPrimaryAndSecondary() {
- context.putProperty("v1", "if");
- secondaryMap.put("v2", "works");
-
- String result = OptionHelper.substVars(text, context, secondaryMap);
+ String result = OptionHelper.substVars(text, context);
assertEquals(expected, result);
}
@@ -68,7 +60,7 @@
System.setProperty("v1", "if");
System.setProperty("v2", "works");
- String result = OptionHelper.substVars(text, context, null);
+ String result = OptionHelper.substVars(text, context);
assertEquals(expected, result);
System.clearProperty("v1");
@@ -80,7 +72,7 @@
String textWithDefault = "Testing ${v1} variable substitution ${v2:-toto}";
String resultWithDefault = "Testing if variable substitution toto";
- String result = OptionHelper.substVars(textWithDefault, context, null);
+ String result = OptionHelper.substVars(textWithDefault, context);
assertEquals(resultWithDefault, result);
}
@@ -89,7 +81,7 @@
context.putProperty("v2", "${v3}");
context.putProperty("v3", "works");
- String result = OptionHelper.substVars(text, context, null);
+ String result = OptionHelper.substVars(text, context);
assertEquals(expected, result);
}
More information about the logback-dev
mailing list