DELTASPIKE-1465 print effective ConfigSource per value
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 f070551..a7f9c48 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.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 @@
// 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 @@
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 39693d0..6aee67c 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 @@
@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 @@
.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");
}