@Test public void testSystemProperty() throws Exception { System.setProperty("org.apache.karaf.shell.sshPort", "8102"); KarafConfigurationPlugin plugin = new KarafConfigurationPlugin(); Dictionary<String, Object> properties = new Hashtable<>(); properties.put(Constants.SERVICE_PID, "org.apache.karaf.shell"); properties.put("foo", "bar"); properties.put("sshPort", 8101); plugin.modifyConfiguration(null, properties); Assert.assertEquals(8102, properties.get("sshPort")); Assert.assertEquals("bar", properties.get("foo")); }
@Override public void modifyConfiguration(ServiceReference<?> reference, Dictionary<String, Object> properties) { final Object pid = properties.get(Constants.SERVICE_PID); for (Enumeration<String> keys = properties.keys(); keys.hasMoreElements(); ) { String key = keys.nextElement(); String env = (pid + "." + key).toUpperCase().replaceAll("\\.", "_"); 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)); } else { 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)); } else { properties.put(key, value); } } } }
KarafConfigurationPlugin implements ConfigurationPlugin { @Override public void modifyConfiguration(ServiceReference<?> reference, Dictionary<String, Object> properties) { final Object pid = properties.get(Constants.SERVICE_PID); for (Enumeration<String> keys = properties.keys(); keys.hasMoreElements(); ) { String key = keys.nextElement(); String env = (pid + "." + key).toUpperCase().replaceAll("\\.", "_"); 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)); } else { 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)); } else { properties.put(key, value); } } } } }
KarafConfigurationPlugin implements ConfigurationPlugin { @Override public void modifyConfiguration(ServiceReference<?> reference, Dictionary<String, Object> properties) { final Object pid = properties.get(Constants.SERVICE_PID); for (Enumeration<String> keys = properties.keys(); keys.hasMoreElements(); ) { String key = keys.nextElement(); String env = (pid + "." + key).toUpperCase().replaceAll("\\.", "_"); 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)); } else { 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)); } else { properties.put(key, value); } } } }  }
KarafConfigurationPlugin implements ConfigurationPlugin { @Override public void modifyConfiguration(ServiceReference<?> reference, Dictionary<String, Object> properties) { final Object pid = properties.get(Constants.SERVICE_PID); for (Enumeration<String> keys = properties.keys(); keys.hasMoreElements(); ) { String key = keys.nextElement(); String env = (pid + "." + key).toUpperCase().replaceAll("\\.", "_"); 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)); } else { 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)); } else { properties.put(key, value); } } } }  @Override void modifyConfiguration(ServiceReference<?> reference, Dictionary<String, Object> properties); }
KarafConfigurationPlugin implements ConfigurationPlugin { @Override public void modifyConfiguration(ServiceReference<?> reference, Dictionary<String, Object> properties) { final Object pid = properties.get(Constants.SERVICE_PID); for (Enumeration<String> keys = properties.keys(); keys.hasMoreElements(); ) { String key = keys.nextElement(); String env = (pid + "." + key).toUpperCase().replaceAll("\\.", "_"); 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)); } else { 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)); } else { properties.put(key, value); } } } }  @Override void modifyConfiguration(ServiceReference<?> reference, Dictionary<String, Object> properties); static final String PLUGIN_ID; static final int PLUGIN_RANKING; }