tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1491423 - in /tomee/tomee/trunk/container: openejb-core/src/main/java/org/apache/openejb/util/ openejb-core/src/test/java/org/apache/openejb/config/ openejb-core/src/test/resources/ openejb-loader/src/main/java/org/apache/openejb/loader/
Date Mon, 10 Jun 2013 11:32:05 GMT
Author: rmannibucau
Date: Mon Jun 10 11:32:05 2013
New Revision: 1491423

URL: http://svn.apache.org/r1491423
Log:
TOMEE-966 supporting '=' separator instead of : too + using system properties as parent of
internal properties to get it as fallback everwhere freely

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
    tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json
    tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java?rev=1491423&r1=1491422&r2=1491423&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
Mon Jun 10 11:32:05 2013
@@ -91,7 +91,17 @@ public final class PropertyPlaceHolderHe
 
         @Override
         public String lookup(final String key) {
-            return PROPERTIES.getProperty(key, ENV.get(key));
+            String value = PROPERTIES.getProperty(key);
+            if (value != null) {
+                return value;
+            }
+
+            value = ENV.get(key);
+            if (value != null) {
+                return value;
+            }
+
+            return key;
         }
     }
 }

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java?rev=1491423&r1=1491422&r2=1491423&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java
Mon Jun 10 11:32:05 2013
@@ -55,11 +55,11 @@ public class SimpleJSonParser {
                     throw new IllegalArgumentException("String should be between \"");
                 }
 
-                final String value = b.substring(0, b.length() - 1); // remove last "
+                final String value = PropertyPlaceHolderHelper.simpleValue(b.substring(0,
b.length() - 1)); // remove last "
                 if (valueRead(is, json, array, value)) {
                     return value;
                 }
-            } else if (current != ':' && current != ',' && !isWhiteSpace(current))
{
+            } else if (current != ':' && current != '=' && current != ','
&& !isWhiteSpace(current)) {
                 final StringBuilder b =  new StringBuilder().append(current);
                 do {
                     read = is.read();
@@ -68,7 +68,7 @@ public class SimpleJSonParser {
                     b.append(current);
                 } while (current != -1 && !isWhiteSpace(current) && current
!= ',');
 
-                final String value = b.substring(0, b.length() - 1); // remove last character
+                final String value = PropertyPlaceHolderHelper.simpleValue(b.substring(0,
b.length() - 1)); // remove last character
                 if (valueRead(is, json, array, value)) {
                     return value;
                 }
@@ -81,9 +81,11 @@ public class SimpleJSonParser {
 
     private static boolean valueRead(final InputStream is, final Map<String, Object>
json, final Collection<Object> array, final String value) throws IOException {
         int read;
+        char c;
         do {
             read = is.read();
-        } while (read != -1 && read != ':' && read == ',');
+            c = (char) read;
+        } while (c != -1 && c != ':' && c != '=' && (c == ',' ||
c == '\n' || c == '\r'));
 
         if (json != null) {
             json.put(value, read(is));

Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java?rev=1491423&r1=1491422&r2=1491423&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
Mon Jun 10 11:32:05 2013
@@ -42,6 +42,7 @@ import static org.junit.Assert.assertTru
 public class JSonConfigTest {
     @Configuration
     public String config() {
+        System.setProperty("JSonConfigTest.foo", "bar");
         return "openejb.json";
     }
 
@@ -67,6 +68,14 @@ public class JSonConfigTest {
         assertEquals("d", System.getProperty("c"));
         assertEquals("g", System.getProperty("e.f"));
         assertEquals("j", System.getProperty("e.h.i"));
+        assertEquals("properties-value", System.getProperty("properties-key"));
+        assertEquals("2", System.getProperty("object.attribute.#1"));
+    }
+
+    @Test
+    public void checkPlaceHolder() {
+        assertEquals("bar", System.getProperty("JSonConfigTest.foo")); // the real one
+        assertEquals("bar", System.getProperty("placeholder")); // the configured one
     }
 
     @Test

Modified: tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json?rev=1491423&r1=1491422&r2=1491423&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json (original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json Mon Jun 10 11:32:05
2013
@@ -41,6 +41,13 @@
             "h": {
                 "i": "j"
             }
+        },
+        "placeholder": "${JSonConfigTest.foo}",
+        "properties-key" = "properties-value",
+        "object" = {
+            "attribute" = {
+                "#1" = "2"
+            }
         }
     }
 }

Modified: tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java?rev=1491423&r1=1491422&r2=1491423&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
(original)
+++ tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
Mon Jun 10 11:32:05 2013
@@ -46,7 +46,7 @@ public class SystemInstance {
     /**
      * Properties that have to be away from System (i.e. {@link System#setProperty(String,
String)} must not be called)
      */
-    private final Properties internalProperties = new Properties();
+    private final Properties internalProperties = new Properties(System.getProperties());
 
     private final Options options;
 
@@ -67,6 +67,7 @@ public class SystemInstance {
     private SystemInstance(final Properties properties) throws Exception {
         this.components = new HashMap<Class, Object>();
 
+        /* since defaults are system properties no need to do it
         for (Map.Entry<? extends Object, ? extends Object> e : System.getProperties().entrySet()){
             final String key = e.getKey().toString();
             if (key.startsWith("sun.")) continue;
@@ -87,6 +88,7 @@ public class SystemInstance {
             }
             this.internalProperties.put(e.getKey(), e.getValue());
         }
+        */
 
         this.internalProperties.putAll(properties);
 
@@ -318,7 +320,7 @@ public class SystemInstance {
             return;
         }
 
-        System.getProperties().putAll(systemProperties);
+        // System.getProperties().putAll(systemProperties); // no need since System.getProperties()
is the parent of internalProperties
         system.getProperties().putAll(systemProperties);
     }
 



Mime
View raw message