Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-06-19 05:27:47 +0000
committerGreg Wilkins2015-06-19 05:27:47 +0000
commit13b63c194b010201c439932ece2f1bc628ebf287 (patch)
tree771c4ae21b48e80864d4e5d4bf0f794aa488c6b6 /jetty-start/src
parentb0a3c7c5eafc472d685f86178ca04b173616215e (diff)
downloadorg.eclipse.jetty.project-13b63c194b010201c439932ece2f1bc628ebf287.tar.gz
org.eclipse.jetty.project-13b63c194b010201c439932ece2f1bc628ebf287.tar.xz
org.eclipse.jetty.project-13b63c194b010201c439932ece2f1bc628ebf287.zip
Default values for properties in ini files
While this feature is not strictly needed, the patch contains some good code cleanups. So it will be applied and then the default feature removed in a subsequent commit.
Diffstat (limited to 'jetty-start/src')
-rw-r--r--jetty-start/src/main/java/org/eclipse/jetty/start/Props.java17
-rw-r--r--jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java13
2 files changed, 24 insertions, 6 deletions
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java
index 78cdaa43a1..65191c81f5 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java
@@ -42,6 +42,9 @@ import org.eclipse.jetty.start.Props.Prop;
*/
public final class Props implements Iterable<Prop>
{
+ private static final Pattern __propertyPattern = Pattern.compile("(?<=[^$]|^)\\$\\{([^:}]*)(:=([^}]*))?\\}");
+
+
public static class Prop
{
public String key;
@@ -200,8 +203,7 @@ public final class Props implements Iterable<Prop>
return str;
}
- Pattern pat = Pattern.compile("(?<=[^$]|^)(\\$\\{[^}]*\\})");
- Matcher mat = pat.matcher(str);
+ Matcher mat = __propertyPattern.matcher(str);
StringBuilder expanded = new StringBuilder();
int offset = 0;
String property;
@@ -209,7 +211,8 @@ public final class Props implements Iterable<Prop>
while (mat.find(offset))
{
- property = cleanReference(mat.group(1));
+ property = mat.group(1);
+ String dftValue = mat.groupCount()>2?mat.group(3):null;
// Loop detection
if (seenStack.contains(property))
@@ -229,13 +232,15 @@ public final class Props implements Iterable<Prop>
seenStack.push(property);
// find property name
- expanded.append(str.subSequence(offset,mat.start(1)));
+ expanded.append(str.subSequence(offset,mat.start()));
// get property value
value = getString(property);
+ if (value==null)
+ value=dftValue;
if (value == null)
{
StartLog.trace("Unable to expand: %s",property);
- expanded.append(mat.group(1));
+ expanded.append(mat.group());
}
else
{
@@ -244,7 +249,7 @@ public final class Props implements Iterable<Prop>
expanded.append(value);
}
// update offset
- offset = mat.end(1);
+ offset = mat.end();
}
// leftover
diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java
index f7c9ee1039..0151f3b61a 100644
--- a/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java
+++ b/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java
@@ -98,6 +98,19 @@ public class PropsTest
}
@Test
+ public void testSimpleExpandWithDefaults()
+ {
+ Props props = new Props();
+ props.setProperty("name","jetty",FROM_TEST);
+ props.setProperty("version","9.1",FROM_TEST);
+
+ assertThat(props.expand("port=8080"),is("port=8080"));
+ assertThat(props.expand("jdk=${java.version:=WRONG}"),is("jdk=" + System.getProperty("java.version")));
+ assertThat(props.expand("id=${name:=WRONG}-${version:=WRONG}"),is("id=jetty-9.1"));
+ assertThat(props.expand("id=${unknown:=UNKNOWN}-${wibble}"),is("id=UNKNOWN-${wibble}"));
+ }
+
+ @Test
public void testNoExpandDoubleDollar()
{
Props props = new Props();

Back to the top