]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.init/src/org/argeo/api/init/RuntimeManager.java
Fix IPA initialisation
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / api / init / RuntimeManager.java
index cb8caeda9366c9c8d47c5ac19e29e49ae4bae6da..649ae17f50884486baa75d538ca7f75b487e1b46 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;
@@ -13,16 +15,55 @@ import java.util.function.Consumer;
 public interface RuntimeManager {
        String JVM_ARGS = "jvm.args";
        String STATE = "state";
+       String OSGI_STORAGE_DIRNAME = "osgi";
        String DATA = "data";
+       String SHARED = "shared";
 
        public void startRuntime(String relPath, Consumer<Map<String, String>> configCallback);
 
        public void closeRuntime(String relPath, boolean async);
 
+       default void startRuntime(String relPath, String props) {
+               startRuntime(relPath, (config) -> {
+                       loadProperties(config, props);
+               });
+       }
+
+       static void loadProperties(Map<String, String> config, Properties properties) {
+               for (Object key : properties.keySet()) {
+                       config.put(key.toString(), properties.getProperty(key.toString()));
+               }
+       }
+
+       static void loadProperties(Map<String, String> config, 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);
+               }
+               loadProperties(config, properties);
+       }
+
+       static void loadProperties(Map<String, String> config, InputStream in) throws IOException {
+               Properties properties = new Properties();
+               properties.load(in);
+               loadProperties(config, properties);
+       }
+
+       static void loadDefaults(Map<String, String> config) {
+               try (InputStream in = RuntimeManager.class.getResourceAsStream("defaults.ini")) {
+                       loadProperties(config, in);
+               } catch (IOException e) {
+                       throw new IllegalStateException("Could not load runtime defaults", e);
+               }
+       }
+
        /**
         * Load configs recursively starting with the parent directories, until a
         * jvm.args file is found.
         */
+       @Deprecated
        static void loadConfig(Path dir, Map<String, String> config) {
                try {
                        Path jvmArgsPath = dir.resolve(RuntimeManager.JVM_ARGS);
@@ -44,9 +85,10 @@ public interface RuntimeManager {
 
        /**
         * Load config from a {@link Properties} formatted stream. If a property value
-        * starts with a '+' character, itis expected that the last character is a
+        * starts with a '+' character, it is expected that the last character is a
         * separator and it will be prepended to the existing value.
         */
+       @Deprecated
        static void loadConfig(InputStream in, Map<String, String> config) throws IOException {
                Properties props = new Properties();
                props.load(in);