You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2017/11/27 15:06:23 UTC

[1/3] deltaspike git commit: DELTASPIKE-1282 support variables 4 String default

Repository: deltaspike
Updated Branches:
  refs/heads/master b1903c2b3 -> f0d56be8f


DELTASPIKE-1282 support variables 4 String default


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

Branch: refs/heads/master
Commit: 77fa4b8653c525d631e462d148c3af5b368f8361
Parents: b1903c2
Author: Mark Struberg <st...@apache.org>
Authored: Mon Nov 27 15:46:27 2017 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Nov 27 15:46:27 2017 +0100

----------------------------------------------------------------------
 .../core/api/config/ConfigResolver.java         | 34 +++++++++++---------
 .../core/api/config/ConfigResolverContext.java  | 11 ++++++-
 .../test/api/config/ConfigResolverTest.java     | 15 +++++++++
 3 files changed, 44 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/77fa4b86/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
index d415719..f3f8743 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
@@ -186,12 +186,11 @@ public final class ConfigResolver
 
     public static String getPropertyValue(String key, String defaultValue, boolean evaluateVariables)
     {
-        String value = getPropertyValue(
-                key, 
-                new ConfigResolverContext()
-                        .setEvaluateVariables(evaluateVariables));
+        ConfigResolverContext configResolverContext = evaluateVariables ?
+                ConfigResolverContext.EVAL_VARIABLES : ConfigResolverContext.NONE;
+        String value = getPropertyValue(key, configResolverContext);
 
-        return fallbackToDefaultIfEmpty(key, value, defaultValue);
+        return fallbackToDefaultIfEmpty(key, value, defaultValue, configResolverContext);
     }
 
     /**
@@ -222,8 +221,7 @@ public final class ConfigResolver
     {
         return getPropertyValue(
                 key, 
-                new ConfigResolverContext()
-                        .setEvaluateVariables(evaluateVariables));        
+                evaluateVariables ? ConfigResolverContext.EVAL_VARIABLES : ConfigResolverContext.NONE);
     }
 
     /**
@@ -247,10 +245,7 @@ public final class ConfigResolver
      */
     public static String getProjectStageAwarePropertyValue(String key)
     {
-        ConfigResolverContext configResolverContext = 
-                new ConfigResolverContext()
-                    .setProjectStageAware(true)
-                    .setEvaluateVariables(true);
+        ConfigResolverContext configResolverContext = ConfigResolverContext.PROJECTSTAGE_EVAL_VARIABLES;
         
         ProjectStage ps = getProjectStage();
 
@@ -276,7 +271,7 @@ public final class ConfigResolver
     {
         String value = getProjectStageAwarePropertyValue(key);
 
-        return fallbackToDefaultIfEmpty(key, value, defaultValue);
+        return fallbackToDefaultIfEmpty(key, value, defaultValue, ConfigResolverContext.PROJECTSTAGE_EVAL_VARIABLES);
     }
 
     /**
@@ -356,7 +351,7 @@ public final class ConfigResolver
     {
         String value = getPropertyAwarePropertyValue(key, property);
 
-        return fallbackToDefaultIfEmpty(key, value, defaultValue);
+        return fallbackToDefaultIfEmpty(key, value, defaultValue, ConfigResolverContext.PROJECTSTAGE_EVAL_VARIABLES);
     }
     
     private static String getPropertyValue(String key, ConfigResolverContext configResolverContext)
@@ -567,10 +562,16 @@ public final class ConfigResolver
         return ProjectStageProducer.getInstance().getProjectStage();
     }
 
-    private static <T> T fallbackToDefaultIfEmpty(String key, T value, T defaultValue)
+    private static <T> T fallbackToDefaultIfEmpty(String key, T value, T defaultValue,
+                                                  ConfigResolverContext configResolverContext)
     {
         if (value == null || (value instanceof String && ((String)value).isEmpty()))
         {
+            if (configResolverContext != null && defaultValue instanceof String
+                    && configResolverContext.isEvaluateVariables())
+            {
+                defaultValue = (T) resolveVariables((String) defaultValue, configResolverContext);
+            }
             LOG.log(Level.FINE, "no configured value found for key {0}, using default value {1}.",
                     new Object[]{key, defaultValue});
 
@@ -1001,7 +1002,10 @@ public final class ConfigResolver
 
             if (withDefault)
             {
-                value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue);
+                ConfigResolverContext configResolverContext = new ConfigResolverContext()
+                        .setEvaluateVariables(evaluateVariables)
+                        .setProjectStageAware(projectStageAware);
+                value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue, configResolverContext);
             }
 
             if (logChanges && (value != null && !value.equals(lastValue) || (value == null && lastValue != null)) )

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/77fa4b86/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolverContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolverContext.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolverContext.java
index 21418db..223932f 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolverContext.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolverContext.java
@@ -20,7 +20,16 @@ package org.apache.deltaspike.core.api.config;
 
 class ConfigResolverContext
 {
-    
+    static final ConfigResolverContext NONE = new ConfigResolverContext();
+
+    static final ConfigResolverContext EVAL_VARIABLES = new ConfigResolverContext().setEvaluateVariables(true);
+
+    static final ConfigResolverContext PROJECTSTAGE = new ConfigResolverContext().setProjectStageAware(true);
+
+    static final ConfigResolverContext PROJECTSTAGE_EVAL_VARIABLES = new ConfigResolverContext()
+                                                                            .setProjectStageAware(true)
+                                                                            .setEvaluateVariables(true);
+
     private boolean projectStageAware;
     private boolean evaluateVariables;
     private boolean propertyAware;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/77fa4b86/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
index 6613043..c8b8c99 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
@@ -158,6 +158,21 @@ public class ConfigResolverTest
     }
 
     @Test
+    public void testConfigVariableReplacementInDefault()
+    {
+        {
+            String url = ConfigResolver.getPropertyValue("deltaspike.test.notexisting",
+                    "url: ${deltaspike.test.host.url}", true);
+            Assert.assertEquals("url: http://localhost:12345", url);
+        }
+
+        {
+            String url = ConfigResolver.getPropertyValue("deltaspike.test.someapp.soap.endpoint", true);
+            Assert.assertEquals("http://localhost:12345/someservice/myendpoint", url);
+        }
+    }
+
+    @Test
     public void testConfigVariableNotExisting()
     {
         {


[2/3] deltaspike git commit: DELTASPIKE-1278 avoid signature change

Posted by st...@apache.org.
DELTASPIKE-1278 avoid signature change

previously we did not throw the URISyntaxException which
is a checked Exception. So this change did require to catch
that exception in user code.
Now handling this issue internally.


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

Branch: refs/heads/master
Commit: 717771b275f406ce7ce43cd528be44d6053b7d2b
Parents: 77fa4b8
Author: Mark Struberg <st...@apache.org>
Authored: Mon Nov 27 15:57:36 2017 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Nov 27 15:57:36 2017 +0100

----------------------------------------------------------------------
 .../deltaspike/core/util/PropertyFileUtils.java      | 15 +++++++++++----
 .../EnvironmentPropertyConfigSourceProvider.java     |  6 ------
 2 files changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/717771b2/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
index 813b988..f38029b 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
@@ -42,7 +42,7 @@ public abstract class PropertyFileUtils
         // prevent instantiation
     }
 
-    public static Enumeration<URL> resolvePropertyFiles(String propertyFileName) throws IOException, URISyntaxException
+    public static Enumeration<URL> resolvePropertyFiles(String propertyFileName) throws IOException
     {
         if (propertyFileName != null && (propertyFileName.contains("://") || propertyFileName.startsWith("file:")))
         {
@@ -52,10 +52,17 @@ public abstract class PropertyFileUtils
 
             if (propertyFileName.startsWith("file:"))
             {
-                File file = new File(url.toURI());
-                if (file.exists())
+                try
                 {
-                    propertyFileUrls.add(url);
+                    File file = new File(url.toURI());
+                    if (file.exists())
+                    {
+                        propertyFileUrls.add(url);
+                    }
+                }
+                catch (URISyntaxException e)
+                {
+                    throw new IllegalStateException("Property file URL is malformed", e);
                 }
             }
             else

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/717771b2/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
index 64d9cdd..b34e68c 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
@@ -19,7 +19,6 @@
 package org.apache.deltaspike.core.impl.config;
 
 import java.io.IOException;
-import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -66,11 +65,6 @@ class EnvironmentPropertyConfigSourceProvider implements ConfigSourceProvider
         {
             throw new IllegalStateException("problem while loading DeltaSpike property files", ioe);
         }
-        catch (URISyntaxException ue)
-        {
-            throw new IllegalStateException("Property file URL is malformed", ue);
-        }
-
     }
 
     @Override


[3/3] deltaspike git commit: DELTASPIKE-1296 move ConfigSource registration

Posted by st...@apache.org.
DELTASPIKE-1296 move ConfigSource registration

we now register PropertyFileConfig ConfigSources
already in AfterBeanDiscovery and not in AfterDeploymentValidation.
As requested by Romain


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

Branch: refs/heads/master
Commit: f0d56be8f4867908c39c1937fdf25fa8d8524c07
Parents: 717771b
Author: Mark Struberg <st...@apache.org>
Authored: Mon Nov 27 16:05:03 2017 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Nov 27 16:05:03 2017 +0100

----------------------------------------------------------------------
 .../deltaspike/core/impl/config/ConfigurationExtension.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f0d56be8/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
index 4350445..f5be8cc 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
@@ -263,7 +263,7 @@ public class ConfigurationExtension implements Extension, Deactivatable
     }
 
     @SuppressWarnings("UnusedDeclaration")
-    public void registerUserConfigSources(@Observes AfterDeploymentValidation adv)
+    public void registerUserConfigSources(@Observes AfterBeanDiscovery abd)
     {
         if (!isActivated)
         {
@@ -306,13 +306,16 @@ public class ConfigurationExtension implements Extension, Deactivatable
             ConfigResolver.addConfigFilter(BeanProvider.getContextualReference(ConfigFilter.class, bean));
         }
 
-        processConfigurationValidation(adv);
-
         registerConfigMBean();
 
         logConfiguration();
     }
 
+    public void validateConfiguration(@Observes AfterDeploymentValidation adv)
+    {
+        processConfigurationValidation(adv);
+    }
+
     private void logConfiguration()
     {
         Boolean logConfig = ConfigResolver.resolve(ConfigResolver.DELTASPIKE_LOG_CONFIG).as(Boolean.class).getValue();