You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/02/06 16:47:44 UTC
[camel] 03/04: CAMEL-16160: camel-main - JVM system properties
should override application.properties
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7c9eeab5013976fa0c7bf8a84cc249a82022e677
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 6 17:37:07 2021 +0100
CAMEL-16160: camel-main - JVM system properties should override application.properties
---
.../src/main/java/org/apache/camel/main/BaseMainSupport.java | 8 ++++++++
.../src/main/java/org/apache/camel/main/MainHelper.java | 10 +++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 1c16fa9..ab1ac48 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -1076,6 +1076,7 @@ public abstract class BaseMainSupport extends BaseService {
// load properties from ENV (override existing)
if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) {
Properties propENV = loadEnvironmentVariablesAsProperties(new String[] { "camel.main." });
+ // special handling of these so remove them
// ENV variables cannot use dash so replace with dot
propENV.remove(INITIAL_PROPERTIES_LOCATION.replace('-', '.'));
propENV.remove(OVERRIDE_PROPERTIES_LOCATION.replace('-', '.'));
@@ -1087,6 +1088,13 @@ public abstract class BaseMainSupport extends BaseService {
// load properties from JVM (override existing)
if (mainConfigurationProperties.isAutoConfigurationSystemPropertiesEnabled()) {
Properties propJVM = loadJvmSystemPropertiesAsProperties(new String[] { "camel.main." });
+ // special handling of these so remove them
+ propJVM.remove(INITIAL_PROPERTIES_LOCATION);
+ propJVM.remove(StringHelper.dashToCamelCase(INITIAL_PROPERTIES_LOCATION));
+ propJVM.remove(OVERRIDE_PROPERTIES_LOCATION);
+ propJVM.remove(StringHelper.dashToCamelCase(OVERRIDE_PROPERTIES_LOCATION));
+ propJVM.remove(PROPERTY_PLACEHOLDER_LOCATION);
+ propJVM.remove(StringHelper.dashToCamelCase(PROPERTY_PLACEHOLDER_LOCATION));
if (!propJVM.isEmpty()) {
prop.putAll(propJVM);
}
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java b/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java
index c48cad0..8412e8d 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java
@@ -86,11 +86,15 @@ public final class MainHelper {
for (String prefix : prefixes) {
final String pk = prefix.toUpperCase(Locale.US).replaceAll("[^\\w]", "-");
final String pk2 = pk.replace('-', '.');
+ Map<String, String> env = System.getenv();
System.getProperties().forEach((k, v) -> {
String key = k.toString().toUpperCase(Locale.US);
- if (key.startsWith(pk) || key.startsWith(pk2)) {
- key = key.toLowerCase(Locale.ENGLISH).replace('_', '.');
- answer.put(key, v);
+ if (!env.containsKey(key)) {
+ // skip keys that are already from ENV so we don't process it twice
+ // as we only want to do this for JVM system properties
+ if (key.startsWith(pk) || key.startsWith(pk2)) {
+ answer.put(k.toString(), v);
+ }
}
});
}