openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [openwebbeans] branch master updated: MEECROWAVE-203 enable to control what happens when no config file is found in PropertyLoader - meecrowave does not want to log.info it due to the way it calls it
Date Fri, 09 Aug 2019 18:46:13 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new e0e0021  MEECROWAVE-203 enable to control what happens when no config file is found
in PropertyLoader - meecrowave does not want to log.info it due to the way it calls it
e0e0021 is described below

commit e0e0021bdfc6d30e685391bc16d2e90bc1136829
Author: Romain Manni-Bucau <rmannibucau@apache.org>
AuthorDate: Fri Aug 9 20:46:07 2019 +0200

    MEECROWAVE-203 enable to control what happens when no config file is found in PropertyLoader
- meecrowave does not want to log.info it due to the way it calls it
---
 .../org/apache/webbeans/config/PropertyLoader.java | 32 ++++++++++++++++------
 .../webbeans/test/config/PropertyLoaderTest.java   |  4 +--
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java b/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java
index bfcc22d..9e0dd29 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java
@@ -72,15 +72,18 @@ public final class PropertyLoader
      * is not really defined. The Properties file which got found first will be
      * processed first and thus get overwritten by the one found later.</p> 
      *
-     * @param propertyFileName the name of the properties file
+     * @param propertyFileName the name of the properties file.
+     * @param merger how to merge conflicting properties sets.
+     * @param onMissing executed when no file is found.
      * @return the final property values
      */
     public static synchronized Properties getProperties(String propertyFileName,
-                                                        Function<List<Properties>,
Properties> merger)
+                                                        Function<List<Properties>,
Properties> merger,
+                                                        Runnable onMissing)
     {
         try
         {
-            List<Properties> allProperties = loadAllProperties(propertyFileName);
+            List<Properties> allProperties = loadAllProperties(propertyFileName, onMissing);
             if (allProperties == null)
             {
                 return null;
@@ -96,21 +99,32 @@ public final class PropertyLoader
 
     public static synchronized Properties getProperties(String propertyFileName)
     {
-        return getProperties(propertyFileName, PropertyLoader::mergeProperties);
+        return getProperties(propertyFileName, PropertyLoader::mergeProperties, () ->
+                onMissingConfiguration(propertyFileName));
+    }
+
+    private static void onMissingConfiguration(final String propertyFileName)
+    {
+        if (logger.isLoggable(Level.INFO))
+        {
+            logger.info("could not find any property files with name " + propertyFileName);
+        }
     }
 
     public static List<Properties> loadAllProperties(String propertyFileName)
             throws IOException
     {
+        return loadAllProperties(propertyFileName, () -> onMissingConfiguration(propertyFileName));
+    }
+
+    public static List<Properties> loadAllProperties(String propertyFileName, Runnable
onMissing)
+            throws IOException
+    {
         ClassLoader cl = WebBeansUtil.getCurrentClassLoader();
         Enumeration<URL> propertyUrls = cl.getResources(propertyFileName);
         if (propertyUrls == null || !propertyUrls.hasMoreElements())
         {
-            if(logger.isLoggable(Level.INFO))
-            {
-                logger.info("could not find any property files with name " + propertyFileName);
  
-            }
-            
+            onMissing.run();
             return null;
         }
 
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/config/PropertyLoaderTest.java
b/webbeans-impl/src/test/java/org/apache/webbeans/test/config/PropertyLoaderTest.java
index 863467d..9e28283 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/config/PropertyLoaderTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/config/PropertyLoaderTest.java
@@ -65,8 +65,8 @@ public class PropertyLoaderTest
         try
         {
             final Properties p = PropertyLoader.getProperties(PROPERTY_FILE4, props ->
-                    props.stream().sorted(comparing(it -> Integer.parseInt(it.getProperty("order"))))
-                            .findFirst().orElseThrow(IllegalStateException::new));
+                    props.stream().min(comparing(it -> Integer.parseInt(it.getProperty("order"))))
+                            .orElseThrow(IllegalStateException::new), () -> {});
             Assert.assertNotNull(p);
 
             String testValue = p.getProperty("testConfig");


Mime
View raw message