package io.quarkus.runtime.configuration;

import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

import org.eclipse.microprofile.config.spi.ConfigSource;

import io.smallrye.config.PropertiesConfigSource;

/**
 *
 */
public final class BuildTimeConfigFactory {

    public static final String BUILD_TIME_CONFIG_NAME = "META-INF/build-config.properties";

    private BuildTimeConfigFactory() {
    }

    public static ConfigSource getBuildTimeConfigSource() {
        Properties properties = new Properties();
        try (InputStream is = BuildTimeConfigFactory.class.getClassLoader().getResourceAsStream(BUILD_TIME_CONFIG_NAME)) {
            if (is != null)
                try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
                    properties.load(isr);
                }
            return new PropertiesConfigSource(properties, "Build time configuration");
        } catch (IOException e) {
            throw new IOError(e);
        }
    }
}

@@ -150,16 +150,37 @@
 Reader;%0A
+import java.net.URL;%0A
 import j
@@ -213,16 +213,46 @@
 arsets;%0A
+import java.util.Enumeration;%0A
 import j
@@ -699,123 +699,369 @@
     
-try (InputStream is = BuildTimeConfigFactory.class.getClassLoader().getResourceAsStream(BUILD_TIME_CONFIG_NAME)) %7B%0A
+final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();%0A        try %7B%0A            final Enumeration%3CURL%3E resources = classLoader.getResources(BUILD_TIME_CONFIG_NAME);%0A            if (resources.hasMoreElements()) %7B%0A                final URL url = resources.nextElement();%0A                try (InputStream is = url.openStream()) %7B%0A        
     
@@ -1084,16 +1084,24 @@
 = null)%0A
+        
         
@@ -1210,16 +1210,24 @@
         
+        
 properti
@@ -1240,24 +1240,64 @@
 d(isr);%0A    
+                    %7D%0A                %7D%0A
             

Load build config from correct class loader