openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [openwebbeans-meecrowave] branch master updated: MEECROWAVE-203 allow multiple meecrowave.properties on the CP
Date Mon, 15 Jul 2019 08:50:40 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 8e2a8f6  MEECROWAVE-203 allow multiple meecrowave.properties on the CP
8e2a8f6 is described below

commit 8e2a8f6a2d6e9a222e09b37b735ba056575a4293
Author: Mark Struberg <struberg@apache.org>
AuthorDate: Mon Jul 15 10:28:21 2019 +0200

    MEECROWAVE-203 allow multiple meecrowave.properties on the CP
    
    When having multiple meecrowave.properties on the classpath they
    are now being sorted according to their ordinal.
    Just add an entry configuration.ordinal=n where n is an intenger.
    The higher the ordinal number, the more important that property file.
    A file without any configuration.ordinal has ordinal=100.
---
 .../java/org/apache/meecrowave/Meecrowave.java     | 37 ++++++++++------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
index 200a651..0028c60 100644
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
+++ b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
@@ -29,7 +29,6 @@ import static java.util.stream.Collectors.toSet;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -129,6 +128,7 @@ import org.apache.tomcat.util.descriptor.web.SecurityCollection;
 import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
 import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.net.SSLHostConfig;
+import org.apache.webbeans.config.PropertyLoader;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.xbean.finder.ResourceFinder;
 import org.apache.xbean.recipe.ObjectRecipe;
@@ -2050,17 +2050,24 @@ public class Meecrowave implements AutoCloseable {
         }
 
         public Builder loadFrom(final String resource) {
-            try (final InputStream is = findStream(resource)) {
-                if (is != null) {
-                    final Properties config = new Properties() {{
-                        load(is);
-                    }};
-                    loadFromProperties(config);
+            // load all of those files on the classpath, sorted by ordinal
+            Properties config = PropertyLoader.getProperties(resource);
+            if (config == null) {
+                final File file = new File(resource);
+                if (file.exists()) {
+                    config = new Properties();
+                    try (InputStream is = new FileInputStream(file)) {
+                        config.load(is);
+                    }
+                    catch (IOException e) {
+                        throw new IllegalStateException(e);
+                    }
                 }
-                return this;
-            } catch (final IOException e) {
-                throw new IllegalStateException(e);
             }
+            if (config != null) {
+                loadFromProperties(config);
+            }
+            return this;
         }
 
         public void setServerXml(final String file) {
@@ -2079,16 +2086,6 @@ public class Meecrowave implements AutoCloseable {
             return this;
         }
 
-        private InputStream findStream(final String resource) throws FileNotFoundException
{
-            InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
-            if (stream == null) {
-                final File file = new File(resource);
-                if (file.exists()) {
-                    return new FileInputStream(file);
-                }
-            }
-            return stream;
-        }
 
         public Builder user(final String name, final String pwd) {
             if (users == null) {


Mime
View raw message