X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Fapi%2Finit%2FRuntimeManager.java;h=cb8caeda9366c9c8d47c5ac19e29e49ae4bae6da;hb=641e3f3c535f540afd122d2a7b53389342f77002;hp=da15b1ebccab4dc6d7f30a69edbec23d0bfad837;hpb=7d4cccc2f758f30e0704f2e8f500c43fd4245ebf;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/api/init/RuntimeManager.java b/org.argeo.init/src/org/argeo/api/init/RuntimeManager.java index da15b1ebc..cb8caeda9 100644 --- a/org.argeo.init/src/org/argeo/api/init/RuntimeManager.java +++ b/org.argeo.init/src/org/argeo/api/init/RuntimeManager.java @@ -19,27 +19,54 @@ public interface RuntimeManager { public void closeRuntime(String relPath, boolean async); + /** + * Load configs recursively starting with the parent directories, until a + * jvm.args file is found. + */ static void loadConfig(Path dir, Map config) { - try { - // System.out.println("Load from " + dir); - Path jvmArgsPath = dir.resolve(RuntimeManager.JVM_ARGS); - if (!Files.exists(jvmArgsPath)) { - // load from parent directory - loadConfig(dir.getParent(), config); - } - - if (Files.exists(dir)) - for (Path p : Files.newDirectoryStream(dir, "*.ini")) { - Properties props = new Properties(); - try (InputStream in = Files.newInputStream(p)) { - props.load(in); - } - for (Object key : props.keySet()) { - config.put(key.toString(), props.getProperty(key.toString())); - } + try { + Path jvmArgsPath = dir.resolve(RuntimeManager.JVM_ARGS); + if (!Files.exists(jvmArgsPath)) { + // load from parent directory + loadConfig(dir.getParent(), config); + } + + if (Files.exists(dir)) + for (Path p : Files.newDirectoryStream(dir, "*.ini")) { + try (InputStream in = Files.newInputStream(p)) { + loadConfig(in, config); } - } catch (IOException e) { - throw new UncheckedIOException("Cannot load configuration from " + dir, e); + } + } catch (IOException e) { + throw new UncheckedIOException("Cannot load configuration from " + dir, e); + } + } + + /** + * Load config from a {@link Properties} formatted stream. If a property value + * starts with a '+' character, itis expected that the last character is a + * separator and it will be prepended to the existing value. + */ + static void loadConfig(InputStream in, Map config) throws IOException { + Properties props = new Properties(); + props.load(in); + for (Object k : props.keySet()) { + String key = k.toString(); + String value = props.getProperty(key); + if (value.length() > 1 && '+' == value.charAt(0)) { + String currentValue = config.get(key); + if (currentValue == null || "".equals(currentValue)) { + // remove the + and the trailing separator + value = value.substring(1, value.length() - 1); + config.put(key, value); + } else { + // remove the + but keep the trailing separator + value = value.substring(1); + config.put(key, value + currentValue); + } + } else { + config.put(key, value); } } + } }