X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Fapi%2Finit%2FRuntimeManager.java;h=2344a86884fee44978dd2bc03aca3bd00db0223f;hb=2067f02c749114ea49d23a443ff4fa8cd3e6d30f;hp=302237f5ef932d4380fb1740bbe39b50b902c950;hpb=9a3cf6732b7b42d19e113bce32c799b283b8f79b;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 302237f5e..2344a8688 100644 --- a/org.argeo.init/src/org/argeo/api/init/RuntimeManager.java +++ b/org.argeo.init/src/org/argeo/api/init/RuntimeManager.java @@ -15,30 +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> 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 config, Properties properties) { + for (Object key : properties.keySet()) { + config.put(key.toString(), properties.getProperty(key.toString())); + } + } + + static void loadProperties(Map 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); } - startRuntime(relPath, (config) -> { - for (Object key : properties.keySet()) { - config.put(key.toString(), properties.getProperty(key.toString())); - } - }); + loadProperties(config, properties); + } + + static void loadProperties(Map config, InputStream in) throws IOException { + Properties properties = new Properties(); + properties.load(in); + loadProperties(config, properties); + } + + static void loadDefaults(Map 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 config) { try { Path jvmArgsPath = dir.resolve(RuntimeManager.JVM_ARGS); @@ -63,6 +88,7 @@ public interface RuntimeManager { * starts with a '+' character, itis expected that the last character is a * separator and it will be prepended to the existing value. */ + @Deprecated static void loadConfig(InputStream in, Map config) throws IOException { Properties props = new Properties(); props.load(in);