deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-750 support for optional and mandatory config-files
Date Mon, 17 Nov 2014 18:27:53 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 7cee58435 -> ed8ad5816


DELTASPIKE-750 support for optional and mandatory config-files


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

Branch: refs/heads/master
Commit: ed8ad5816bafc030023bbcc8701d7399ce41b345
Parents: 7cee584
Author: gpetracek <gpetracek@apache.org>
Authored: Mon Nov 17 19:23:00 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Mon Nov 17 19:27:18 2014 +0100

----------------------------------------------------------------------
 .../deltaspike/core/api/config/PropertyFileConfig.java    |  5 +++++
 .../core/impl/config/ConfigurationExtension.java          | 10 ++++++++--
 .../core/impl/config/DefaultConfigSourceProvider.java     |  3 ++-
 .../config/EnvironmentPropertyConfigSourceProvider.java   |  7 ++++++-
 .../propertyconfigsource/MyCustomPropertyFileConfig.java  |  6 ++++++
 .../example/config/CustomPropertyFileConfig.java          |  6 ++++++
 6 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ed8ad581/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyFileConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyFileConfig.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyFileConfig.java
index 216ebe7..fed736c 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyFileConfig.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyFileConfig.java
@@ -44,4 +44,9 @@ public interface PropertyFileConfig extends DeltaSpikeConfig
      * @return the full file name (including path) of the property files to pick up.
      */
     String getPropertyFileName();
+
+    /**
+     * @return true if the file is optional, false if the specified file has to be in place.
+     */
+    boolean isOptional();
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ed8ad581/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 0bdbf4a..baec960 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
@@ -110,11 +110,13 @@ public class ConfigurationExtension implements Extension, Deactivatable
      */
     private List<ConfigSource> createPropertyConfigSource(Class<? extends PropertyFileConfig>
propertyFileConfigClass)
     {
+        String fileName = "";
         try
         {
             PropertyFileConfig propertyFileConfig = propertyFileConfigClass.newInstance();
+            fileName = propertyFileConfig.getPropertyFileName();
             EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider
-                = new EnvironmentPropertyConfigSourceProvider(propertyFileConfig.getPropertyFileName());
+                = new EnvironmentPropertyConfigSourceProvider(fileName, propertyFileConfig.isOptional());
 
             return environmentPropertyConfigSourceProvider.getConfigSources();
         }
@@ -128,6 +130,10 @@ public class ConfigurationExtension implements Extension, Deactivatable
             throw new RuntimeException(CANNOT_CREATE_CONFIG_SOURCE_FOR_CUSTOM_PROPERTY_FILE_CONFIG
+
                     propertyFileConfigClass.getName(), e);
         }
+        catch (IllegalStateException e)
+        {
+            throw new IllegalStateException(
+                propertyFileConfigClass.getName() + " points to an invalid file: '" + fileName
+ "'", e);
+        }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ed8ad581/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
index 8057a70..126ec06 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DefaultConfigSourceProvider.java
@@ -48,7 +48,8 @@ public class DefaultConfigSourceProvider implements ConfigSourceProvider
         configSources.add(new EnvironmentPropertyConfigSource());
         configSources.add(new LocalJndiConfigSource());
 
-        EnvironmentPropertyConfigSourceProvider epcsp = new EnvironmentPropertyConfigSourceProvider(PROPERTY_FILE_NAME);
+        EnvironmentPropertyConfigSourceProvider epcsp =
+            new EnvironmentPropertyConfigSourceProvider(PROPERTY_FILE_NAME, true);
         configSources.addAll(epcsp.getConfigSources());
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ed8ad581/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 2babf3a..b5daeb4 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
@@ -40,12 +40,17 @@ class EnvironmentPropertyConfigSourceProvider implements ConfigSourceProvider
 
     private List<ConfigSource> configSources = new ArrayList<ConfigSource>();
 
-    EnvironmentPropertyConfigSourceProvider(String propertyFileName)
+    EnvironmentPropertyConfigSourceProvider(String propertyFileName, boolean optional)
     {
         try
         {
             Enumeration<URL> propertyFileUrls = PropertyFileUtils.resolvePropertyFiles(propertyFileName);
 
+            if (!optional && !propertyFileUrls.hasMoreElements())
+            {
+                throw new IllegalStateException(propertyFileName + " wasn't found.");
+            }
+
             while (propertyFileUrls.hasMoreElements())
             {
                 URL propertyFileUrl = propertyFileUrls.nextElement();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ed8ad581/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyFileConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyFileConfig.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyFileConfig.java
index 8d3e832..49c4a2f 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyFileConfig.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyFileConfig.java
@@ -30,4 +30,10 @@ public class MyCustomPropertyFileConfig implements PropertyFileConfig
     {
         return "myconfig.properties";
     }
+
+    @Override
+    public boolean isOptional()
+    {
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ed8ad581/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/config/CustomPropertyFileConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/config/CustomPropertyFileConfig.java
b/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/config/CustomPropertyFileConfig.java
index 2e72834..6e89cd3 100644
--- a/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/config/CustomPropertyFileConfig.java
+++ b/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/config/CustomPropertyFileConfig.java
@@ -33,4 +33,10 @@ public class CustomPropertyFileConfig implements PropertyFileConfig
     {
         return "META-INF/location.properties";
     }
+
+    @Override
+    public boolean isOptional()
+    {
+        return false;
+    }
 }


Mime
View raw message