tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [06/10] incubator-tamaya git commit: Added possibility to switch off default features.
Date Wed, 09 Mar 2016 13:11:15 GMT
Added possibility to switch off default features.


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

Branch: refs/heads/master
Commit: d2f16905ff61d464072ea0025fc017e5a630d148
Parents: 71ad5f5
Author: anatole <anatole@apache.org>
Authored: Wed Mar 9 13:39:36 2016 +0100
Committer: anatole <anatole@apache.org>
Committed: Wed Mar 9 13:39:36 2016 +0100

----------------------------------------------------------------------
 .../EnvironmentPropertySource.java              | 33 ++++++++++++++++++--
 .../propertysource/SystemPropertySource.java    | 32 ++++++++++++++++++-
 .../provider/JavaConfigurationProvider.java     | 26 ++++++++++++++-
 3 files changed, 87 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d2f16905/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
b/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
index 841d432..1324ebd 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
@@ -21,13 +21,15 @@ package org.apache.tamaya.core.propertysource;
 import org.apache.tamaya.spi.PropertySource;
 import org.apache.tamaya.spi.PropertyValue;
 
+import java.util.Collections;
 import java.util.Map;
 
 /**
  * This {@link org.apache.tamaya.spi.PropertySource} provides all Properties which are set
  * via
  * {@code export myprop=myval} on UNIX Systems or
- * {@code set myprop=myval} on Windows
+ * {@code set myprop=myval} on Windows. You can disable this feature by setting {@code tamaya.envprops.disable}
+ * or {@code tamaya.defaults.disable}.
  */
 public class EnvironmentPropertySource implements PropertySource {
 
@@ -36,6 +38,25 @@ public class EnvironmentPropertySource implements PropertySource {
      */
     public static final int DEFAULT_ORDINAL = 300;
 
+    private final boolean disabled = evaluateDisabled();
+
+    private boolean evaluateDisabled() {
+        String value = System.getProperty("tamaya.envprops.disable");
+        if(value==null){
+            value = System.getenv("tamaya.envprops.disable");
+        }
+        if(value==null){
+            value = System.getProperty("tamaya.defaults.disable");
+        }
+        if(value==null){
+            value = System.getenv("tamaya.defaults.disable");
+        }
+        if(value==null){
+            return false;
+        }
+        return value.isEmpty() || Boolean.parseBoolean(value);
+    }
+
     @Override
     public int getOrdinal() {
         return DEFAULT_ORDINAL;
@@ -43,18 +64,26 @@ public class EnvironmentPropertySource implements PropertySource {
 
     @Override
     public String getName() {
+        if(disabled){
+            return "environment-properties(disabled)";
+        }
         return "environment-properties";
     }
 
     @Override
     public PropertyValue get(String key) {
+        if(disabled){
+            return null;
+        }
         return PropertyValue.of(key, System.getenv(key), getName());
     }
 
     @Override
     public Map<String, String> getProperties() {
+        if(disabled){
+            return Collections.emptyMap();
+        }
         return System.getenv(); // already a map and unmodifiable
-
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d2f16905/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
index 80cd140..a5b748f 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -28,7 +28,8 @@ import java.util.Map;
 import java.util.Properties;
 
 /**
- * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
+ * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties. You can
disable this feature by
+ * setting {@code tamaya.envprops.disable} or {@code tamaya.defaults.disable}.
  */
 public class SystemPropertySource implements PropertySource {
 
@@ -45,6 +46,26 @@ public class SystemPropertySource implements PropertySource {
      */
     private int previousHash;
 
+    private final boolean disabled = evaluateDisabled();
+
+    private boolean evaluateDisabled() {
+        String value = System.getProperty("tamaya.sysprops.disable");
+        if(value==null){
+            value = System.getenv("tamaya.sysprops.disable");
+        }
+        if(value==null){
+            value = System.getProperty("tamaya.defaults.disable");
+        }
+        if(value==null){
+            value = System.getenv("tamaya.defaults.disable");
+        }
+        if(value==null){
+            return false;
+        }
+        return value.isEmpty() || Boolean.parseBoolean(value);
+    }
+
+
 
     public SystemPropertySource() {
         cachedProperties = loadProperties();
@@ -67,16 +88,25 @@ public class SystemPropertySource implements PropertySource {
 
     @Override
     public String getName() {
+        if(disabled){
+            return "system-properties(disabled)";
+        }
         return "system-properties";
     }
 
     @Override
     public PropertyValue get(String key) {
+        if(disabled){
+            return null;
+        }
         return PropertyValue.of(key, System.getProperty(key), getName());
     }
 
     @Override
     public Map<String, String> getProperties() {
+        if(disabled){
+            return Collections.emptyMap();
+        }
         // only need to reload and fill our map if something has changed
         // synchronization was removed, Instance was marked as volatile. In the worst case
it
         // is reloaded twice, but the values will be the same.

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d2f16905/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
b/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
index 9c04926..331f88a 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
@@ -32,14 +32,38 @@ import java.util.Enumeration;
 import java.util.List;
 
 /**
- * Provider which reads all {@code javaconfiguration.properties} files from classpath
+ * Provider which reads all {@code javaconfiguration.properties} files from classpath. By
setting
+ * {@code tamaya.defaultprops.disable} or {@code tamaya.defaults.disable} as system or environment
property this feature
+ * can be disabled.
  */
 public class JavaConfigurationProvider implements PropertySourceProvider {
     /** Default location in the classpath, where Tamaya looks for configuration by default.
*/
     public static final String DEFAULT_PROPERTIES_FILE_NAME="META-INF/javaconfiguration.properties";
 
+    private final boolean disabled = evaluateDisabled();
+
+    private boolean evaluateDisabled() {
+        String value = System.getProperty("tamaya.defaultprops.disable");
+        if(value==null){
+            value = System.getenv("tamaya.defaultprops.disable");
+        }
+        if(value==null){
+            value = System.getProperty("tamaya.defaults.disable");
+        }
+        if(value==null){
+            value = System.getenv("tamaya.defaults.disable");
+        }
+        if(value==null){
+            return false;
+        }
+        return value.isEmpty() || Boolean.parseBoolean(value);
+    }
+
     @Override
     public Collection<PropertySource> getPropertySources() {
+        if(disabled){
+            return Collections.emptySet();
+        }
         List<PropertySource> propertySources = new ArrayList<>();
         try {
             ClassLoader cl = Thread.currentThread().getContextClassLoader();


Mime
View raw message