deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject deltaspike git commit: DELTASPIKE-1090 also lookup an env key with underlines instead of dots
Date Fri, 11 Mar 2016 18:23:06 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 265f9a0c0 -> 1c23b4cad


DELTASPIKE-1090 also lookup an env key with underlines instead of dots

You now can write
$> export my_config_key=blablub
and access it via my.config.key


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

Branch: refs/heads/master
Commit: 1c23b4cad21357bf16c310ef0766c5d589caf12f
Parents: 265f9a0
Author: Mark Struberg <struberg@apache.org>
Authored: Fri Mar 11 17:55:47 2016 +0100
Committer: Mark Struberg <struberg@apache.org>
Committed: Fri Mar 11 17:55:47 2016 +0100

----------------------------------------------------------------------
 .../config/EnvironmentPropertyConfigSource.java | 21 ++++++++++++++++++++
 .../test/core/api/config/ConfigSourceTest.java  | 17 ++++++++++++++++
 2 files changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1c23b4ca/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSource.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSource.java
index b0c4a26..5c5ea5d 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSource.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSource.java
@@ -23,6 +23,9 @@ package org.apache.deltaspike.core.impl.config;
 /**
  * {@link org.apache.deltaspike.core.spi.config.ConfigSource}
  * which uses {@link System#getenv()}
+ *
+ * We also allow to write underlines _ instead of dots _ in the
+ * environment via export (unix) or SET (windows)
  */
 class EnvironmentPropertyConfigSource extends MapConfigSource
 {
@@ -42,4 +45,22 @@ class EnvironmentPropertyConfigSource extends MapConfigSource
     {
         return "environment-properties";
     }
+
+    @Override
+    public String getPropertyValue(String key)
+    {
+        String val = super.getPropertyValue(key);
+        if (val == null || val.isEmpty())
+        {
+            val = super.getPropertyValue(key.replace('.', '_'));
+        }
+
+        return val;
+    }
+
+    @Override
+    public boolean isScannable()
+    {
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1c23b4ca/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
index c3f62a7..89e6d72 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/ConfigSourceTest.java
@@ -18,6 +18,8 @@
  */
 package org.apache.deltaspike.test.core.api.config;
 
+import java.util.Map;
+
 import org.apache.deltaspike.core.api.config.ConfigResolver;
 import org.junit.Assert;
 import org.junit.Test;
@@ -94,5 +96,20 @@ public class ConfigSourceTest
         Assert.assertEquals("a secret value: onlyIDoKnowIt", secretVal);
     }
 
+    @Test
+    public void testEnvProperties() {
+        String javaHome = System.getenv("JAVA_HOME");
+        if (javaHome == null || javaHome.isEmpty())
+        {
+            // weird, should exist. Anyway, in that case we cannot test it.
+            return;
+        }
+
+        // we search for JAVA.HOME which should also give us JAVA_HOME
+        String value = ConfigResolver.getPropertyValue("JAVA.HOME");
+        Assert.assertNotNull(value);
+        Assert.assertEquals(javaHome, value);
+    }
+
 
 }


Mime
View raw message