You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2017/04/10 14:20:44 UTC

svn commit: r1790833 - in /felix/trunk: fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ utils/src/main/java/org/apache/felix/utils/properties/

Author: gnodet
Date: Mon Apr 10 14:20:44 2017
New Revision: 1790833

URL: http://svn.apache.org/viewvc?rev=1790833&view=rev
Log:
[FELIX-5609] Do not require the OSGi package when using TypedProperties

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
    felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
    felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java?rev=1790833&r1=1790832&r2=1790833&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java (original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java Mon Apr 10 14:20:44 2017
@@ -130,7 +130,7 @@ public class ConfigInstaller implements
                 String fileName = (String) dict.get( DirectoryWatcher.FILENAME );
                 File file = fileName != null ? fromConfigKey(fileName) : null;
                 if( file != null && file.isFile() ) {
-                    TypedProperties props = new TypedProperties( context );
+                    TypedProperties props = new TypedProperties( bundleSubstitution() );
                     props.load( file );
                     // remove "removed" properties from the cfg file
                     List<String> propertiesToRemove = new ArrayList<>();
@@ -238,7 +238,7 @@ public class ConfigInstaller implements
                 InterpolationHelper.performSubstitution(strMap, context);
                 ht.putAll(strMap);
             } else {
-                TypedProperties p = new TypedProperties(context);
+                TypedProperties p = new TypedProperties( bundleSubstitution() );
                 p.load(in);
                 for (String k : p.keySet()) {
                     ht.put(k, p.get(k));
@@ -365,6 +365,16 @@ public class ConfigInstaller implements
         }
     }
 
+    TypedProperties.SubstitutionCallback bundleSubstitution() {
+        final InterpolationHelper.SubstitutionCallback cb = new InterpolationHelper.BundleContextSubstitutionCallback(context);
+        return new TypedProperties.SubstitutionCallback() {
+            @Override
+            public String getValue(String name, String key, String value) {
+                return cb.getValue(value);
+            }
+        };
+    }
+
     private String escapeFilterValue(String s) {
         return s.replaceAll("[(]", "\\\\(").
                 replaceAll("[)]", "\\\\)").

Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java?rev=1790833&r1=1790832&r2=1790833&view=diff
==============================================================================
--- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java (original)
+++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java Mon Apr 10 14:20:44 2017
@@ -420,7 +420,7 @@ public class InterpolationHelper {
         return val;
     }
 
-    static class BundleContextSubstitutionCallback implements SubstitutionCallback
+    public static class BundleContextSubstitutionCallback implements SubstitutionCallback
     {
         private final BundleContext context;
 

Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java?rev=1790833&r1=1790832&r2=1790833&view=diff
==============================================================================
--- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java (original)
+++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/TypedProperties.java Mon Apr 10 14:20:44 2017
@@ -16,11 +16,8 @@
  */
 package org.apache.felix.utils.properties;
 
-import org.osgi.framework.BundleContext;
-
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -32,7 +29,6 @@ import java.util.AbstractMap;
 import java.util.AbstractSet;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -40,10 +36,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.felix.utils.properties.InterpolationHelper.SubstitutionCallback;
-import org.apache.felix.utils.properties.InterpolationHelper.BundleContextSubstitutionCallback;
-
-import static org.apache.felix.utils.properties.InterpolationHelper.performSubstitution;
 import static org.apache.felix.utils.properties.InterpolationHelper.substVars;
 
 /**
@@ -59,6 +51,8 @@ import static org.apache.felix.utils.pro
  */
 public class TypedProperties extends AbstractMap<String, Object> {
 
+    public static final String ENV_PREFIX = "env:";
+
     private final Properties storage;
     private final SubstitutionCallback callback;
     private final boolean substitute;
@@ -71,10 +65,6 @@ public class TypedProperties extends Abs
         this(null, substitute);
     }
 
-    public TypedProperties(BundleContext context) {
-        this(wrap(new BundleContextSubstitutionCallback(context)), true);
-    }
-
     public TypedProperties(SubstitutionCallback callback) {
         this(callback, true);
     }
@@ -299,7 +289,18 @@ public class TypedProperties extends Abs
         if (!substitute) {
             return;
         }
-        final SubstitutionCallback callback = cb != null ? cb  : wrap(new BundleContextSubstitutionCallback(null));
+        final SubstitutionCallback callback = cb != null ? cb  : new SubstitutionCallback() {
+            public String getValue(String name, String key, String value) {
+                if (value.startsWith(ENV_PREFIX))
+                {
+                    return System.getenv(value.substring(ENV_PREFIX.length()));
+                }
+                else
+                {
+                    return System.getProperty(value);
+                }
+            }
+        }; //wrap(new BundleContextSubstitutionCallback(null));
         Map<String, TypedProperties> props = Collections.singletonMap("root", this);
         substitute(props, prepare(props), callback, true);
     }