BundleContext bc = fwk.getBundleContext(); bc.installBundle("file:/path/to/bundle.jar"); bc.registerService(MyService.class.getName(), new MyServiceImpl(), null); // ...
private Bundle getBundle(GoPluginDescriptor pluginDescriptor, File bundleLocation) { Bundle bundle = null; try { bundle = framework.getBundleContext().installBundle("reference:" + bundleLocation.toURI()); pluginDescriptor.setBundle(bundle); bundle.start(); if (pluginDescriptor.isInvalid()) { handlePluginInvalidation(pluginDescriptor, bundleLocation, bundle); return bundle; } IterableUtils.forEach(pluginChangeListeners, notifyPluginLoadedEvent(pluginDescriptor)); return bundle; } catch (Exception e) { pluginDescriptor.markAsInvalid(asList(e.getMessage()), e); LOGGER.error("Failed to load plugin: {}", bundleLocation, e); handlePluginInvalidation(pluginDescriptor, bundleLocation, bundle); throw new RuntimeException("Failed to load plugin: " + bundleLocation, e); } }
@Test public void shouldMarkThePluginAsInvalidIfAnyExceptionOccursAfterLoad() throws BundleException { final Bundle bundle = mock(Bundle.class); spy.addPluginChangeListener(new PluginChangeListener() { @Override public void pluginLoaded(GoPluginDescriptor pluginDescriptor) { throw new RuntimeException("some error"); } @Override public void pluginUnLoaded(GoPluginDescriptor pluginDescriptor) { } }); when(bundleContext.installBundle(any(String.class))).thenReturn(bundle); final GoPluginDescriptor goPluginDescriptor = new GoPluginDescriptor(TEST_SYMBOLIC_NAME, "1.0", null, "location", new File(""), false); spy.start(); try { spy.loadPlugin(goPluginDescriptor); fail("should throw exception"); } catch (Exception e) { assertTrue(goPluginDescriptor.getStatus().isInvalid()); } }
Bundle b = context.installBundle(location, null); sl.setBundleStartLevel(b, startLevel); Bundle b = context.installBundle(location, null); if (b != null)
b = context.installBundle( ((File) jarList.get(i)).toURI().toString());
/** * Installs a bundle. * @param location the URL of the bundle to install * @return the installed bundle * @throws BundleException if the bundle cannot be installed correctly * @see org.osgi.framework.BundleContext#installBundle(java.lang.String) */ public Bundle installBundle(String location) throws BundleException { return m_global.installBundle(location); }
/** * Installs a bundle. * @param location the URL of the bundle to install * @param input the input stream to load the bundle. * @return the installed bundle * @throws BundleException if the bundle cannot be installed correctly * @see org.osgi.framework.BundleContext#installBundle(java.lang.String, java.io.InputStream) */ public Bundle installBundle(String location, InputStream input) throws BundleException { return m_bundleContext.installBundle(location, input); }
/** * Installs a bundle. * @param location the URL of the bundle to install * @return the installed bundle * @throws BundleException if the bundle cannot be installed correctly * @see org.osgi.framework.BundleContext#installBundle(java.lang.String) */ public Bundle installBundle(String location) throws BundleException { return m_bundleContext.installBundle(location); }
/** * Installs a bundle. * @param location the URL of the bundle to install * @param input the input stream to load the bundle content * @return the installed bundle * @throws BundleException if the bundle cannot be installed correctly * @see org.osgi.framework.BundleContext#installBundle(java.lang.String, java.io.InputStream) */ public Bundle installBundle(String location, InputStream input) throws BundleException { return m_global.installBundle(location, input); }
/** * Install a bundle. * @param location : URL of the bundle to install * @return the installed bundle * @throws BundleException : if the bundle cannot be installed correctly * @see org.osgi.framework.BundleContext#installBundle(java.lang.String) */ public Bundle installBundle(String location) throws BundleException { return m_global.installBundle(location); }
/** * Install a bundle. * @param location : URL of the bundle to install * @param input : * @return the installed bundle * @throws BundleException : if the bundle cannot be installed correctly * @see org.osgi.framework.BundleContext#installBundle(java.lang.String, java.io.InputStream) */ public Bundle installBundle(String location, InputStream input) throws BundleException { return m_global.installBundle(location, input); }
public void installBundle(String bundleLocation, boolean start) throws Exception { Bundle bundle = bundleContext.installBundle(bundleLocation); if (start) { bundle.start(); } }
private void startBundle(BundleContext frameworkContext, String location) { // Installing twice just returns the same bundle. try { Bundle b = frameworkContext.installBundle(location, null); if (b != null) { b.start(); } } catch (Exception ex) { System.err.println("Auto-properties start: " + location + " (" + ex + ((ex.getCause() != null) ? " - " + ex.getCause() : "") + ")"); } }
public long install(String url, boolean start) throws MBeanException { try { Bundle bundle = bundleContext.installBundle(url, null); if (start) { bundle.start(); } return bundle.getBundleId(); } catch (Exception e) { throw new MBeanException(null, e.toString()); } }
public long installBundle( String bundleUrl ) throws RemoteException, BundleException { Bundle bundle = framework.getBundleContext().installBundle( bundleUrl ); return bundle.getBundleId(); }
private void installBundle(String location, BundleContext frameworkContext, int startLevel) { try { Bundle b = frameworkContext.installBundle(location, null); setStartLevel(b, startLevel); } catch (BundleException | RuntimeException ex) { System.err.println("Auto-properties install: " + location + " (" + ex + ((ex.getCause() != null) ? " - " + ex.getCause() : "") + ")"); if (ex.getCause() != null) { ex.printStackTrace(); } } }
private void installAllJavaBundles(final BundleContext context, final List<Bundle> installedBundles, @Nullable final String jrubyBundlePath) throws PluginConfigException, BundleException { final List<String> bundleJarPaths = osgiBundleFinder.getLatestBundles(); for (final String cur : bundleJarPaths) { // Don't install the jruby.jar bundle if (jrubyBundlePath != null && jrubyBundlePath.equals(cur)) { continue; } logger.info("Installing Java OSGI bundle from {}", cur); final Bundle bundle = context.installBundle("file:" + cur); installedBundles.add(bundle); } }
private void installAndStartBundle(BundleContext context, Resource resource) throws Exception { // install & start Bundle bundle = context.installBundle("[onTheFly-test-bundle]" + ClassUtils.getShortName(getClass()) + "[" + hashCode() + "]", resource.getInputStream()); String bundleString = OsgiStringUtils.nullSafeNameAndSymName(bundle); boolean debug = logger.isDebugEnabled(); if (debug) logger.debug("Test bundle [" + bundleString + "] succesfully installed"); bundle.start(); if (debug) logger.debug("Test bundle [" + bundleString + "] succesfully started"); }
public void addBundles(File bndrun) throws Exception { Run run = Run.createRun(getWorkspace(), bndrun); List<Bundle> bundles = new ArrayList<>(); for (Container c : run.getRunbundles()) { assert c.getError() == null; Bundle bundle = context.installBundle(c.getFile() .toURI() .toString()); bundles.add(bundle); } startAll(bundles); }
public void addBundles(File bndrun) throws Exception { Run run = Run.createRun(getWorkspace(), bndrun); List<Bundle> bundles = new ArrayList<>(); for (Container c : run.getRunbundles()) { assert c.getError() == null; Bundle bundle = context.installBundle(c.getFile() .toURI() .toString()); bundles.add(bundle); } startAll(bundles); }