geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1833281 - in /geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config: DefaultConfigBuilder.java configsource/PropertyFileConfigSourceProvider.java
Date Sun, 10 Jun 2018 14:59:43 GMT
Author: struberg
Date: Sun Jun 10 14:59:43 2018
New Revision: 1833281

URL: http://svn.apache.org/viewvc?rev=1833281&view=rev
Log:
workaround for differently behaving classloaders regarding leading /


Modified:
    geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
    geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java

Modified: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java?rev=1833281&r1=1833280&r2=1833281&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
(original)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
Sun Jun 10 14:59:43 2018
@@ -159,7 +159,7 @@ public class DefaultConfigBuilder implem
 
         configSources.add(new SystemEnvConfigSource());
         configSources.add(new SystemPropertyConfigSource());
-        configSources.addAll(new PropertyFileConfigSourceProvider("/META-INF/microprofile-config.properties",
true, forClassLoader).getConfigSources(forClassLoader));
+        configSources.addAll(new PropertyFileConfigSourceProvider("META-INF/microprofile-config.properties",
true, forClassLoader).getConfigSources(forClassLoader));
 
         return configSources;
     }

Modified: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java?rev=1833281&r1=1833280&r2=1833281&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
(original)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
Sun Jun 10 14:59:43 2018
@@ -21,8 +21,11 @@ package org.apache.geronimo.config.confi
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -48,14 +51,12 @@ public class PropertyFileConfigSourcePro
 
     public PropertyFileConfigSourceProvider(String propertyFileName, boolean optional, ClassLoader
forClassLoader) {
         try {
-            Enumeration<URL> propertyFileUrls = resolvePropertyFiles(forClassLoader,
propertyFileName);
-
-            if (!optional && !propertyFileUrls.hasMoreElements()) {
+            Collection<URL> propertyFileUrls = resolvePropertyFiles(forClassLoader,
propertyFileName);
+            if (!optional && propertyFileUrls.isEmpty()) {
                 throw new IllegalStateException(propertyFileName + " wasn't found.");
             }
 
-            while (propertyFileUrls.hasMoreElements()) {
-                URL propertyFileUrl = propertyFileUrls.nextElement();
+            for (URL propertyFileUrl : propertyFileUrls) {
                 LOG.log(Level.INFO,
                         "Custom config found by GeronimoConfig. Name: ''{0}'', URL: ''{1}''",
                         new Object[]{propertyFileName, propertyFileUrl});
@@ -68,9 +69,23 @@ public class PropertyFileConfigSourcePro
 
     }
 
-    public Enumeration<URL> resolvePropertyFiles(ClassLoader cl, String propertyFileName)
throws IOException {
-        Enumeration<URL> propertyFileUrls = cl.getResources(propertyFileName);
+    public Collection<URL> resolvePropertyFiles(ClassLoader forClassLoader, String
propertyFileName) throws IOException {
+        // de-duplicate
+        Map<String, URL> propertyFileUrls = resolveUrls(propertyFileName, forClassLoader);
+
+        // and once again with preceding a "/"
+        propertyFileUrls.putAll(resolveUrls("/" + propertyFileName, forClassLoader));
 
+        return propertyFileUrls.values();
+    }
+
+    private Map<String, URL> resolveUrls(String propertyFileName, ClassLoader forClassLoader)
throws IOException {
+        Map<String, URL> propertyFileUrls = new HashMap<>();
+        Enumeration<URL> urls = forClassLoader.getResources(propertyFileName);
+        while (urls.hasMoreElements()) {
+            URL url = urls.nextElement();
+            propertyFileUrls.put(url.toExternalForm(), url);
+        }
         return propertyFileUrls;
     }
 



Mime
View raw message