From: Mathieu Baudier Date: Sat, 11 May 2024 09:45:54 +0000 (+0200) Subject: Make using foreign runtime configurable X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=refs%2Fremotes%2Fgithub%2Funstable Make using foreign runtime configurable --- diff --git a/org.argeo.init/src/org/argeo/api/init/InitConstants.java b/org.argeo.init/src/org/argeo/api/init/InitConstants.java index 188b3c253..864749f60 100644 --- a/org.argeo.init/src/org/argeo/api/init/InitConstants.java +++ b/org.argeo.init/src/org/argeo/api/init/InitConstants.java @@ -29,6 +29,7 @@ public interface InitConstants { @Deprecated String PROP_ARGEO_OSGI_PARENT_CATEGORIES = "argeo.osgi.parent.categories"; String PROP_ARGEO_OSGI_EXPORT_CATEGORIES = "argeo.osgi.export.categories"; + String PROP_ARGEO_OSGI_EXPORT_ENABLED = "argeo.osgi.export.enabled"; // Symbolic names String SYMBOLIC_NAME_INIT = "org.argeo.init"; diff --git a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeManager.java b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeManager.java index 097ca44ea..6b5365757 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeManager.java +++ b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeManager.java @@ -45,6 +45,9 @@ class OsgiRuntimeManager implements RuntimeManager { private Map runtimeContexts = new TreeMap<>(); + private boolean useForeignRuntime = Boolean + .parseBoolean(System.getProperty(InitConstants.PROP_ARGEO_OSGI_EXPORT_ENABLED, "true")); + OsgiRuntimeManager(BundleContext bundleContext) { Objects.requireNonNull(bundleContext); this.bundleContext = bundleContext; @@ -91,38 +94,42 @@ class OsgiRuntimeManager implements RuntimeManager { OsgiRuntimeContext loadRuntime(String relPath, Consumer> configCallback) { closeRuntime(relPath, false); - BundleContext foreignBundleContext = bundleContext; - - Path parentRelPath = Paths.get(relPath).getParent(); - if (parentRelPath != null && Files.exists(baseConfigArea.resolve(parentRelPath))) { - if (!runtimeContexts.containsKey(parentRelPath.toString())) { - - String exportCategories = bundleContext.getProperty(InitConstants.PROP_ARGEO_OSGI_EXPORT_CATEGORIES); - List foreignCategories = exportCategories == null ? new ArrayList<>() - : Arrays.asList(exportCategories.trim().split(",")); - Path writableArea = baseWritableArea.resolve(parentRelPath); - Path configArea = baseConfigArea.resolve(parentRelPath); - Map config = new HashMap<>(); - RuntimeManager.loadDefaults(config); - config.put(InitConstants.PROP_OSGI_USE_SYSTEM_PROPERTIES, "false"); - config.put(InitConstants.PROP_OSGI_CONFIGURATION_AREA, writableArea.resolve(STATE).toUri().toString()); - config.put(InitConstants.PROP_OSGI_SHARED_CONFIGURATION_AREA, configArea.toUri().toString()); - config.put(InitConstants.PROP_OSGI_SHARED_CONFIGURATION_AREA_RO, "true"); - OsgiRuntimeContext runtimeContext = new OsgiRuntimeContext(frameworkFactory, config, - foreignBundleContext, foreignCategories); - runtimeContexts.put(parentRelPath.toString(), runtimeContext); - runtimeContext.run(); - // FIXME properly stage installation - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // silent + BundleContext foreignBundleContext = null; + if (useForeignRuntime) { + foreignBundleContext = bundleContext; + + Path parentRelPath = Paths.get(relPath).getParent(); + if (parentRelPath != null && Files.exists(baseConfigArea.resolve(parentRelPath))) { + if (!runtimeContexts.containsKey(parentRelPath.toString())) { + + String exportCategories = bundleContext + .getProperty(InitConstants.PROP_ARGEO_OSGI_EXPORT_CATEGORIES); + List foreignCategories = exportCategories == null ? new ArrayList<>() + : Arrays.asList(exportCategories.trim().split(",")); + Path writableArea = baseWritableArea.resolve(parentRelPath); + Path configArea = baseConfigArea.resolve(parentRelPath); + Map config = new HashMap<>(); + RuntimeManager.loadDefaults(config); + config.put(InitConstants.PROP_OSGI_USE_SYSTEM_PROPERTIES, "false"); + config.put(InitConstants.PROP_OSGI_CONFIGURATION_AREA, + writableArea.resolve(STATE).toUri().toString()); + config.put(InitConstants.PROP_OSGI_SHARED_CONFIGURATION_AREA, configArea.toUri().toString()); + config.put(InitConstants.PROP_OSGI_SHARED_CONFIGURATION_AREA_RO, "true"); + OsgiRuntimeContext runtimeContext = new OsgiRuntimeContext(frameworkFactory, config, + foreignBundleContext, foreignCategories); + runtimeContexts.put(parentRelPath.toString(), runtimeContext); + runtimeContext.run(); + // FIXME properly stage installation + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // silent + } } + OsgiRuntimeContext parentRuntimeContext = runtimeContexts.get(parentRelPath.toString()); + foreignBundleContext = parentRuntimeContext.getFramework().getBundleContext(); } - OsgiRuntimeContext parentRuntimeContext = runtimeContexts.get(parentRelPath.toString()); - foreignBundleContext = parentRuntimeContext.getFramework().getBundleContext(); } - Path writableArea = baseWritableArea.resolve(relPath); Path configArea = baseConfigArea.resolve(relPath).getParent().resolve(SHARED); Map config = new HashMap<>(); @@ -141,11 +148,15 @@ class OsgiRuntimeManager implements RuntimeManager { config.put(InitConstants.PROP_OSGI_INSTANCE_AREA, writableArea.resolve(DATA).toUri().toString()); // create framework - String exportCategories = bundleContext.getProperty(InitConstants.PROP_ARGEO_OSGI_EXPORT_CATEGORIES); - List foreignCategories = exportCategories == null ? new ArrayList<>() - : Arrays.asList(exportCategories.trim().split(",")); - OsgiRuntimeContext runtimeContext = new OsgiRuntimeContext(frameworkFactory, config, foreignBundleContext, - foreignCategories); + OsgiRuntimeContext runtimeContext; + if (useForeignRuntime) { + String exportCategories = bundleContext.getProperty(InitConstants.PROP_ARGEO_OSGI_EXPORT_CATEGORIES); + List foreignCategories = exportCategories == null ? new ArrayList<>() + : Arrays.asList(exportCategories.trim().split(",")); + runtimeContext = new OsgiRuntimeContext(frameworkFactory, config, foreignBundleContext, foreignCategories); + } else { + runtimeContext = new OsgiRuntimeContext(frameworkFactory, config); + } runtimeContexts.put(relPath, runtimeContext); return runtimeContext; }