You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/02/21 18:10:02 UTC

[1/3] git commit: [KARAF-2776] Startup bundles are installed our of order Use felix/karaf Properties instead of the java.util one in Main to keep the order of bundles

Repository: karaf
Updated Branches:
  refs/heads/master 79cf40932 -> f03731719


[KARAF-2776] Startup bundles are installed our of order
Use felix/karaf Properties instead of the java.util one in Main to keep the order of bundles


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/f0373171
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/f0373171
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/f0373171

Branch: refs/heads/master
Commit: f037317195a7241c227e40090c0d903d5c039b66
Parents: f859795
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Feb 21 18:09:41 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Feb 21 18:09:52 2014 +0100

----------------------------------------------------------------------
 .../core/internal/InstanceServiceImpl.java      |  20 +--
 .../org/apache/karaf/main/ConfigProperties.java |   2 +-
 .../org/apache/karaf/main/InstanceHelper.java   |   4 +-
 .../main/java/org/apache/karaf/main/Main.java   |   6 +-
 .../org/apache/karaf/main/PropertiesLoader.java |  32 ++---
 .../apache/karaf/main/lock/DefaultJDBCLock.java |   2 +-
 .../apache/karaf/main/lock/DerbyJDBCLock.java   |   2 +-
 .../apache/karaf/main/lock/GenericJDBCLock.java |   2 +-
 .../org/apache/karaf/main/lock/LockFactory.java |   2 +-
 .../apache/karaf/main/lock/MySQLJDBCLock.java   |   2 +-
 .../apache/karaf/main/lock/OracleJDBCLock.java  |   2 +-
 .../karaf/main/lock/PostgreSQLJDBCLock.java     |   2 +-
 .../karaf/main/lock/SQLServerJDBCLock.java      |   2 +-
 .../apache/karaf/main/lock/SimpleFileLock.java  |   2 +-
 .../karaf/main/util/BootstrapLogManager.java    |   6 +-
 .../org/apache/karaf/main/util/SubstHelper.java | 141 -------------------
 .../java/org/apache/karaf/main/MockLock.java    |   2 +-
 .../main/lock/BaseJDBCLockIntegrationTest.java  |   2 +-
 .../karaf/main/lock/BaseJDBCLockTest.java       |   4 +-
 .../lock/DefaultJDBCLockIntegrationTest.java    |   2 +-
 .../karaf/main/lock/DefaultJDBCLockTest.java    |   2 +-
 .../main/lock/DerbyJDBCLockIntegrationTest.java |   2 +-
 .../karaf/main/lock/DerbyJDBCLockTest.java      |   2 +-
 .../main/lock/MySQLJDBCLockIntegrationTest.java |   2 +-
 .../karaf/main/lock/MySQLJDBCLockTest.java      |   2 +-
 .../lock/OracleJDBCLockIntegrationTest.java     |   2 +-
 .../karaf/main/lock/OracleJDBCLockTest.java     |   2 +-
 .../lock/PostgreSQLJDBCLockIntegrationTest.java |   2 +-
 .../karaf/main/lock/PostgreSQLJDBCLockTest.java |   2 +-
 .../main/util/BootstrapLogManagerTest.java      |   2 +-
 .../apache/karaf/util/locks/FileLockUtils.java  |   2 +-
 31 files changed, 58 insertions(+), 203 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
index 1d3e922..32326ba 100644
--- a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
@@ -110,7 +110,7 @@ public class InstanceServiceImpl implements InstanceService {
         this.stopTimeout = stopTimeout;
     }
 
-    private State loadData(org.apache.felix.utils.properties.Properties storage) {
+    private State loadData(org.apache.karaf.util.properties.Properties storage) {
         State state = new State();
         int count = getInt(storage, "count", 0);
         state.defaultSshPortStart = getInt(storage, "ssh.port", state.defaultSshPortStart);
@@ -142,7 +142,7 @@ public class InstanceServiceImpl implements InstanceService {
         return state;
     }
 
-    private void saveData(State state, org.apache.felix.utils.properties.Properties storage) {
+    private void saveData(State state, org.apache.karaf.util.properties.Properties storage) {
         storage.put("ssh.port", Integer.toString(state.defaultSshPortStart));
         storage.put("rmi.registry.port", Integer.toString(state.defaultRmiRegistryPortStart));
         storage.put("rmi.server.port", Integer.toString(state.defaultRmiServerPortStart));
@@ -166,7 +166,7 @@ public class InstanceServiceImpl implements InstanceService {
         }
     }
 
-    private boolean getBool(org.apache.felix.utils.properties.Properties storage, String name, boolean def) {
+    private boolean getBool(org.apache.karaf.util.properties.Properties storage, String name, boolean def) {
         Object value = storage.get(name);
         if (value != null) {
             return Boolean.parseBoolean(value.toString());
@@ -175,7 +175,7 @@ public class InstanceServiceImpl implements InstanceService {
         }
     }
 
-    private int getInt(org.apache.felix.utils.properties.Properties storage, String name, int def) {
+    private int getInt(org.apache.karaf.util.properties.Properties storage, String name, int def) {
         Object value = storage.get(name);
         if (value != null) {
             return Integer.parseInt(value.toString());
@@ -184,7 +184,7 @@ public class InstanceServiceImpl implements InstanceService {
         }
     }
 
-    private String getString(org.apache.felix.utils.properties.Properties storage, String name, String def) {
+    private String getString(org.apache.karaf.util.properties.Properties storage, String name, String def) {
         Object value = storage.get(name);
         return value != null ? value.toString() : def;
     }
@@ -209,7 +209,7 @@ public class InstanceServiceImpl implements InstanceService {
             }
             try {
                 return FileLockUtils.execute(storageFile, new FileLockUtils.CallableWithProperties<T>() {
-                    public T call(org.apache.felix.utils.properties.Properties properties) throws IOException {
+                    public T call(org.apache.karaf.util.properties.Properties properties) throws IOException {
                         State state = loadData(properties);
                         T t = callback.call(state);
                         saveData(state, properties);
@@ -355,14 +355,14 @@ public class InstanceServiceImpl implements InstanceService {
 
     void addFeaturesFromSettings(File featuresCfg, final InstanceSettings settings) throws IOException {
         FileLockUtils.execute(featuresCfg, new FileLockUtils.RunnableWithProperties() {
-            public void run(org.apache.felix.utils.properties.Properties properties) throws IOException {
+            public void run(org.apache.karaf.util.properties.Properties properties) throws IOException {
                 appendToPropList(properties, "featuresBoot", settings.getFeatures());
                 appendToPropList(properties, "featuresRepositories", settings.getFeatureURLs());
             }
         });
     }
 
-    private void appendToPropList(org.apache.felix.utils.properties.Properties p, String key, List<String> elements) {
+    private void appendToPropList(org.apache.karaf.util.properties.Properties p, String key, List<String> elements) {
         if (elements == null) {
             return;
         }
@@ -708,7 +708,7 @@ public class InstanceServiceImpl implements InstanceService {
         File f = new File(instance.loc, path);
         try {
             return FileLockUtils.execute(f, new FileLockUtils.CallableWithProperties<Integer>() {
-                public Integer call(org.apache.felix.utils.properties.Properties properties) throws IOException {
+                public Integer call(org.apache.karaf.util.properties.Properties properties) throws IOException {
                     return Integer.parseInt(properties.get(key).toString());
                 }
             });
@@ -730,7 +730,7 @@ public class InstanceServiceImpl implements InstanceService {
                 }
                 File f = new File(instance.loc, path);
                 FileLockUtils.execute(f, new FileLockUtils.RunnableWithProperties() {
-                    public void run(org.apache.felix.utils.properties.Properties properties) throws IOException {
+                    public void run(org.apache.karaf.util.properties.Properties properties) throws IOException {
                         properties.put(key, Integer.toString(port));
                     }
                 });

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/ConfigProperties.java b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
index 1bec6b1..25f19b6 100644
--- a/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
+++ b/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
@@ -22,7 +22,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.SimpleFileLock;
 import org.apache.karaf.main.util.Utils;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
index 31329e5..01f08c5 100644
--- a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
+++ b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
@@ -19,7 +19,6 @@
 package org.apache.karaf.main;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -28,7 +27,6 @@ import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 import java.net.InetAddress;
 import java.net.ServerSocket;
-import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -62,7 +60,7 @@ public class InstanceHelper {
                     }
                 }
                 FileLockUtils.execute(propertiesFile, new FileLockUtils.RunnableWithProperties() {
-                    public void run(org.apache.felix.utils.properties.Properties props) throws IOException {
+                    public void run(org.apache.karaf.util.properties.Properties props) throws IOException {
                         if (props.isEmpty()) {
                             if (isRoot) {
                                 props.setProperty("count", "1");

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/Main.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/Main.java b/main/src/main/java/org/apache/karaf/main/Main.java
index 296c965..bc3e3d4 100644
--- a/main/src/main/java/org/apache/karaf/main/Main.java
+++ b/main/src/main/java/org/apache/karaf/main/Main.java
@@ -31,7 +31,7 @@ import java.security.Security;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -363,10 +363,8 @@ public class Main {
     
     public List<BundleInfo> readBundlesFromStartupProperties(File startupPropsFile) {
         Properties startupProps = PropertiesLoader.loadPropertiesOrFail(startupPropsFile);
-        Enumeration<Object> keyIt = startupProps.keys();
         List<BundleInfo> bundeList = new ArrayList<BundleInfo>();
-        while (keyIt.hasMoreElements()) {
-            String key = (String) keyIt.nextElement();
+        for (String key : startupProps.keySet()) {
             try {
                 BundleInfo bi = new BundleInfo();
                 bi.uri = new URI(key);

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/PropertiesLoader.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/PropertiesLoader.java b/main/src/main/java/org/apache/karaf/main/PropertiesLoader.java
index fc036c9..750241e 100644
--- a/main/src/main/java/org/apache/karaf/main/PropertiesLoader.java
+++ b/main/src/main/java/org/apache/karaf/main/PropertiesLoader.java
@@ -26,12 +26,13 @@ import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Enumeration;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.StringTokenizer;
 
-import org.apache.karaf.main.util.SubstHelper;
 import org.apache.karaf.main.util.Utils;
 
+import static org.apache.karaf.util.properties.InterpolationHelper.substVars;
+
 public class PropertiesLoader {
 
     private static final String INCLUDES_PROPERTY = "${includes}"; // mandatory includes
@@ -71,13 +72,14 @@ public class PropertiesLoader {
 
         Properties configProps = loadPropertiesFile(configPropURL, false);
         copySystemProperties(configProps);
+        configProps.substitute();
 
         // Perform variable substitution for system properties.
-        for (Enumeration<?> e = configProps.propertyNames(); e.hasMoreElements();) {
-            String name = (String) e.nextElement();
-            configProps.setProperty(name,
-                    SubstHelper.substVars(configProps.getProperty(name), name, null, configProps));
-        }
+//        for (Enumeration<?> e = configProps.propertyNames(); e.hasMoreElements();) {
+//            String name = (String) e.nextElement();
+//            configProps.setProperty(name,
+//                    SubstHelper.substVars(configProps.getProperty(name), name, null, configProps));
+//        }
 
         return configProps;
     }
@@ -100,7 +102,7 @@ public class PropertiesLoader {
      * @throws IOException
      */
     static void loadSystemProperties(File file) throws IOException {
-        Properties props = new Properties();
+        Properties props = new Properties(false);
         try {
             InputStream is = new FileInputStream(file);
             props.load(is);
@@ -114,10 +116,10 @@ public class PropertiesLoader {
 			if (name.startsWith(OVERRIDE_PREFIX)) {
 				String overrideName = name.substring(OVERRIDE_PREFIX.length());
 				String value = props.getProperty(name);
-				System.setProperty(overrideName, SubstHelper.substVars(value, name, null, props));
+				System.setProperty(overrideName, substVars(value, name, null, props));
 			} else {
 				String value = System.getProperty(name, props.getProperty(name));
-				System.setProperty(name, SubstHelper.substVars(value, name, null, props));
+				System.setProperty(name, substVars(value, name, null, props));
 			}
         }
     }
@@ -144,7 +146,7 @@ public class PropertiesLoader {
     }
 
     private static Properties loadPropertiesFile(URL configPropURL, boolean failIfNotFound) throws Exception {
-        Properties configProps = new Properties();
+        Properties configProps = new Properties(null, false);
         InputStream is = null;
         try {
             is = configPropURL.openConnection().getInputStream();
@@ -198,12 +200,8 @@ public class PropertiesLoader {
     }
 
     private static void trimValues(Properties configProps) {
-        for (Enumeration<?> e = configProps.propertyNames(); e.hasMoreElements();) {
-            Object key = e.nextElement();
-            if (key instanceof String) {
-                String v = configProps.getProperty((String) key);
-                configProps.put(key, v.trim());
-            }
+        for (String key : configProps.keySet()) {
+            configProps.put(key, configProps.get(key).trim());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java b/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
index 53358d1..1b624a6 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
@@ -24,7 +24,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java b/main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java
index 722bdce..9b7027d 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java
@@ -19,7 +19,7 @@
 package org.apache.karaf.main.lock;
 
 import java.sql.Connection;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 /**
  * Represents an exclusive lock on a database,

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java b/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
index d989315..a31bd3c 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
@@ -24,7 +24,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/LockFactory.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/LockFactory.java b/main/src/main/java/org/apache/karaf/main/lock/LockFactory.java
index 6507e26..6b11f9d 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/LockFactory.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/LockFactory.java
@@ -18,7 +18,7 @@
  */
 package org.apache.karaf.main.lock;
 
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 public class LockFactory {
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/MySQLJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/MySQLJDBCLock.java b/main/src/main/java/org/apache/karaf/main/lock/MySQLJDBCLock.java
index 597491c..6000b85 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/MySQLJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/MySQLJDBCLock.java
@@ -19,7 +19,7 @@
 package org.apache.karaf.main.lock;
 
 import java.sql.Connection;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 /**
  * Represents an exclusive lock on a database,

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/OracleJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/OracleJDBCLock.java b/main/src/main/java/org/apache/karaf/main/lock/OracleJDBCLock.java
index 6e11127..b2a41c2 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/OracleJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/OracleJDBCLock.java
@@ -20,7 +20,7 @@ package org.apache.karaf.main.lock;
 
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 /**
  * Represents an exclusive lock on a database,

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/PostgreSQLJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/PostgreSQLJDBCLock.java b/main/src/main/java/org/apache/karaf/main/lock/PostgreSQLJDBCLock.java
index c3da0b4..c73e568 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/PostgreSQLJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/PostgreSQLJDBCLock.java
@@ -18,7 +18,7 @@
  */
 package org.apache.karaf.main.lock;
 
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 /**
  * Represents an exclusive lock on a database,

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/SQLServerJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/SQLServerJDBCLock.java b/main/src/main/java/org/apache/karaf/main/lock/SQLServerJDBCLock.java
index e9d388b..d14f9c0 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/SQLServerJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/SQLServerJDBCLock.java
@@ -18,7 +18,7 @@
  */
 package org.apache.karaf.main.lock;
 
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 /**
  * Represents an exclusive lock on a database,

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java b/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
index 16dd599..3cb43ab 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
@@ -22,7 +22,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.nio.channels.FileLock;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.logging.Logger;
 
 import org.apache.karaf.main.util.BootstrapLogManager;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/util/BootstrapLogManager.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/util/BootstrapLogManager.java b/main/src/main/java/org/apache/karaf/main/util/BootstrapLogManager.java
index ceb1725..e46b50f 100644
--- a/main/src/main/java/org/apache/karaf/main/util/BootstrapLogManager.java
+++ b/main/src/main/java/org/apache/karaf/main/util/BootstrapLogManager.java
@@ -24,7 +24,9 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
+import org.apache.karaf.util.properties.InterpolationHelper;
+
 import java.util.logging.Handler;
 import java.util.logging.LogRecord;
 import java.util.logging.StreamHandler;
@@ -70,7 +72,7 @@ public class BootstrapLogManager {
         }
         
         String filename = getLogFilePath();
-        filename = SubstHelper.substVars(filename, LOG4J_APPENDER_FILE, null, configProps);
+        filename = InterpolationHelper.substVars(filename, LOG4J_APPENDER_FILE, null, configProps);
         File logFile = new File(filename);
         try {
 			return new SimpleFileHandler(logFile);

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/main/java/org/apache/karaf/main/util/SubstHelper.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/util/SubstHelper.java b/main/src/main/java/org/apache/karaf/main/util/SubstHelper.java
deleted file mode 100644
index c1ae08c..0000000
--- a/main/src/main/java/org/apache/karaf/main/util/SubstHelper.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.karaf.main.util;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-public class SubstHelper {
-    private static final String DELIM_START = "${";
-    private static final String DELIM_STOP = "}";
-
-    /**
-     * <p>
-     * This method performs property variable substitution on the
-     * specified value. If the specified value contains the syntax
-     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
-     * refers to either a configuration property or a system property,
-     * then the corresponding property value is substituted for the variable
-     * placeholder. Multiple variable placeholders may exist in the
-     * specified value as well as nested variable placeholders, which
-     * are substituted from inner most to outer most. Configuration
-     * properties override system properties.
-     * </p>
-     *
-     * @param val         The string on which to perform property substitution.
-     * @param currentKey  The key of the property being evaluated used to
-     *                    detect cycles.
-     * @param cycleMap    Map of variable references used to detect nested cycles.
-     * @param configProps Set of configuration properties.
-     * @return The value of the specified string after system property substitution.
-     * @throws IllegalArgumentException If there was a syntax error in the
-     *                                  property placeholder syntax or a recursive variable reference.
-     */
-    public static String substVars(String val, String currentKey,
-                                    Map<String, String> cycleMap, Properties configProps)
-            throws IllegalArgumentException {
-        // If there is currently no cycle map, then create
-        // one for detecting cycles for this invocation.
-        if (cycleMap == null) {
-            cycleMap = new HashMap<String, String>();
-        }
-    
-        // Put the current key in the cycle map.
-        cycleMap.put(currentKey, currentKey);
-    
-        // Assume we have a value that is something like:
-        // "leading ${foo.${bar}} middle ${baz} trailing"
-    
-        // Find the first ending '}' variable delimiter, which
-        // will correspond to the first deepest nested variable
-        // placeholder.
-        int stopDelim = val.indexOf(DELIM_STOP);
-    
-        // Find the matching starting "${" variable delimiter
-        // by looping until we find a start delimiter that is
-        // greater than the stop delimiter we have found.
-        int startDelim = val.indexOf(DELIM_START);
-        while (stopDelim >= 0) {
-            int idx = val.indexOf(DELIM_START, startDelim + DELIM_START.length());
-            if ((idx < 0) || (idx > stopDelim)) {
-                break;
-            } else if (idx < stopDelim) {
-                startDelim = idx;
-            }
-        }
-    
-        // If we do not have a start or stop delimiter, then just
-        // return the existing value.
-        if ((startDelim < 0) && (stopDelim < 0)) {
-            return val;
-        }
-        // At this point, we found a stop delimiter without a start,
-        // so throw an exception.
-        else if (((startDelim < 0) || (startDelim > stopDelim))
-                && (stopDelim >= 0)) {
-            throw new IllegalArgumentException(
-                    "stop delimiter with no start delimiter: "
-                            + val);
-        }
-    
-        // At this point, we have found a variable placeholder so
-        // we must perform a variable substitution on it.
-        // Using the start and stop delimiter indices, extract
-        // the first, deepest nested variable placeholder.
-        String variable =
-                val.substring(startDelim + DELIM_START.length(), stopDelim);
-    
-        // Verify that this is not a recursive variable reference.
-        if (cycleMap.get(variable) != null) {
-            throw new IllegalArgumentException(
-                    "recursive variable reference: " + variable);
-        }
-    
-        // Get the value of the deepest nested variable placeholder.
-        // Try to configuration properties first.
-        String substValue = (configProps != null)
-                ? configProps.getProperty(variable, null)
-                : null;
-        if (substValue == null) {
-            // Ignore unknown property values.
-            substValue = System.getProperty(variable, "");
-        }
-    
-        // Remove the found variable from the cycle map, since
-        // it may appear more than once in the value and we don't
-        // want such situations to appear as a recursive reference.
-        cycleMap.remove(variable);
-    
-        // Append the leading characters, the substituted value of
-        // the variable, and the trailing characters to get the new
-        // value.
-        val = val.substring(0, startDelim)
-                + substValue
-                + val.substring(stopDelim + DELIM_STOP.length(), val.length());
-    
-        // Now perform substitution again, since there could still
-        // be substitutions to make.
-        val = substVars(val, currentKey, cycleMap, configProps);
-    
-        // Return the value.
-        return val;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/MockLock.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/MockLock.java b/main/src/test/java/org/apache/karaf/main/MockLock.java
index 4bc9ab3..176d8bb 100644
--- a/main/src/test/java/org/apache/karaf/main/MockLock.java
+++ b/main/src/test/java/org/apache/karaf/main/MockLock.java
@@ -1,6 +1,6 @@
 package org.apache.karaf.main;
 
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.logging.Logger;
 
 import org.apache.karaf.main.lock.Lock;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockIntegrationTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockIntegrationTest.java b/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockIntegrationTest.java
index 17fc99f..dc29b70 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockIntegrationTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockIntegrationTest.java
@@ -23,7 +23,7 @@ import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.logging.Logger;
 
 import org.apache.karaf.main.util.BootstrapLogManager;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockTest.java b/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockTest.java
index a45c4a2..0fd32f3 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/BaseJDBCLockTest.java
@@ -28,7 +28,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.util.BootstrapLogManager;
 import org.easymock.EasyMock;
@@ -81,7 +81,7 @@ public abstract class BaseJDBCLockTest {
         props.put("karaf.lock.jdbc.password", password);
         props.put("karaf.lock.jdbc.table", tableName);
         props.put("karaf.lock.jdbc.clustername", clustername);
-        props.put("karaf.lock.jdbc.timeout", timeout);
+        props.put("karaf.lock.jdbc.timeout", Integer.toString(timeout));
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
index eef782a..91c5bc8 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
@@ -20,7 +20,7 @@ package org.apache.karaf.main.lock;
 
 import static org.junit.Assert.assertTrue;
 
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.DefaultJDBCLock;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
index eaafe3d..5705033 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
@@ -21,7 +21,7 @@ package org.apache.karaf.main.lock;
 import static org.junit.Assert.assertEquals;
 
 import java.sql.Connection;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.DefaultJDBCLock;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java b/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java
index d8fb55e..6cbedb9 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java
@@ -20,7 +20,7 @@ package org.apache.karaf.main.lock;
 
 import static org.junit.Assert.assertTrue;
 
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.DefaultJDBCLock;
 import org.apache.karaf.main.lock.DerbyJDBCLock;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java b/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java
index bd6fcec..26cae64 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java
@@ -21,7 +21,7 @@ package org.apache.karaf.main.lock;
 import static org.junit.Assert.assertEquals;
 
 import java.sql.Connection;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.DerbyJDBCLock;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockIntegrationTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockIntegrationTest.java b/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockIntegrationTest.java
index 4bb126d..e22ef09 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockIntegrationTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockIntegrationTest.java
@@ -22,7 +22,7 @@ package org.apache.karaf.main.lock;
 import static org.junit.Assert.assertFalse;
 
 import java.sql.Connection;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.MySQLJDBCLock;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockTest.java b/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockTest.java
index c49e434..842f4e1 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/MySQLJDBCLockTest.java
@@ -21,7 +21,7 @@ package org.apache.karaf.main.lock;
 import static org.junit.Assert.assertEquals;
 
 import java.sql.Connection;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.MySQLJDBCLock;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockIntegrationTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockIntegrationTest.java b/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockIntegrationTest.java
index e2b0ce6..80f105c 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockIntegrationTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockIntegrationTest.java
@@ -22,7 +22,7 @@ package org.apache.karaf.main.lock;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.OracleJDBCLock;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockTest.java b/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockTest.java
index a2242a1..20a8198 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/OracleJDBCLockTest.java
@@ -26,7 +26,7 @@ import static org.junit.Assert.*;
 
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import org.apache.karaf.main.lock.OracleJDBCLock;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockIntegrationTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockIntegrationTest.java b/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockIntegrationTest.java
index dea5ebb..76a9dbc 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockIntegrationTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockIntegrationTest.java
@@ -22,7 +22,7 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import static org.junit.Assert.assertTrue;
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockTest.java b/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockTest.java
index 20aba82..818aafe 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/PostgreSQLJDBCLockTest.java
@@ -23,7 +23,7 @@ import org.junit.Test;
 
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 import static org.easymock.EasyMock.*;
 import static org.junit.Assert.assertEquals;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/main/src/test/java/org/apache/karaf/main/util/BootstrapLogManagerTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/util/BootstrapLogManagerTest.java b/main/src/test/java/org/apache/karaf/main/util/BootstrapLogManagerTest.java
index d9e203c..7eb468a 100644
--- a/main/src/test/java/org/apache/karaf/main/util/BootstrapLogManagerTest.java
+++ b/main/src/test/java/org/apache/karaf/main/util/BootstrapLogManagerTest.java
@@ -19,7 +19,7 @@
 package org.apache.karaf.main.util;
 
 import java.io.File;
-import java.util.Properties;
+import org.apache.karaf.util.properties.Properties;
 import java.util.logging.Handler;
 
 import junit.framework.Assert;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f0373171/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java b/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java
index b64639b..b3d1c32 100644
--- a/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java
+++ b/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java
@@ -24,7 +24,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.nio.channels.FileLock;
-import org.apache.felix.utils.properties.Properties;
+import org.apache.karaf.util.properties.Properties;
 
 public final class FileLockUtils {
 


[3/3] git commit: Fix dev:create-dump command

Posted by gn...@apache.org.
Fix dev:create-dump command


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/abfbc3b1
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/abfbc3b1
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/abfbc3b1

Branch: refs/heads/master
Commit: abfbc3b160c84e837d6b3be7e8e31d1de428a2dd
Parents: 79cf409
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Feb 21 16:04:13 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Feb 21 18:09:52 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/karaf/diagnostic/command/DumpCommand.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/abfbc3b1/diagnostic/command/src/main/java/org/apache/karaf/diagnostic/command/DumpCommand.java
----------------------------------------------------------------------
diff --git a/diagnostic/command/src/main/java/org/apache/karaf/diagnostic/command/DumpCommand.java b/diagnostic/command/src/main/java/org/apache/karaf/diagnostic/command/DumpCommand.java
index 551fc0e..9a0af4c 100644
--- a/diagnostic/command/src/main/java/org/apache/karaf/diagnostic/command/DumpCommand.java
+++ b/diagnostic/command/src/main/java/org/apache/karaf/diagnostic/command/DumpCommand.java
@@ -30,11 +30,13 @@ import org.apache.karaf.diagnostic.core.DumpProvider;
 import org.apache.karaf.diagnostic.core.common.DirectoryDumpDestination;
 import org.apache.karaf.diagnostic.core.common.ZipDumpDestination;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.inject.Service;
 
 /**
  * Command to create dump from shell.
  */
 @Command(scope = "dev", name = "dump-create", description = "Creates zip archive with diagnostic info.")
+@Service
 public class DumpCommand extends OsgiCommandSupport {
 
     /**
@@ -85,7 +87,7 @@ public class DumpCommand extends OsgiCommandSupport {
             provider.createDump(destination);
         }
         destination.save();
-        session.getConsole().println("Diagnostic dump created.");
+        session.getConsole().println("Diagnostic dump created at " + target.getAbsolutePath() + ".");
 
         return null;
     }


[2/3] git commit: [KARAF-2777] Substitution is scattered in various place and the code has bugs

Posted by gn...@apache.org.
[KARAF-2777] Substitution is scattered in various place and the code has bugs


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/f8597953
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/f8597953
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/f8597953

Branch: refs/heads/master
Commit: f8597953bf43e328ad53b0b31dc976f480c3bb09
Parents: abfbc3b
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Feb 21 17:47:11 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Feb 21 18:09:52 2014 +0100

----------------------------------------------------------------------
 instance/core/pom.xml                           |    3 +-
 .../core/internal/InstanceServiceImpl.java      |    3 +-
 .../org/apache/karaf/main/InstanceHelper.java   |    2 +-
 shell/help/pom.xml                              |    2 +-
 .../karaf/shell/help/impl/HelpSystem.java       |    2 +-
 .../apache/karaf/util/InterpolationHelper.java  |  215 ----
 .../apache/karaf/util/locks/FileLockUtils.java  |  110 ++
 .../karaf/util/properties/FileLockUtils.java    |  110 --
 .../util/properties/InterpolationHelper.java    |  325 ++++++
 .../karaf/util/properties/Properties.java       | 1102 ++++++++++++++++++
 10 files changed, 1543 insertions(+), 331 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/instance/core/pom.xml
----------------------------------------------------------------------
diff --git a/instance/core/pom.xml b/instance/core/pom.xml
index 00a112e..45844e4 100644
--- a/instance/core/pom.xml
+++ b/instance/core/pom.xml
@@ -153,7 +153,8 @@
                             org.apache.karaf.jpm.impl,
                             org.apache.karaf.instance.core.internal,
                             org.apache.felix.utils.properties;-split-package:=merge-first,
-                            org.apache.karaf.util.properties
+                            org.apache.karaf.util.properties,
+                            org.apache.karaf.util.locks
                         </Private-Package>
                     </instructions>
                 </configuration>

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
index c232e34..1d3e922 100644
--- a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
@@ -22,7 +22,7 @@ import org.apache.karaf.instance.core.InstanceSettings;
 import org.apache.karaf.jpm.Process;
 import org.apache.karaf.jpm.impl.ProcessBuilderFactoryImpl;
 import org.apache.karaf.jpm.impl.ScriptUtils;
-import org.apache.karaf.util.properties.FileLockUtils;
+import org.apache.karaf.util.locks.FileLockUtils;
 import org.fusesource.jansi.Ansi;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,7 +41,6 @@ import java.io.PrintStream;
 import java.net.Socket;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.LinkedHashMap;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
index 93f3d2c..31329e5 100644
--- a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
+++ b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
@@ -32,7 +32,7 @@ import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.karaf.util.properties.FileLockUtils;
+import org.apache.karaf.util.locks.FileLockUtils;
 import org.osgi.framework.launch.Framework;
 
 public class InstanceHelper {

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/shell/help/pom.xml
----------------------------------------------------------------------
diff --git a/shell/help/pom.xml b/shell/help/pom.xml
index ef3fe18..78952da 100644
--- a/shell/help/pom.xml
+++ b/shell/help/pom.xml
@@ -110,7 +110,7 @@
                         </Export-Package>
                         <Private-Package>
                             org.apache.karaf.util.process;-split-package:=merge-first,
-                            org.apache.karaf.util;-split-package:=merge-first,
+                            org.apache.karaf.util.properties;-split-package:=merge-first,
                             org.apache.karaf.shell.help.impl*
                         </Private-Package>
                     </instructions>

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/shell/help/src/main/java/org/apache/karaf/shell/help/impl/HelpSystem.java
----------------------------------------------------------------------
diff --git a/shell/help/src/main/java/org/apache/karaf/shell/help/impl/HelpSystem.java b/shell/help/src/main/java/org/apache/karaf/shell/help/impl/HelpSystem.java
index fdb2738..d88a747 100644
--- a/shell/help/src/main/java/org/apache/karaf/shell/help/impl/HelpSystem.java
+++ b/shell/help/src/main/java/org/apache/karaf/shell/help/impl/HelpSystem.java
@@ -25,7 +25,7 @@ import java.util.Map;
 
 import org.apache.felix.service.command.CommandSession;
 import org.apache.karaf.shell.console.HelpProvider;
-import org.apache.karaf.util.InterpolationHelper;
+import org.apache.karaf.util.properties.InterpolationHelper;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/util/src/main/java/org/apache/karaf/util/InterpolationHelper.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/InterpolationHelper.java b/util/src/main/java/org/apache/karaf/util/InterpolationHelper.java
deleted file mode 100644
index 6fb64b9..0000000
--- a/util/src/main/java/org/apache/karaf/util/InterpolationHelper.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.util;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.osgi.framework.BundleContext;
-
-/**
- * Enhancement of the standard <code>Properties</code>
- * managing the maintain of comments, etc.
- */
-public class InterpolationHelper {
-
-    private InterpolationHelper() {
-    }
-
-    private static final char ESCAPE_CHAR = '\\';
-    private static final String DELIM_START = "${";
-    private static final String DELIM_STOP = "}";
-
-
-    /**
-     * Callback for substitution
-     */
-    public interface SubstitutionCallback {
-
-        public String getValue(String key);
-
-    }
-
-    /**
-     * Perform substitution on a property set
-     *
-     * @param properties the property set to perform substitution on
-     */
-    public static void performSubstitution(Map<String, String> properties) {
-        performSubstitution(properties, (BundleContext) null);
-    }
-
-    /**
-     * Perform substitution on a property set
-     *
-     * @param properties the property set to perform substitution on
-     */
-    public static void performSubstitution(Map<String, String> properties, final BundleContext context) {
-        performSubstitution(properties, new SubstitutionCallback() {
-            public String getValue(String key) {
-                String value = null;
-                if (context != null) {
-                    value = context.getProperty(key);
-                }
-                if (value == null) {
-                    value = System.getProperty(value, "");
-                }
-                return value;
-            }
-        });
-    }
-
-    /**
-     * Perform substitution on a property set
-     *
-     * @param properties the property set to perform substitution on
-     */
-    public static void performSubstitution(Map<String, String> properties, SubstitutionCallback callback) {
-        for (String name : properties.keySet()) {
-            String value = properties.get(name);
-            properties.put(name, substVars(value, name, null, properties, callback));
-        }
-    }
-
-
-    /**
-     * <p>
-     * This method performs property variable substitution on the
-     * specified value. If the specified value contains the syntax
-     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
-     * refers to either a configuration property or a system property,
-     * then the corresponding property value is substituted for the variable
-     * placeholder. Multiple variable placeholders may exist in the
-     * specified value as well as nested variable placeholders, which
-     * are substituted from inner most to outer most. Configuration
-     * properties override system properties.
-     * </p>
-     *
-     * @param val         The string on which to perform property substitution.
-     * @param currentKey  The key of the property being evaluated used to
-     *                    detect cycles.
-     * @param cycleMap    Map of variable references used to detect nested cycles.
-     * @param configProps Set of configuration properties.
-     * @param callback    the callback to obtain substitution values
-     * @return The value of the specified string after system property substitution.
-     * @throws IllegalArgumentException If there was a syntax error in the
-     *                                  property placeholder syntax or a recursive variable reference.
-     */
-    public static String substVars(String val,
-                                   String currentKey,
-                                   Map<String, String> cycleMap,
-                                   Map<String, String> configProps,
-                                   SubstitutionCallback callback)
-            throws IllegalArgumentException {
-        if (cycleMap == null) {
-            cycleMap = new HashMap<String, String>();
-        }
-
-        // Put the current key in the cycle map.
-        cycleMap.put(currentKey, currentKey);
-
-        // Assume we have a value that is something like:
-        // "leading ${foo.${bar}} middle ${baz} trailing"
-
-        // Find the first ending '}' variable delimiter, which
-        // will correspond to the first deepest nested variable
-        // placeholder.
-        int stopDelim = val.indexOf(DELIM_STOP);
-        while (stopDelim > 0 && val.charAt(stopDelim - 1) == ESCAPE_CHAR) {
-            stopDelim = val.indexOf(DELIM_STOP, stopDelim + 1);
-        }
-
-        // Find the matching starting "${" variable delimiter
-        // by looping until we find a start delimiter that is
-        // greater than the stop delimiter we have found.
-        int startDelim = val.indexOf(DELIM_START);
-        while (stopDelim >= 0) {
-            int idx = val.indexOf(DELIM_START, startDelim + DELIM_START.length());
-            if ((idx < 0) || (idx > stopDelim)) {
-                break;
-            } else if (idx < stopDelim) {
-                startDelim = idx;
-            }
-        }
-
-        // If we do not have a start or stop delimiter, then just
-        // return the existing value.
-        if ((startDelim < 0) || (stopDelim < 0)) {
-            return unescape(val);
-        }
-
-        // At this point, we have found a variable placeholder so
-        // we must perform a variable substitution on it.
-        // Using the start and stop delimiter indices, extract
-        // the first, deepest nested variable placeholder.
-        String variable = val.substring(startDelim + DELIM_START.length(), stopDelim);
-
-        // Verify that this is not a recursive variable reference.
-        if (cycleMap.get(variable) != null) {
-            throw new IllegalArgumentException("recursive variable reference: " + variable);
-        }
-
-        // Get the value of the deepest nested variable placeholder.
-        // Try to configuration properties first.
-        String substValue = (String) ((configProps != null) ? configProps.get(variable) : null);
-        if (substValue == null) {
-            if (variable.length() <= 0) {
-                substValue = "";
-            } else {
-                if (callback != null) {
-                    substValue = callback.getValue(variable);
-                }
-                if (substValue == null) {
-                    substValue = System.getProperty(variable, "");
-                }
-            }
-        }
-
-        // Remove the found variable from the cycle map, since
-        // it may appear more than once in the value and we don't
-        // want such situations to appear as a recursive reference.
-        cycleMap.remove(variable);
-
-        // Append the leading characters, the substituted value of
-        // the variable, and the trailing characters to get the new
-        // value.
-        val = val.substring(0, startDelim) + substValue + val.substring(stopDelim + DELIM_STOP.length(), val.length());
-
-        // Now perform substitution again, since there could still
-        // be substitutions to make.
-        val = substVars(val, currentKey, cycleMap, configProps, callback);
-
-        // Remove escape characters preceding {, } and \
-        val = unescape(val);
-
-        // Return the value.
-        return val;
-    }
-
-    private static String unescape(String val) {
-        int escape = val.indexOf(ESCAPE_CHAR);
-        while (escape >= 0 && escape < val.length() - 1) {
-            char c = val.charAt(escape + 1);
-            if (c == '{' || c == '}' || c == ESCAPE_CHAR) {
-                val = val.substring(0, escape) + val.substring(escape + 1);
-            }
-            escape = val.indexOf(ESCAPE_CHAR, escape + 1);
-        }
-        return val;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java b/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java
new file mode 100644
index 0000000..b64639b
--- /dev/null
+++ b/util/src/main/java/org/apache/karaf/util/locks/FileLockUtils.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.karaf.util.locks;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileLock;
+import org.apache.felix.utils.properties.Properties;
+
+public final class FileLockUtils {
+
+    private FileLockUtils() { }
+
+    public static interface Runnable {
+        void run(RandomAccessFile file) throws IOException;
+    }
+
+    public static interface Callable<T> {
+        T call(RandomAccessFile file) throws IOException;
+    }
+
+    public static interface RunnableWithProperties {
+        void run(Properties properties) throws IOException;
+    }
+
+    public static interface CallableWithProperties<T> {
+        T call(Properties properties) throws IOException;
+    }
+
+    public static void execute(File file, Runnable callback) throws IOException {
+        RandomAccessFile raf = new RandomAccessFile(file, "rw");
+        try {
+            FileLock lock = raf.getChannel().lock();
+            try {
+                callback.run(raf);
+            } finally {
+                lock.release();
+            }
+        } finally {
+            raf.close();
+        }
+    }
+
+    public static <T> T execute(File file, Callable<T> callback) throws IOException {
+        RandomAccessFile raf = new RandomAccessFile(file, "rw");
+        try {
+            FileLock lock = raf.getChannel().lock();
+            try {
+                return callback.call(raf);
+            } finally {
+                lock.release();
+            }
+        } finally {
+            raf.close();
+        }
+    }
+
+    public static void execute(File file, final RunnableWithProperties callback) throws IOException {
+        execute(file, new Runnable() {
+            public void run(RandomAccessFile file) throws IOException {
+                byte[] buffer = new byte[(int) file.length()];
+                file.readFully(buffer);
+                Properties props = new Properties();
+                props.load(new ByteArrayInputStream(buffer));
+                callback.run(props);
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                props.store(baos, null);
+                file.setLength(0);
+                file.write(baos.toByteArray());
+            }
+        });
+    }
+
+    public static <T> T execute(File file, final CallableWithProperties<T> callback) throws IOException {
+        return execute(file, new Callable<T>() {
+            public T call(RandomAccessFile file) throws IOException {
+                byte[] buffer = new byte[(int) file.length()];
+                file.readFully(buffer);
+                Properties props = new Properties();
+                props.load(new ByteArrayInputStream(buffer));
+                T result = callback.call(props);
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                props.store(baos, null);
+                file.setLength(0);
+                file.write(baos.toByteArray());
+                return result;
+            }
+        });
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/util/src/main/java/org/apache/karaf/util/properties/FileLockUtils.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/properties/FileLockUtils.java b/util/src/main/java/org/apache/karaf/util/properties/FileLockUtils.java
deleted file mode 100644
index 1e72e34..0000000
--- a/util/src/main/java/org/apache/karaf/util/properties/FileLockUtils.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.karaf.util.properties;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileLock;
-import org.apache.felix.utils.properties.Properties;
-
-public final class FileLockUtils {
-
-    private FileLockUtils() { }
-
-    public static interface Runnable {
-        void run(RandomAccessFile file) throws IOException;
-    }
-
-    public static interface Callable<T> {
-        T call(RandomAccessFile file) throws IOException;
-    }
-
-    public static interface RunnableWithProperties {
-        void run(Properties properties) throws IOException;
-    }
-
-    public static interface CallableWithProperties<T> {
-        T call(Properties properties) throws IOException;
-    }
-
-    public static void execute(File file, Runnable callback) throws IOException {
-        RandomAccessFile raf = new RandomAccessFile(file, "rw");
-        try {
-            FileLock lock = raf.getChannel().lock();
-            try {
-                callback.run(raf);
-            } finally {
-                lock.release();
-            }
-        } finally {
-            raf.close();
-        }
-    }
-
-    public static <T> T execute(File file, Callable<T> callback) throws IOException {
-        RandomAccessFile raf = new RandomAccessFile(file, "rw");
-        try {
-            FileLock lock = raf.getChannel().lock();
-            try {
-                return callback.call(raf);
-            } finally {
-                lock.release();
-            }
-        } finally {
-            raf.close();
-        }
-    }
-
-    public static void execute(File file, final RunnableWithProperties callback) throws IOException {
-        execute(file, new Runnable() {
-            public void run(RandomAccessFile file) throws IOException {
-                byte[] buffer = new byte[(int) file.length()];
-                file.readFully(buffer);
-                Properties props = new Properties();
-                props.load(new ByteArrayInputStream(buffer));
-                callback.run(props);
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                props.store(baos, null);
-                file.setLength(0);
-                file.write(baos.toByteArray());
-            }
-        });
-    }
-
-    public static <T> T execute(File file, final CallableWithProperties<T> callback) throws IOException {
-        return execute(file, new Callable<T>() {
-            public T call(RandomAccessFile file) throws IOException {
-                byte[] buffer = new byte[(int) file.length()];
-                file.readFully(buffer);
-                Properties props = new Properties();
-                props.load(new ByteArrayInputStream(buffer));
-                T result = callback.call(props);
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                props.store(baos, null);
-                file.setLength(0);
-                file.write(baos.toByteArray());
-                return result;
-            }
-        });
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/util/src/main/java/org/apache/karaf/util/properties/InterpolationHelper.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/properties/InterpolationHelper.java b/util/src/main/java/org/apache/karaf/util/properties/InterpolationHelper.java
new file mode 100644
index 0000000..b59dda5
--- /dev/null
+++ b/util/src/main/java/org/apache/karaf/util/properties/InterpolationHelper.java
@@ -0,0 +1,325 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.util.properties;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * <p>
+ * Enhancement of the standard <code>Properties</code>
+ * managing the maintain of comments, etc.
+ * </p>
+ *
+ * @author gnodet, jbonofre
+ */
+public class InterpolationHelper {
+
+    private InterpolationHelper() {
+    }
+
+    private static final char   ESCAPE_CHAR = '\\';
+    private static final String DELIM_START = "${";
+    private static final String DELIM_STOP = "}";
+
+
+    /**
+     * Callback for substitution
+     */
+    public interface SubstitutionCallback {
+
+        public String getValue(String key);
+
+    }
+
+    /**
+     * Perform substitution on a property set
+     *
+     * @param properties the property set to perform substitution on
+     */
+    public static void performSubstitution(Map<String,String> properties)
+    {
+        performSubstitution(properties, (BundleContext) null);
+    }
+
+    /**
+     * Perform substitution on a property set
+     *
+     * @param properties the property set to perform substitution on
+     */
+    public static void performSubstitution(Map<String,String> properties, BundleContext context)
+    {
+        performSubstitution(properties, new BundleContextSubstitutionCallback(context));
+    }
+
+    /**
+     * Perform substitution on a property set
+     *
+     * @param properties the property set to perform substitution on
+     */
+    public static void performSubstitution(Map<String,String> properties, SubstitutionCallback callback)
+    {
+        Map<String, String> org = new HashMap<String, String>(properties);
+        for (String name : properties.keySet())
+        {
+            String value = properties.get(name);
+            properties.put(name, substVars(value, name, null, org, callback));
+        }
+    }
+
+    /**
+     * <p>
+     * This method performs property variable substitution on the
+     * specified value. If the specified value contains the syntax
+     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
+     * refers to either a configuration property or a system property,
+     * then the corresponding property value is substituted for the variable
+     * placeholder. Multiple variable placeholders may exist in the
+     * specified value as well as nested variable placeholders, which
+     * are substituted from inner most to outer most. Configuration
+     * properties override system properties.
+     * </p>
+     *
+     * @param val The string on which to perform property substitution.
+     * @param currentKey The key of the property being evaluated used to
+     *        detect cycles.
+     * @param cycleMap Map of variable references used to detect nested cycles.
+     * @param configProps Set of configuration properties.
+     * @return The value of the specified string after system property substitution.
+     * @throws IllegalArgumentException If there was a syntax error in the
+     *         property placeholder syntax or a recursive variable reference.
+     **/
+    public static String substVars(String val,
+                                   String currentKey,
+                                   Map<String,String> cycleMap,
+                                   Map<String,String> configProps)
+            throws IllegalArgumentException
+    {
+        return substVars(val, currentKey, cycleMap, configProps, (SubstitutionCallback) null);
+    }
+
+    /**
+     * <p>
+     * This method performs property variable substitution on the
+     * specified value. If the specified value contains the syntax
+     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
+     * refers to either a configuration property or a system property,
+     * then the corresponding property value is substituted for the variable
+     * placeholder. Multiple variable placeholders may exist in the
+     * specified value as well as nested variable placeholders, which
+     * are substituted from inner most to outer most. Configuration
+     * properties override system properties.
+     * </p>
+     *
+     * @param val The string on which to perform property substitution.
+     * @param currentKey The key of the property being evaluated used to
+     *        detect cycles.
+     * @param cycleMap Map of variable references used to detect nested cycles.
+     * @param configProps Set of configuration properties.
+     * @param context the bundle context to retrieve properties from
+     * @return The value of the specified string after system property substitution.
+     * @throws IllegalArgumentException If there was a syntax error in the
+     *         property placeholder syntax or a recursive variable reference.
+     **/
+    public static String substVars(String val,
+                                   String currentKey,
+                                   Map<String,String> cycleMap,
+                                   Map<String,String> configProps,
+                                   BundleContext context)
+            throws IllegalArgumentException
+    {
+        return substVars(val, currentKey, cycleMap, configProps, new BundleContextSubstitutionCallback(context));
+    }
+
+    /**
+     * <p>
+     * This method performs property variable substitution on the
+     * specified value. If the specified value contains the syntax
+     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
+     * refers to either a configuration property or a system property,
+     * then the corresponding property value is substituted for the variable
+     * placeholder. Multiple variable placeholders may exist in the
+     * specified value as well as nested variable placeholders, which
+     * are substituted from inner most to outer most. Configuration
+     * properties override system properties.
+     * </p>
+     *
+     * @param val The string on which to perform property substitution.
+     * @param currentKey The key of the property being evaluated used to
+     *        detect cycles.
+     * @param cycleMap Map of variable references used to detect nested cycles.
+     * @param configProps Set of configuration properties.
+     * @param callback the callback to obtain substitution values
+     * @return The value of the specified string after system property substitution.
+     * @throws IllegalArgumentException If there was a syntax error in the
+     *         property placeholder syntax or a recursive variable reference.
+     **/
+    public static String substVars(String val,
+                                   String currentKey,
+                                   Map<String,String> cycleMap,
+                                   Map<String,String> configProps,
+                                   SubstitutionCallback callback)
+            throws IllegalArgumentException
+    {
+        return unescape(doSubstVars(val, currentKey, cycleMap, configProps, callback));
+    }
+
+    private static String doSubstVars(String val,
+                                      String currentKey,
+                                      Map<String,String> cycleMap,
+                                      Map<String,String> configProps,
+                                      SubstitutionCallback callback)
+            throws IllegalArgumentException
+    {
+        if (cycleMap == null)
+        {
+            cycleMap = new HashMap<String,String>();
+        }
+
+        // Put the current key in the cycle map.
+        cycleMap.put(currentKey, currentKey);
+
+        // Assume we have a value that is something like:
+        // "leading ${foo.${bar}} middle ${baz} trailing"
+
+        // Find the first ending '}' variable delimiter, which
+        // will correspond to the first deepest nested variable
+        // placeholder.
+        int stopDelim = val.indexOf(DELIM_STOP);
+        while (stopDelim > 0 && val.charAt(stopDelim - 1) == ESCAPE_CHAR)
+        {
+            stopDelim = val.indexOf(DELIM_STOP, stopDelim + 1);
+        }
+
+        // Find the matching starting "${" variable delimiter
+        // by looping until we find a start delimiter that is
+        // greater than the stop delimiter we have found.
+        int startDelim = val.indexOf(DELIM_START);
+        while (stopDelim >= 0)
+        {
+            int idx = val.indexOf(DELIM_START, startDelim + DELIM_START.length());
+            if ((idx < 0) || (idx > stopDelim))
+            {
+                break;
+            }
+            else if (idx < stopDelim)
+            {
+                startDelim = idx;
+            }
+        }
+
+        // If we do not have a start or stop delimiter, then just
+        // return the existing value.
+        if ((startDelim < 0) || (stopDelim < 0))
+        {
+            return val;
+        }
+
+        // At this point, we have found a variable placeholder so
+        // we must perform a variable substitution on it.
+        // Using the start and stop delimiter indices, extract
+        // the first, deepest nested variable placeholder.
+        String variable = val.substring(startDelim + DELIM_START.length(), stopDelim);
+
+        // Verify that this is not a recursive variable reference.
+        if (cycleMap.get(variable) != null)
+        {
+            throw new IllegalArgumentException("recursive variable reference: " + variable);
+        }
+
+        // Get the value of the deepest nested variable placeholder.
+        // Try to configuration properties first.
+        String substValue = (String) ((configProps != null) ? configProps.get(variable) : null);
+        if (substValue == null)
+        {
+            if (variable.length() <= 0)
+            {
+                substValue = "";
+            }
+            else
+            {
+                if (callback != null)
+                {
+                    substValue = callback.getValue(variable);
+                }
+                if (substValue == null)
+                {
+                    substValue = System.getProperty(variable, "");
+                }
+            }
+        }
+
+        // Remove the found variable from the cycle map, since
+        // it may appear more than once in the value and we don't
+        // want such situations to appear as a recursive reference.
+        cycleMap.remove(variable);
+
+        // Append the leading characters, the substituted value of
+        // the variable, and the trailing characters to get the new
+        // value.
+        val = val.substring(0, startDelim) + substValue + val.substring(stopDelim + DELIM_STOP.length(), val.length());
+
+        // Now perform substitution again, since there could still
+        // be substitutions to make.
+        val = doSubstVars(val, currentKey, cycleMap, configProps, callback);
+
+        // Return the value.
+        return val;
+    }
+
+    private static String unescape(String val)
+    {
+        int escape = val.indexOf(ESCAPE_CHAR);
+        while (escape >= 0 && escape < val.length() - 1)
+        {
+            char c = val.charAt(escape + 1);
+            if (c == '{' || c == '}' || c == ESCAPE_CHAR)
+            {
+                val = val.substring(0, escape) + val.substring(escape + 1);
+            }
+            escape = val.indexOf(ESCAPE_CHAR, escape + 1);
+        }
+        return val;
+    }
+
+    static class BundleContextSubstitutionCallback implements SubstitutionCallback
+    {
+        private final BundleContext context;
+
+        public BundleContextSubstitutionCallback(BundleContext context)
+        {
+            this.context = context;
+        }
+
+        public String getValue(String key)
+        {
+            String value = null;
+            if (context != null)
+            {
+                value = context.getProperty(key);
+            }
+            if (value == null)
+            {
+                value = System.getProperty(key, "");
+            }
+            return value;
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf/blob/f8597953/util/src/main/java/org/apache/karaf/util/properties/Properties.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/properties/Properties.java b/util/src/main/java/org/apache/karaf/util/properties/Properties.java
new file mode 100644
index 0000000..dffc3f2
--- /dev/null
+++ b/util/src/main/java/org/apache/karaf/util/properties/Properties.java
@@ -0,0 +1,1102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.util.properties;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * <p>
+ * Enhancement of the standard <code>Properties</code>
+ * managing the maintain of comments, etc.
+ * </p>
+ *
+ * @author gnodet, jbonofre
+ */
+public class Properties extends AbstractMap<String, String> {
+
+    /** Constant for the supported comment characters.*/
+    private static final String COMMENT_CHARS = "#!";
+
+    /** The list of possible key/value separators */
+    private static final char[] SEPARATORS = new char[] {'=', ':'};
+
+    /** The white space characters used as key/value separators. */
+    private static final char[] WHITE_SPACE = new char[] {' ', '\t', '\f'};
+
+    /**
+     * The default encoding (ISO-8859-1 as specified by
+     * http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html)
+     */
+    private static final String DEFAULT_ENCODING = "ISO-8859-1";
+
+    /** Constant for the platform specific line separator.*/
+    private static final String LINE_SEPARATOR = AccessController.doPrivileged(new PrivilegedAction<String>() {
+        public String run() {
+            return System.getProperty("line.separator");
+        }
+    });
+
+    /** Constant for the radix of hex numbers.*/
+    private static final int HEX_RADIX = 16;
+
+    /** Constant for the length of a unicode literal.*/
+    private static final int UNICODE_LEN = 4;
+
+    private final Map<String,String> storage = new LinkedHashMap<String,String>();
+    private final Map<String,Layout> layout = new LinkedHashMap<String,Layout>();
+    private List<String> header;
+    private List<String> footer;
+    private File location;
+    private InterpolationHelper.SubstitutionCallback callback;
+    private boolean substitute = true;
+
+    public Properties() {
+    }
+
+    public Properties(File location) throws IOException {
+      this(location, (InterpolationHelper.SubstitutionCallback) null);
+    }
+
+    public Properties(File location, BundleContext context) throws IOException {
+        this(location, new InterpolationHelper.BundleContextSubstitutionCallback(context));
+    }
+
+    public Properties(File location, InterpolationHelper.SubstitutionCallback callback) throws IOException {
+        this.location = location;
+        this.callback = callback;
+        if(location.exists())
+            load(location);
+    }
+
+    public Properties(boolean substitute) throws IOException {
+        this.substitute = substitute;
+    }
+
+    public Properties(File location, boolean substitute) throws IOException {
+        this.location = location;
+        this.substitute = substitute;
+    }
+
+    public void load(File location) throws IOException {
+        InputStream is = new FileInputStream(location);
+        try {
+            load(is);
+        } finally {
+            is.close();
+        }
+    }
+
+    public void load(URL location) throws IOException {
+        InputStream is = location.openStream();
+        try {
+            load(is);
+        } finally {
+            is.close();
+        }
+    }
+
+    public void load(InputStream is) throws IOException {
+        load(new InputStreamReader(is, DEFAULT_ENCODING));
+    }
+
+    public void load(Reader reader) throws IOException {
+        loadLayout(reader);
+    }
+
+    public void save() throws IOException {
+        save(this.location);
+    }
+
+    public void save(File location) throws IOException {
+        OutputStream os = new FileOutputStream(location);
+        try {
+            save(os);
+        } finally {
+            os.close();
+        }
+    }
+
+    public void save(OutputStream os) throws IOException {
+        save(new OutputStreamWriter(os, DEFAULT_ENCODING));
+    }
+
+    public void save(Writer writer) throws IOException {
+        saveLayout(writer);
+    }
+
+    /**
+     * Store a properties into a output stream, preserving comments, special character, etc.
+     * This method is mainly to be compatible with the java.util.Properties class.
+     *
+     * @param os an output stream.
+     * @param comment this parameter is ignored as this Properties
+     * @throws java.io.IOException
+     */
+    public void store(OutputStream os, String comment) throws IOException {
+        this.save(os);
+    }
+
+    /**
+     * Searches for the property with the specified key in this property list.
+     *
+     * @param key the property key.
+     * @return the value in this property list with the specified key value.
+     */
+    public String getProperty(String key) {
+        return this.get(key);
+    }
+
+    /**
+     * Searches for the property with the specified key in this property list. If the key is not found in this property
+     * list, the default property list, and its defaults, recursively, are then checked. The method returns the default
+     * value argument if the property is not found.
+     *
+     * @param key the property key.
+     * @param defaultValue a default value.
+     * @return
+     */
+    public String getProperty(String key, String defaultValue) {
+        if (this.get(key) != null)
+            return this.get(key);
+        return defaultValue;
+    }
+
+    @Override
+    public Set<Entry<String, String>> entrySet() {
+        return storage.entrySet();
+    }
+
+    /**
+     * Returns an enumeration of all the keys in this property list, including distinct keys in the default property
+     * list if a key of the same name has not already been found from the main properties list.
+     *
+     * @return an enumeration of all the keys in this property list, including the keys in the default property list.
+     */
+    public Enumeration<?> propertyNames() {
+        return Collections.enumeration(storage.keySet());
+    }
+
+    /**
+     * Calls the map method put. Provided for parallelism with the getProperty method.
+     * Enforces use of strings for property keys and values. The value returned is the result of the map call to put.
+     *
+     * @param key the key to be placed into this property list.
+     * @param value the value corresponding to the key.
+     * @return the previous value of the specified key in this property list, or null if it did not have one.
+     */
+    public Object setProperty(String key, String value) {
+        return this.put(key, value);
+    }
+
+    @Override
+    public String put(String key, String value) {
+        String old = storage.put(key, value);
+        if (old == null || !old.equals(value)) {
+            Layout l = layout.get(key);
+            if (l != null) {
+                l.clearValue();
+            }
+        }
+        return old;
+    }
+
+    public String put(String key, List<String> commentLines, List<String> valueLines) {
+        commentLines = new ArrayList<String>(commentLines);
+        valueLines = new ArrayList<String>(valueLines);
+        String escapedKey = escapeKey(key);
+        int lastLine = valueLines.size() - 1;
+        if (valueLines.isEmpty()) {
+            valueLines.add(escapedKey + "=");
+        } else if (!valueLines.get(0).trim().startsWith(escapedKey)) {
+            valueLines.set(0, escapedKey + " = " + escapeJava(valueLines.get(0)) + (0 < lastLine? "\\": ""));
+        }
+        for (int i = 1; i < valueLines.size(); i++) {
+            valueLines.set(i, escapeJava(valueLines.get(i)) + (i < lastLine? "\\": ""));
+        }
+        StringBuilder value = new StringBuilder();
+        for (String line: valueLines) {
+            value.append(line);
+        }
+        this.layout.put(key, new Layout(commentLines, valueLines));
+        return storage.put(key, unescapeJava(value.toString()));
+    }
+
+    public String put(String key, List<String> commentLines, String value) {
+        commentLines = new ArrayList<String>(commentLines);
+        this.layout.put(key, new Layout(commentLines, null));
+        return storage.put(key, value);
+    }
+
+    public String put(String key, String comment, String value) {
+        return put(key, Collections.singletonList(comment), value);
+    }
+
+    public List<String> getRaw(String key) {
+        if (layout.containsKey(key)) {
+            if (layout.get(key).getValueLines() != null) {
+                return new ArrayList<String>(layout.get(key).getValueLines());
+            }
+        }
+        List<String> result = new ArrayList<String>();
+        if (storage.containsKey(key)) {
+            result.add(storage.get(key));
+        }
+        return result;
+    }
+
+    @Override
+    public String remove(Object key) {
+        Layout l = layout.get(key);
+        if (l != null) {
+            l.clearValue();
+        }
+        return storage.remove(key);
+    }
+
+    @Override
+    public void clear() {
+        for (Layout l : layout.values()) {
+            l.clearValue();
+        }
+        storage.clear();
+    }
+
+    /**
+     * Return the comment header.
+     *
+     * @return the comment header
+     */
+    public List<String> getHeader()
+    {
+        return header;
+    }
+
+    /**
+     * Set the comment header.
+     *
+     * @param header the header to use
+     */
+    public void setHeader(List<String> header)
+    {
+        this.header = header;
+    }
+
+    /**
+     * Return the comment footer.
+     *
+     * @return the comment footer
+     */
+    public List<String> getFooter()
+    {
+        return footer;
+    }
+
+    /**
+     * Set the comment footer.
+     *
+     * @param footer the footer to use
+     */
+    public void setFooter(List<String> footer)
+    {
+        this.footer = footer;
+    }
+
+    /**
+     * Reads a properties file and stores its internal structure. The found
+     * properties will be added to the associated configuration object.
+     *
+     * @param in the reader to the properties file
+     * @throws java.io.IOException if an error occurs
+     */
+    protected void loadLayout(Reader in) throws IOException
+    {
+        PropertiesReader reader = new PropertiesReader(in);
+        while (reader.nextProperty())
+        {
+            storage.put(reader.getPropertyName(), reader.getPropertyValue());
+            int idx = checkHeaderComment(reader.getCommentLines());
+            layout.put(reader.getPropertyName(),
+                    new Layout(idx < reader.getCommentLines().size() ?
+                                    new ArrayList<String>(reader.getCommentLines().subList(idx, reader.getCommentLines().size())) :
+                                    null,
+                               new ArrayList<String>(reader.getValueLines())));
+        }
+        footer = new ArrayList<String>(reader.getCommentLines());
+        if (substitute)
+        {
+            substitute();
+        }
+    }
+
+    public void substitute()
+    {
+        substitute(callback);
+    }
+
+    public void substitute(InterpolationHelper.SubstitutionCallback callback)
+    {
+        if(callback != null)
+        {
+            InterpolationHelper.performSubstitution(storage, callback);
+        }
+        else {
+            InterpolationHelper.performSubstitution(storage);
+        }
+
+    }
+
+    /**
+     * Writes the properties file to the given writer, preserving as much of its
+     * structure as possible.
+     *
+     * @param out the writer
+     * @throws java.io.IOException if an error occurs
+     */
+    protected void saveLayout(Writer out) throws IOException
+    {
+        PropertiesWriter writer = new PropertiesWriter(out);
+        if (header != null)
+        {
+            for (String s : header)
+            {
+                writer.writeln(s);
+            }
+        }
+
+        for (String key : storage.keySet())
+        {
+            Layout l = layout.get(key);
+            if (l != null && l.getCommentLines() != null)
+            {
+                for (String s : l.getCommentLines())
+                {
+                    writer.writeln(s);
+                }
+            }
+            if (l != null && l.getValueLines() != null)
+            {
+                for (String s : l.getValueLines())
+                {
+                    writer.writeln(s);
+                }
+            }
+            else
+            {
+                writer.writeProperty(key, storage.get(key));
+            }
+        }
+        if (footer != null)
+        {
+            for (String s : footer)
+            {
+                writer.writeln(s);
+            }
+        }
+        writer.flush();
+    }
+
+    /**
+     * Checks if parts of the passed in comment can be used as header comment.
+     * This method checks whether a header comment can be defined (i.e. whether
+     * this is the first comment in the loaded file). If this is the case, it is
+     * searched for the lates blank line. This line will mark the end of the
+     * header comment. The return value is the index of the first line in the
+     * passed in list, which does not belong to the header comment.
+     *
+     * @param commentLines the comment lines
+     * @return the index of the next line after the header comment
+     */
+    private int checkHeaderComment(List<String> commentLines)
+    {
+        if (getHeader() == null && layout.isEmpty())
+        {
+            // This is the first comment. Search for blank lines.
+            int index = commentLines.size() - 1;
+            while (index >= 0 && commentLines.get(index).length() > 0)
+            {
+                index--;
+            }
+            setHeader(new ArrayList<String>(commentLines.subList(0, index + 1)));
+            return index + 1;
+        }
+        else
+        {
+            return 0;
+        }
+    }
+
+    /**
+     * Tests whether a line is a comment, i.e. whether it starts with a comment
+     * character.
+     *
+     * @param line the line
+     * @return a flag if this is a comment line
+     */
+    static boolean isCommentLine(String line) {
+        String s = line.trim();
+        // blank lines are also treated as comment lines
+        return s.length() < 1 || COMMENT_CHARS.indexOf(s.charAt(0)) >= 0;
+    }
+
+    /**
+     * <p>Unescapes any Java literals found in the <code>String</code> to a
+     * <code>Writer</code>.</p> This is a slightly modified version of the
+     * StringEscapeUtils.unescapeJava() function in commons-lang that doesn't
+     * drop escaped separators (i.e '\,').
+     *
+     * @param str  the <code>String</code> to unescape, may be null
+     * @return the processed string
+     * @throws IllegalArgumentException if the Writer is <code>null</code>
+     */
+    protected static String unescapeJava(String str) {
+        if (str == null) {
+            return null;
+        }
+        int sz = str.length();
+        StringBuffer out = new StringBuffer(sz);
+        StringBuffer unicode = new StringBuffer(UNICODE_LEN);
+        boolean hadSlash = false;
+        boolean inUnicode = false;
+        for (int i = 0; i < sz; i++) {
+            char ch = str.charAt(i);
+            if (inUnicode) {
+                // if in unicode, then we're reading unicode
+                // values in somehow
+                unicode.append(ch);
+                if (unicode.length() == UNICODE_LEN) {
+                    // unicode now contains the four hex digits
+                    // which represents our unicode character
+                    try {
+                        int value = Integer.parseInt(unicode.toString(), HEX_RADIX);
+                        out.append((char) value);
+                        unicode.setLength(0);
+                        inUnicode = false;
+                        hadSlash = false;
+                    } catch (NumberFormatException nfe) {
+                        throw new IllegalArgumentException("Unable to parse unicode value: " + unicode, nfe);
+                    }
+                }
+                continue;
+            }
+
+            if (hadSlash) {
+                // handle an escaped value
+                hadSlash = false;
+                switch (ch) {
+                    case '\\' :
+                        out.append('\\');
+                        break;
+                    case '\'' :
+                        out.append('\'');
+                        break;
+                    case '\"' :
+                        out.append('"');
+                        break;
+                    case 'r' :
+                        out.append('\r');
+                        break;
+                    case 'f' :
+                        out.append('\f');
+                        break;
+                    case 't' :
+                        out.append('\t');
+                        break;
+                    case 'n' :
+                        out.append('\n');
+                        break;
+                    case 'b' :
+                        out.append('\b');
+                        break;
+                    case 'u' :
+                        // uh-oh, we're in unicode country....
+                        inUnicode = true;
+                        break;
+                    default :
+                        out.append(ch);
+                        break;
+                }
+                continue;
+            } else if (ch == '\\') {
+                hadSlash = true;
+                continue;
+            }
+            out.append(ch);
+        }
+
+        if (hadSlash) {
+            // then we're in the weird case of a \ at the end of the
+            // string, let's output it anyway.
+            out.append('\\');
+        }
+
+        return out.toString();
+    }
+
+    /**
+     * <p>Escapes the characters in a <code>String</code> using Java String rules.</p>
+     *
+     * <p>Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.) </p>
+     *
+     * <p>So a tab becomes the characters <code>'\\'</code> and
+     * <code>'t'</code>.</p>
+     *
+     * <p>The only difference between Java strings and JavaScript strings
+     * is that in JavaScript, a single quote must be escaped.</p>
+     *
+     * <p>Example:
+     * <pre>
+     * input string: He didn't say, "Stop!"
+     * output string: He didn't say, \"Stop!\"
+     * </pre>
+     * </p>
+     *
+     * @param str  String to escape values in, may be null
+     * @return String with escaped values, <code>null</code> if null string input
+     */
+    protected static String escapeJava(String str) {
+        if (str == null) {
+            return null;
+        }
+        int sz = str.length();
+        StringBuffer out = new StringBuffer(sz * 2);
+        for (int i = 0; i < sz; i++) {
+            char ch = str.charAt(i);
+            // handle unicode
+            if (ch > 0xfff) {
+                out.append("\\u").append(hex(ch));
+            } else if (ch > 0xff) {
+                out.append("\\u0").append(hex(ch));
+            } else if (ch > 0x7f) {
+                out.append("\\u00").append(hex(ch));
+            } else if (ch < 32) {
+                switch (ch) {
+                    case '\b' :
+                        out.append('\\');
+                        out.append('b');
+                        break;
+                    case '\n' :
+                        out.append('\\');
+                        out.append('n');
+                        break;
+                    case '\t' :
+                        out.append('\\');
+                        out.append('t');
+                        break;
+                    case '\f' :
+                        out.append('\\');
+                        out.append('f');
+                        break;
+                    case '\r' :
+                        out.append('\\');
+                        out.append('r');
+                        break;
+                    default :
+                        if (ch > 0xf) {
+                            out.append("\\u00").append(hex(ch));
+                        } else {
+                            out.append("\\u000").append(hex(ch));
+                        }
+                        break;
+                }
+            } else {
+                switch (ch) {
+                    case '"' :
+                        out.append('\\');
+                        out.append('"');
+                        break;
+                    case '\\' :
+                        out.append('\\');
+                        out.append('\\');
+                        break;
+                    default :
+                        out.append(ch);
+                        break;
+                }
+            }
+        }
+        return out.toString();
+    }
+
+    /**
+     * <p>Returns an upper case hexadecimal <code>String</code> for the given
+     * character.</p>
+     *
+     * @param ch The character to convert.
+     * @return An upper case hexadecimal <code>String</code>
+     */
+    protected static String hex(char ch) {
+        return Integer.toHexString(ch).toUpperCase(Locale.ENGLISH);
+    }
+
+    /**
+     * <p>Checks if the value is in the given array.</p>
+     *
+     * <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p>
+     *
+     * @param array  the array to search through
+     * @param valueToFind  the value to find
+     * @return <code>true</code> if the array contains the object
+     */
+    public static boolean contains(char[] array, char valueToFind) {
+        if (array == null) {
+            return false;
+        }
+        for (int i = 0; i < array.length; i++) {
+            if (valueToFind == array[i]) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Escape the separators in the key.
+     *
+     * @param key the key
+     * @return the escaped key
+     */
+    private static String escapeKey(String key)
+    {
+        StringBuffer newkey = new StringBuffer();
+
+        for (int i = 0; i < key.length(); i++)
+        {
+            char c = key.charAt(i);
+
+            if (contains(SEPARATORS, c) || contains(WHITE_SPACE, c))
+            {
+                // escape the separator
+                newkey.append('\\');
+                newkey.append(c);
+            }
+            else
+            {
+                newkey.append(c);
+            }
+        }
+
+        return newkey.toString();
+    }
+
+    /**
+     * This class is used to read properties lines. These lines do
+     * not terminate with new-line chars but rather when there is no
+     * backslash sign a the end of the line.  This is used to
+     * concatenate multiple lines for readability.
+     */
+    public static class PropertiesReader extends LineNumberReader
+    {
+        /** Stores the comment lines for the currently processed property.*/
+        private final List<String> commentLines;
+
+        /** Stores the value lines for the currently processed property.*/
+        private final List<String> valueLines;
+
+        /** Stores the name of the last read property.*/
+        private String propertyName;
+
+        /** Stores the value of the last read property.*/
+        private String propertyValue;
+
+        /**
+         * Creates a new instance of <code>PropertiesReader</code> and sets
+         * the underlaying reader and the list delimiter.
+         *
+         * @param reader the reader
+         */
+        public PropertiesReader(Reader reader)
+        {
+            super(reader);
+            commentLines = new ArrayList<String>();
+            valueLines = new ArrayList<String>();
+        }
+
+        /**
+         * Reads a property line. Returns null if Stream is
+         * at EOF. Concatenates lines ending with "\".
+         * Skips lines beginning with "#" or "!" and empty lines.
+         * The return value is a property definition (<code>&lt;name&gt;</code>
+         * = <code>&lt;value&gt;</code>)
+         *
+         * @return A string containing a property value or null
+         *
+         * @throws java.io.IOException in case of an I/O error
+         */
+        public String readProperty() throws IOException
+        {
+            commentLines.clear();
+            valueLines.clear();
+            StringBuffer buffer = new StringBuffer();
+
+            while (true)
+            {
+                String line = readLine();
+                if (line == null)
+                {
+                    // EOF
+                    return null;
+                }
+
+                if (isCommentLine(line))
+                {
+                    commentLines.add(line);
+                    continue;
+                }
+
+                valueLines.add(line);
+                while (line.length() > 0 && contains(WHITE_SPACE, line.charAt(0)))
+                {
+                    line = line.substring(1, line.length());
+                }
+
+                if (checkCombineLines(line))
+                {
+                    line = line.substring(0, line.length() - 1);
+                    buffer.append(line);
+                }
+                else
+                {
+                    buffer.append(line);
+                    break;
+                }
+            }
+            return buffer.toString();
+        }
+
+        /**
+         * Parses the next property from the input stream and stores the found
+         * name and value in internal fields. These fields can be obtained using
+         * the provided getter methods. The return value indicates whether EOF
+         * was reached (<b>false</b>) or whether further properties are
+         * available (<b>true</b>).
+         *
+         * @return a flag if further properties are available
+         * @throws java.io.IOException if an error occurs
+         */
+        public boolean nextProperty() throws IOException
+        {
+            String line = readProperty();
+
+            if (line == null)
+            {
+                return false; // EOF
+            }
+
+            // parse the line
+            String[] property = parseProperty(line);
+            propertyName = unescapeJava(property[0]);
+            propertyValue = unescapeJava(property[1]);
+            return true;
+        }
+
+        /**
+         * Returns the comment lines that have been read for the last property.
+         *
+         * @return the comment lines for the last property returned by
+         * <code>readProperty()</code>
+         */
+        public List<String> getCommentLines()
+        {
+            return commentLines;
+        }
+
+        /**
+         * Returns the value lines that have been read for the last property.
+         *
+         * @return the raw value lines for the last property returned by
+         * <code>readProperty()</code>
+         */
+        public List<String> getValueLines()
+        {
+            return valueLines;
+        }
+
+        /**
+         * Returns the name of the last read property. This method can be called
+         * after <code>{@link #nextProperty()}</code> was invoked and its
+         * return value was <b>true</b>.
+         *
+         * @return the name of the last read property
+         */
+        public String getPropertyName()
+        {
+            return propertyName;
+        }
+
+        /**
+         * Returns the value of the last read property. This method can be
+         * called after <code>{@link #nextProperty()}</code> was invoked and
+         * its return value was <b>true</b>.
+         *
+         * @return the value of the last read property
+         */
+        public String getPropertyValue()
+        {
+            return propertyValue;
+        }
+
+        /**
+         * Checks if the passed in line should be combined with the following.
+         * This is true, if the line ends with an odd number of backslashes.
+         *
+         * @param line the line
+         * @return a flag if the lines should be combined
+         */
+        private static boolean checkCombineLines(String line)
+        {
+            int bsCount = 0;
+            for (int idx = line.length() - 1; idx >= 0 && line.charAt(idx) == '\\'; idx--)
+            {
+                bsCount++;
+            }
+
+            return bsCount % 2 != 0;
+        }
+
+        /**
+         * Parse a property line and return the key and the value in an array.
+         *
+         * @param line the line to parse
+         * @return an array with the property's key and value
+         */
+        private static String[] parseProperty(String line)
+        {
+            // sorry for this spaghetti code, please replace it as soon as
+            // possible with a regexp when the Java 1.3 requirement is dropped
+
+            String[] result = new String[2];
+            StringBuffer key = new StringBuffer();
+            StringBuffer value = new StringBuffer();
+
+            // state of the automaton:
+            // 0: key parsing
+            // 1: antislash found while parsing the key
+            // 2: separator crossing
+            // 3: white spaces
+            // 4: value parsing
+            int state = 0;
+
+            for (int pos = 0; pos < line.length(); pos++)
+            {
+                char c = line.charAt(pos);
+
+                switch (state)
+                {
+                    case 0:
+                        if (c == '\\')
+                        {
+                            state = 1;
+                        }
+                        else if (contains(WHITE_SPACE, c))
+                        {
+                            // switch to the separator crossing state
+                            state = 2;
+                        }
+                        else if (contains(SEPARATORS, c))
+                        {
+                            // switch to the value parsing state
+                            state = 3;
+                        }
+                        else
+                        {
+                            key.append(c);
+                        }
+
+                        break;
+
+                    case 1:
+                        if (contains(SEPARATORS, c) || contains(WHITE_SPACE, c))
+                        {
+                            // this is an escaped separator or white space
+                            key.append(c);
+                        }
+                        else
+                        {
+                            // another escaped character, the '\' is preserved
+                            key.append('\\');
+                            key.append(c);
+                        }
+
+                        // return to the key parsing state
+                        state = 0;
+
+                        break;
+
+                    case 2:
+                        if (contains(WHITE_SPACE, c))
+                        {
+                            // do nothing, eat all white spaces
+                            state = 2;
+                        }
+                        else if (contains(SEPARATORS, c))
+                        {
+                            // switch to the value parsing state
+                            state = 3;
+                        }
+                        else
+                        {
+                            // any other character indicates we encoutered the beginning of the value
+                            value.append(c);
+
+                            // switch to the value parsing state
+                            state = 4;
+                        }
+
+                        break;
+
+                    case 3:
+                        if (contains(WHITE_SPACE, c))
+                        {
+                            // do nothing, eat all white spaces
+                            state = 3;
+                        }
+                        else
+                        {
+                            // any other character indicates we encoutered the beginning of the value
+                            value.append(c);
+
+                            // switch to the value parsing state
+                            state = 4;
+                        }
+
+                        break;
+
+                    case 4:
+                        value.append(c);
+                        break;
+                }
+            }
+
+            result[0] = key.toString();
+            result[1] = value.toString();
+
+            return result;
+        }
+    } // class PropertiesReader
+
+    /**
+     * This class is used to write properties lines.
+     */
+    public static class PropertiesWriter extends FilterWriter
+    {
+        /**
+         * Constructor.
+         *
+         * @param writer a Writer object providing the underlying stream
+         */
+        public PropertiesWriter(Writer writer)
+        {
+            super(writer);
+        }
+
+        /**
+         * Writes the given property and its value.
+         *
+         * @param key the property key
+         * @param value the property value
+         * @throws java.io.IOException if an error occurs
+         */
+        public void writeProperty(String key, String value) throws IOException
+        {
+            write(escapeKey(key));
+            write(" = ");
+            write(escapeJava(value));
+            writeln(null);
+        }
+
+        /**
+         * Helper method for writing a line with the platform specific line
+         * ending.
+         *
+         * @param s the content of the line (may be <b>null</b>)
+         * @throws java.io.IOException if an error occurs
+         */
+        public void writeln(String s) throws IOException
+        {
+            if (s != null)
+            {
+                write(s);
+            }
+            write(LINE_SEPARATOR);
+        }
+
+    } // class PropertiesWriter
+
+    /**
+     * TODO
+     */
+    protected static class Layout {
+
+        private List<String> commentLines;
+        private List<String> valueLines;
+
+        public Layout() {
+        }
+
+        public Layout(List<String> commentLines, List<String> valueLines) {
+            this.commentLines = commentLines;
+            this.valueLines = valueLines;
+        }
+
+        public List<String> getCommentLines() {
+            return commentLines;
+        }
+
+        public void setCommentLines(List<String> commentLines) {
+            this.commentLines = commentLines;
+        }
+
+        public List<String> getValueLines() {
+            return valueLines;
+        }
+
+        public void setValueLines(List<String> valueLines) {
+            this.valueLines = valueLines;
+        }
+
+        public void clearValue() {
+            this.valueLines = null;
+        }
+
+    } // class Layout
+
+}
\ No newline at end of file