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/deltaspike.git
commit 5fcbc344919e74baf14dad92e931a96b3dd3bd4f Author: Mark Struberg <[email protected]> AuthorDate: Wed May 10 11:40:59 2023 +0200 DELTASPIKE-1465 print effective ConfigSource per value --- .../core/impl/config/ConfigurationExtension.java | 33 ++++++++++++++++++++-- .../ConfigPropertyWARTest.java | 6 +++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java index f07055159..a7f9c48c2 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java @@ -70,6 +70,7 @@ import org.apache.deltaspike.core.spi.config.ConfigValidator; import org.apache.deltaspike.core.util.ClassDeactivationUtils; import org.apache.deltaspike.core.util.ClassUtils; import org.apache.deltaspike.core.util.ServiceUtils; +import org.apache.deltaspike.core.util.StringUtils; /** * This extension handles {@link org.apache.deltaspike.core.api.config.PropertyFileConfig}s @@ -340,9 +341,11 @@ public class ConfigurationExtension implements Extension, Deactivatable // first log out the config sources in descendent ordinal order sb.append("ConfigSources: "); ConfigSource[] configSources = ConfigResolver.getConfigSources(); - for (ConfigSource configSource : configSources) + for (int i = 0; i < configSources.length; i++) { - sb.append("\n\t").append(configSource.getOrdinal()).append(" - ").append(configSource.getConfigName()); + ConfigSource configSource = configSources[i]; + sb.append("\n\t").append(configSource.getOrdinal()).append(" - ").append(configSource.getConfigName()) + .append(" (CS_").append(i + 1).append(")"); } // and all the entries in no guaranteed order @@ -350,16 +353,40 @@ public class ConfigurationExtension implements Extension, Deactivatable sb.append("\n\nConfigured Values:"); for (Map.Entry<String, String> entry : allProperties.entrySet()) { + int fromConfigSource; + sb.append("\n\t") .append(entry.getKey()) .append(" = ") - .append(ConfigResolver.filterConfigValueForLog(entry.getKey(), entry.getValue())); + .append(ConfigResolver.filterConfigValueForLog(entry.getKey(), entry.getValue())) + .append(" (") + .append(configuredIn(configSources, entry.getKey())) + .append(")"); } LOG.info(sb.toString()); } } + private static String configuredIn(ConfigSource[] configSources, String key) + { + int foundInOrdinal = -1; + int foundInConfigSource = -1; + + for (int i = 0; i < configSources.length; i++) + { + ConfigSource configSource = configSources[i]; + if ((configSource.isScannable() && configSource.getProperties().containsKey(key) || + !configSource.isScannable() && StringUtils.isNotEmpty(configSource.getPropertyValue(key))) + && configSource.getOrdinal() > foundInOrdinal) + { + foundInConfigSource = i; + foundInOrdinal = configSource.getOrdinal(); + } + } + return "CS_" + (foundInConfigSource + 1); + } + /** * Add all registered PropertyFileConfigs which got picked up in a parent ClassLoader already */ diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/ConfigPropertyWARTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/ConfigPropertyWARTest.java index 39693d0ec..6aee67ce9 100644 --- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/ConfigPropertyWARTest.java +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/ConfigPropertyWARTest.java @@ -18,6 +18,7 @@ */ package org.apache.deltaspike.test.core.api.config.propertyconfigsource; +import org.apache.deltaspike.core.api.config.ConfigResolver; import org.apache.deltaspike.test.category.WebProfileCategory; import org.apache.deltaspike.test.util.ArchiveUtils; import org.jboss.arquillian.container.test.api.Deployment; @@ -33,6 +34,9 @@ import org.junit.runner.RunWith; @Category(WebProfileCategory.class) public class ConfigPropertyWARTest extends BaseTestConfigProperty { + private final static String PROPERTIES = + "org.apache.deltaspike.ProjectStage = UnitTest\n" + + ConfigResolver.DELTASPIKE_LOG_CONFIG + " = true"; @Deployment public static WebArchive deployEar() @@ -42,7 +46,7 @@ public class ConfigPropertyWARTest extends BaseTestConfigProperty .addPackage(ConfigPropertyWARTest.class.getPackage()) .addAsResource(CONFIG_FILE_NAME) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsWebInfResource(new StringAsset("org.apache.deltaspike.ProjectStage = UnitTest"), + .addAsWebInfResource(new StringAsset(PROPERTIES), "classes/META-INF/apache-deltaspike.properties"); }
