Simplify multi-runtime
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / api / init / RuntimeManager.java
index cb8caeda9366c9c8d47c5ac19e29e49ae4bae6da..302237f5ef932d4380fb1740bbe39b50b902c950 100644 (file)
@@ -2,6 +2,8 @@ package org.argeo.api.init;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.io.UncheckedIOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -19,6 +21,20 @@ public interface RuntimeManager {
 
        public void closeRuntime(String relPath, boolean async);
 
+       default void startRuntime(String relPath, String props) {
+               Properties properties = new Properties();
+               try (Reader reader = new StringReader(props)) {
+                       properties.load(reader);
+               } catch (IOException e) {
+                       throw new IllegalArgumentException("Cannot load properties", e);
+               }
+               startRuntime(relPath, (config) -> {
+                       for (Object key : properties.keySet()) {
+                               config.put(key.toString(), properties.getProperty(key.toString()));
+                       }
+               });
+       }
+
        /**
         * Load configs recursively starting with the parent directories, until a
         * jvm.args file is found.