|
1 | 1 | package io.quarkus.runtime.configuration;
|
2 | 2 |
|
3 |
| -import static io.smallrye.config.PropertiesConfigSourceProvider.classPathSources; |
4 | 3 | import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_LOCATIONS;
|
5 | 4 | import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
|
6 | 5 | import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE_PARENT;
|
7 |
| -import static io.smallrye.config.SmallRyeConfigBuilder.META_INF_MICROPROFILE_CONFIG_PROPERTIES; |
8 | 6 |
|
9 |
| -import java.io.IOException; |
10 | 7 | import java.lang.reflect.InvocationTargetException;
|
11 |
| -import java.net.URL; |
12 | 8 | import java.util.ArrayList;
|
13 | 9 | import java.util.Collection;
|
14 |
| -import java.util.Collections; |
15 | 10 | import java.util.Comparator;
|
16 | 11 | import java.util.HashMap;
|
17 | 12 | import java.util.LinkedHashSet;
|
|
36 | 31 | import io.smallrye.config.ConfigSourceInterceptorContext;
|
37 | 32 | import io.smallrye.config.ConfigSourceInterceptorFactory;
|
38 | 33 | import io.smallrye.config.DotEnvConfigSourceProvider;
|
39 |
| -import io.smallrye.config.EnvConfigSource; |
40 | 34 | import io.smallrye.config.FallbackConfigSourceInterceptor;
|
41 | 35 | import io.smallrye.config.NameIterator;
|
42 | 36 | import io.smallrye.config.Priorities;
|
43 | 37 | import io.smallrye.config.RelocateConfigSourceInterceptor;
|
44 | 38 | import io.smallrye.config.SmallRyeConfig;
|
45 | 39 | import io.smallrye.config.SmallRyeConfigBuilder;
|
46 |
| -import io.smallrye.config.SysPropConfigSource; |
47 |
| -import io.smallrye.config.common.utils.ConfigSourceUtil; |
48 | 40 |
|
49 | 41 | /**
|
50 | 42 | *
|
@@ -100,24 +92,17 @@ public static SmallRyeConfigBuilder configBuilder(final boolean runTime, final b
|
100 | 92 |
|
101 | 93 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
102 | 94 | builder.forClassLoader(classLoader);
|
| 95 | + builder.addDefaultSources(); |
103 | 96 | builder.withSources(new ApplicationPropertiesConfigSourceLoader.InFileSystem());
|
104 | 97 | builder.withSources(new ApplicationPropertiesConfigSourceLoader.InClassPath());
|
| 98 | + builder.withSources(new DotEnvConfigSourceProvider()); |
105 | 99 | if (launchMode.isDevOrTest() && (runTime || bootstrap)) {
|
106 | 100 | builder.withSources(new RuntimeOverrideConfigSource(classLoader));
|
107 | 101 | }
|
108 | 102 | if (runTime || bootstrap) {
|
109 |
| - builder.addDefaultSources(); |
110 | 103 | // Validator only for runtime. We cannot use the current validator for build time (chicken / egg problem)
|
111 | 104 | builder.addDiscoveredValidator();
|
112 | 105 | builder.withDefaultValue(UUID_KEY, UUID.randomUUID().toString());
|
113 |
| - builder.withSources(new DotEnvConfigSourceProvider()); |
114 |
| - } else { |
115 |
| - List<ConfigSource> sources = new ArrayList<>(); |
116 |
| - sources.addAll(classPathSources(META_INF_MICROPROFILE_CONFIG_PROPERTIES, classLoader)); |
117 |
| - sources.addAll(new BuildTimeDotEnvConfigSourceProvider().getConfigSources(classLoader)); |
118 |
| - sources.add(new BuildTimeEnvConfigSource()); |
119 |
| - sources.add(new BuildTimeSysPropConfigSource()); |
120 |
| - builder.withSources(sources); |
121 | 106 | }
|
122 | 107 | if (addDiscovered) {
|
123 | 108 | builder.addDiscoveredSources();
|
@@ -336,77 +321,9 @@ public static <T> Optional<T> getFirstOptionalValue(List<String> propertyNames,
|
336 | 321 | return Optional.empty();
|
337 | 322 | }
|
338 | 323 |
|
339 |
| - /** |
340 |
| - * We override the EnvConfigSource, because we don't want the nothing back from getPropertiesNames at build time. |
341 |
| - * The mapping is one way and there is no way to map them back. |
342 |
| - */ |
343 |
| - static class BuildTimeEnvConfigSource extends EnvConfigSource { |
344 |
| - BuildTimeEnvConfigSource() { |
345 |
| - super(); |
346 |
| - } |
347 |
| - |
348 |
| - BuildTimeEnvConfigSource(final Map<String, String> propertyMap, final int ordinal) { |
349 |
| - super(propertyMap, ordinal); |
350 |
| - } |
351 |
| - |
352 |
| - @Override |
353 |
| - public Set<String> getPropertyNames() { |
354 |
| - return Collections.emptySet(); |
355 |
| - } |
356 |
| - |
357 |
| - @Override |
358 |
| - public String getName() { |
359 |
| - return "System environment"; |
360 |
| - } |
361 |
| - } |
362 |
| - |
363 |
| - /** |
364 |
| - * Same as BuildTimeEnvConfigSource. |
365 |
| - */ |
366 |
| - static class BuildTimeDotEnvConfigSourceProvider extends DotEnvConfigSourceProvider { |
367 |
| - public BuildTimeDotEnvConfigSourceProvider() { |
368 |
| - super(); |
369 |
| - } |
370 |
| - |
371 |
| - public BuildTimeDotEnvConfigSourceProvider(final String location) { |
372 |
| - super(location); |
373 |
| - } |
374 |
| - |
375 |
| - @Override |
376 |
| - protected ConfigSource loadConfigSource(final URL url, final int ordinal) throws IOException { |
377 |
| - return new BuildTimeEnvConfigSource(ConfigSourceUtil.urlToMap(url), ordinal) { |
378 |
| - @Override |
379 |
| - public String getName() { |
380 |
| - return super.getName() + "[source=" + url + "]"; |
381 |
| - } |
382 |
| - }; |
383 |
| - } |
384 |
| - } |
385 |
| - |
386 |
| - /** |
387 |
| - * We only want to include properties in the quarkus namespace. |
388 |
| - * |
389 |
| - * We removed the filter on the quarkus namespace due to the any prefix support for ConfigRoot. Filtering is now |
390 |
| - * done in io.quarkus.deployment.configuration.BuildTimeConfigurationReader.ReadOperation#getAllProperties. |
391 |
| - */ |
392 |
| - static class BuildTimeSysPropConfigSource extends SysPropConfigSource { |
393 |
| - public String getName() { |
394 |
| - return "System properties"; |
395 |
| - } |
396 |
| - |
397 |
| - @Override |
398 |
| - public Set<String> getPropertyNames() { |
399 |
| - return Collections.emptySet(); |
400 |
| - } |
401 |
| - } |
402 |
| - |
403 | 324 | private static class ConfigBuilderComparator implements Comparator<ConfigBuilder> {
|
404 |
| - |
405 | 325 | private static final ConfigBuilderComparator INSTANCE = new ConfigBuilderComparator();
|
406 | 326 |
|
407 |
| - private ConfigBuilderComparator() { |
408 |
| - } |
409 |
| - |
410 | 327 | @Override
|
411 | 328 | public int compare(ConfigBuilder o1, ConfigBuilder o2) {
|
412 | 329 | return Integer.compare(o1.priority(), o2.priority());
|
|
0 commit comments