+ /*
+ * PLAIN OSGI LAUNCHER
+ */
+ /** Launch an OSGi framework. OSGi Boot initialisation is NOT performed. */
+ public static Framework defaultOsgiLaunch(Map<String, String> configuration) {
+ Optional<FrameworkFactory> frameworkFactory = ServiceLoader.load(FrameworkFactory.class).findFirst();
+ if (frameworkFactory.isEmpty())
+ throw new IllegalStateException("No framework factory found");
+ return defaultOsgiLaunch(frameworkFactory.get(), configuration);
+ }
+
+ /** Launch an OSGi framework. OSGi Boot initialisation is NOT performed. */
+ public static Framework defaultOsgiLaunch(FrameworkFactory frameworkFactory, Map<String, String> configuration) {
+ // start OSGi
+ Framework framework = frameworkFactory.newFramework(configuration);
+ try {
+ framework.start();
+ } catch (BundleException e) {
+ throw new IllegalStateException("Cannot start OSGi framework", e);
+ }
+ return framework;
+ }
+
+ /*
+ * OSGI UTILITIES
+ */
+ /** Uninstall all bundles with these symbolic names */
+ public static void uninstallBundles(BundleContext bc, String... symbolicNames) {
+ List<String> lst = Arrays.asList(symbolicNames);
+ for (Bundle b : bc.getBundles()) {
+ String sn = b.getSymbolicName();
+ if (sn == null)
+ continue;
+ if (lst.contains(sn)) {
+ try {
+ b.uninstall();
+ } catch (BundleException e) {
+ logger.log(ERROR, "Cannot uninstall " + sn, e);
+ }
+ }
+ }
+
+ }