This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch karaf-4.4.x
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/karaf-4.4.x by this push:
new 01d398dc29 Deal with Array in config env variable and system property
(#2181)
01d398dc29 is described below
commit 01d398dc297e542b3b8e5dd062d8bbad1cb75fd9
Author: JB Onofré <[email protected]>
AuthorDate: Thu Dec 4 08:26:29 2025 +0100
Deal with Array in config env variable and system property (#2181)
---
.../config/core/impl/KarafConfigurationPlugin.java | 40 +++++++++++++++++-----
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git
a/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
b/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
index 4adb316d15..56261ca0e4 100644
---
a/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
+++
b/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
@@ -33,23 +33,47 @@ public class KarafConfigurationPlugin implements
ConfigurationPlugin {
final Object pid = properties.get(Constants.SERVICE_PID);
for (Enumeration<String> keys = properties.keys();
keys.hasMoreElements(); ) {
String key = keys.nextElement();
+
// looking for env variable and system property matching key
(pid.key).toUpperCase().replace('.', '_').replace('-', '_').replace('~', '_')
String env = (pid + "." + key).toUpperCase().replaceAll("\\.",
"_").replace("-", "_").replace("~", "_");
String sys = pid + "." + key;
+
if (System.getenv(env) != null) {
- String value =
InterpolationHelper.substVars(System.getenv(env), null,null,
convertDictionaryToMap(properties));
- if (properties.get(key) != null && (properties.get(key)
instanceof Number)) {
- properties.put(key, Integer.parseInt(value));
+
+ String value = System.getenv(env);
+
+ if (value.startsWith("[") && value.endsWith("]")) {
+ String[] values = value.substring(1, value.length() -
1).split(",");
+ values = Arrays.stream(values).<String>map(e ->
InterpolationHelper.substVars(e, null,null,
convertDictionaryToMap(properties))).toArray(String[]::new);
+ properties.put(key, values);
} else {
- properties.put(key, value);
+ value = InterpolationHelper.substVars(value, null,null,
convertDictionaryToMap(properties));
+ try {
+ int intValue = Integer.parseInt(value);
+ properties.put(key, intValue);
+ } catch (NumberFormatException e) {
+ properties.put(key, value);
+ }
}
+
} else if (System.getProperty(sys) != null) {
- String value =
InterpolationHelper.substVars(System.getProperty(sys), null, null,
convertDictionaryToMap(properties));
- if (properties.get(key) != null && (properties.get(key)
instanceof Number)) {
- properties.put(key, Integer.parseInt(value));
+
+ String value = System.getProperty(sys);
+
+ if (value.startsWith("[") && value.endsWith("]")) {
+ String[] values= value.substring(1, value.length() -
1).split(",");
+ values = Arrays.stream(values).<String>map(e ->
InterpolationHelper.substVars(e, null,null,
convertDictionaryToMap(properties))).toArray(String[]::new);
+ properties.put(key, values);
} else {
- properties.put(key, value);
+ value = InterpolationHelper.substVars(value, null,null,
convertDictionaryToMap(properties));
+ try {
+ int intValue = Integer.parseInt(value);
+ properties.put(key, intValue);
+ } catch (NumberFormatException e) {
+ properties.put(key, value);
+ }
}
+
}
}
}