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 4adb316d15f..56261ca0e41 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 void modifyConfiguration(ServiceReference reference, Dictionary 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).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).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); + } } + } } }