Java Code Examples for org.osgi.framework.BundleContext#getBundle()
The following examples show how to use
org.osgi.framework.BundleContext#getBundle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckstylePlugin.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * {@inheritDoc} */ @Override public void start(BundleContext context) throws Exception { super.start(context); mAddonExtensionClassLoader = new ExtensionClassLoader(context.getBundle(), ADDON_PROVIDER_EXT_PT_ID); try { Logger checkstyleErrorLog = Logger.getLogger("com.puppycrawl.tools.checkstyle.ExceptionLog"); //$NON-NLS-1$ checkstyleErrorLog.addHandler(new EclipseLogHandler(this)); checkstyleErrorLog.setLevel(Level.ALL); } catch (Exception ioe) { CheckstyleLog.log(ioe); } }
Example 2
Source File: Activator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void start(BundleContext bc) throws Exception { this.bc = bc; isLog = bc.createFilter(LOG_FILTER); isDevice = bc.createFilter(DEVICE_FILTER); isDriver = bc.createFilter(DRIVER_FILTER); isSelector = bc.createFilter(SELECTOR_FILTER); isLocator = bc.createFilter(LOCATOR_FILTER); startService(LOG_FILTER); start(); bc.addFrameworkListener(this); final Bundle b = bc.getBundle(0); if (b.getState() == Bundle.ACTIVE) { activate(); } else { info("Passive start"); } }
Example 3
Source File: BundleUtilsTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testLoadSameBundleMultipleTimes() throws Exception { loadBundles(Arrays.asList(getBundle(), getAnotherBundle())); BundleContext context = JavaLanguageServerPlugin.getBundleContext(); String skippedBundleLocation = getBundleLocation(getBundle(), true); Bundle skippedBundle = context.getBundle(skippedBundleLocation); String bundleLocation = getBundleLocation(getAnotherBundle(), true); Bundle installedBundle = context.getBundle(bundleLocation); try { assertNotNull(installedBundle); assertNull(skippedBundle); assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE); installedBundle.loadClass("testbundle.Activator"); assertEquals(installedBundle.getState(), Bundle.ACTIVE); String extResult = getBundleExtensionResult(); assertEquals("EXT_TOSTRING", extResult); } finally { // Uninstall the bundle to clean up the testing bundle context. uninstallBundles(Arrays.asList(installedBundle, skippedBundle)); } }
Example 4
Source File: BundleUtilsTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testLoadWithoutLoadClass() throws Exception { loadBundles(Arrays.asList(getBundle())); String bundleLocation = getBundleLocation(getBundle(), true); BundleContext context = JavaLanguageServerPlugin.getBundleContext(); Bundle installedBundle = context.getBundle(bundleLocation); try { assertNotNull(installedBundle); assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE); String extResult = getBundleExtensionResult(); assertEquals("EXT_TOSTRING", extResult); } finally { // Uninstall the bundle to clean up the testing bundle context. installedBundle.uninstall(); } }
Example 5
Source File: Activator.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public void start(BundleContext context) throws Exception { //disable the JSR99 compiler that does not work in OSGi; //This will convince jasper to use the JDTCompiler that invokes ecj (see JSP-21 on the glassfish bug-tracker) System.setProperty("org.apache.jasper.compiler.disablejsr199", Boolean.TRUE.toString()); this.context = context; thisBundle = context.getBundle(); packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this); packageAdminTracker.open(); }
Example 6
Source File: BundleCollisionHook.java From vespa with Apache License 2.0 | 5 votes |
private void logHiddenBundles(BundleContext requestingContext, Set<Bundle> hiddenBundles) { if (hiddenBundles.isEmpty()) { log.fine(() -> "No bundles to hide from bundle " + requestingContext.getBundle()); } else { if (requestingContext.getBundle() instanceof Framework) { log.fine(() -> "Requesting bundle is the Framework, so hidden bundles will be visible: " + hiddenBundles); } else { log.fine(() -> "Hiding bundles from bundle '" + requestingContext.getBundle() + "': " + hiddenBundles); } } }
Example 7
Source File: BundleUtilsTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testLoadMultipleExtensionsRequiringSameBundleButDifferentUrl() throws Exception { Bundle extensionBundleA = null; Bundle extensionBundleB = null; Bundle dependencyA = null; Bundle dependencyB = null; try { String extensionBundleAPath = getBundle("testresources/extension-with-dependency-0.0.1", "jdt.ls.extension.with.dependency_0.0.1.jar"); String dependencyAPath = getBundle("testresources/extension-with-dependency-0.0.1", "dependency_0.0.1.201911081535.jar"); String extensionBundleBPath = getBundle("testresources/another-extension-with-dependency-0.0.1", "jdt.ls.another.extension.with.dependency_0.0.1.jar"); String dependencyBPath = getBundle("testresources/another-extension-with-dependency-0.0.1", "dependency_0.0.1.201911081535.jar"); BundleUtils.loadBundles(Arrays.asList(extensionBundleAPath, dependencyAPath, extensionBundleBPath, dependencyBPath)); String extensionBundleALocation = getBundleLocation(extensionBundleAPath, true); String dependencyALocation = getBundleLocation(dependencyAPath, true); String extensionBundleBLocation = getBundleLocation(extensionBundleBPath, true); String dependencyBLocation = getBundleLocation(dependencyBPath, true); BundleContext context = JavaLanguageServerPlugin.getBundleContext(); extensionBundleA = context.getBundle(extensionBundleALocation); dependencyA = context.getBundle(dependencyALocation); extensionBundleB = context.getBundle(extensionBundleBLocation); dependencyB = context.getBundle(dependencyBLocation); assertTrue(extensionBundleA.getState() == Bundle.STARTING || extensionBundleA.getState() == Bundle.ACTIVE); assertTrue(extensionBundleB.getState() == Bundle.STARTING || extensionBundleB.getState() == Bundle.ACTIVE); extensionBundleA.loadClass("jdt.ls.extension.with.dependency.Activator"); assertEquals(extensionBundleA.getState(), Bundle.ACTIVE); extensionBundleB.loadClass("jdt.ls.another.extension.with.dependency.Activator"); assertEquals(extensionBundleB.getState(), Bundle.ACTIVE); // Bundles with same version but different URL, only the later comes one will be loaded assertNull(dependencyA); assertTrue(dependencyB.getState() == Bundle.ACTIVE); } finally { // Uninstall the bundle to clean up the testing bundle context. uninstallBundles(Arrays.asList(extensionBundleA, extensionBundleB, dependencyA, dependencyB)); } }
Example 8
Source File: BundleUtilsTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testLoadSameBundleWithDifferentVersionMultipleTimes() throws Exception { Bundle oldDependencyBundle = null; Bundle newBundleA = null; Bundle newBundleB = null; try { String oldDependencyPath = getBundle("testresources/extension-with-dependency-0.0.1", "dependency_0.0.1.201911081535.jar"); BundleUtils.loadBundles(Arrays.asList(oldDependencyPath)); String oldDependencyLocation = getBundleLocation(oldDependencyPath, true); BundleContext context = JavaLanguageServerPlugin.getBundleContext(); oldDependencyBundle = context.getBundle(oldDependencyLocation); assertNotNull(oldDependencyBundle); assertTrue(oldDependencyBundle.getState() == Bundle.ACTIVE); // Now we load two different version of bundles // this may happen when different extensions which required the same bundle are getting loaded. String newDependencyAPath = getBundle("testresources", "dependency_0.0.2.201911081538.jar"); String newDependencyBPath = getBundle("testresources/another-extension-with-dependency-0.0.1", "dependency_0.0.1.201911081535.jar"); String newDependencyALocation = getBundleLocation(newDependencyAPath, true); String newDependencyBLocation = getBundleLocation(newDependencyBPath, true); BundleUtils.loadBundles(Arrays.asList(newDependencyAPath, newDependencyBPath)); newBundleA = context.getBundle(newDependencyALocation); newBundleB = context.getBundle(newDependencyBLocation); assertTrue(oldDependencyBundle.getState() == Bundle.UNINSTALLED); assertNull(newBundleA); assertNotNull(newBundleB); assertTrue(newBundleB.getState() == Bundle.ACTIVE); } finally { // Uninstall the bundle to clean up the testing bundle context. uninstallBundles(Arrays.asList(oldDependencyBundle, newBundleA, newBundleB)); } }
Example 9
Source File: PluginNamespace.java From gocd with Apache License 2.0 | 5 votes |
public PluginNamespace(BundleContext bundleContext, URL xsdResource) { if (bundleContext == null) { throw new IllegalArgumentException(String.format("context for xsd-resource %s is null", xsdResource)); } Bundle bundle = bundleContext.getBundle(); if (bundle == null) { throw new IllegalArgumentException(String.format("bundle for xsd-resource %s is null", xsdResource)); } GoPluginManifest manifest = new GoPluginManifest(bundle); this.prefix = manifest.getPluginNamespacePrefix(); this.uri = manifest.getPluginNamespaceUri(); this.xsdResource = xsdResource; }
Example 10
Source File: BundleUtilsTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testLoadAndUpdate() throws Exception { loadBundles(Arrays.asList(getBundle())); String bundleLocation = getBundleLocation(getBundle(), true); BundleContext context = JavaLanguageServerPlugin.getBundleContext(); Bundle installedBundle = context.getBundle(bundleLocation); try { assertNotNull(installedBundle); assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE); installedBundle.loadClass("testbundle.Activator"); assertEquals(installedBundle.getState(), Bundle.ACTIVE); String extResult = getBundleExtensionResult(); assertEquals("EXT_TOSTRING", extResult); loadBundles(Arrays.asList(getBundle("testresources", "testbundle-0.6.0-SNAPSHOT.jar"))); bundleLocation = getBundleLocation(getBundle("testresources", "testbundle-0.6.0-SNAPSHOT.jar"), true); installedBundle = context.getBundle(bundleLocation); assertNotNull(installedBundle); assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE); installedBundle.loadClass("testbundle.Activator"); assertEquals(installedBundle.getState(), Bundle.ACTIVE); extResult = getBundleExtensionResult(); assertEquals("EXT_TOSTRING_0.6.0", extResult); } finally { // Uninstall the bundle to clean up the testing bundle context. installedBundle.uninstall(); } }
Example 11
Source File: DefaultGoPluginActivator.java From gocd with Apache License 2.0 | 5 votes |
@Override public void start(BundleContext bundleContext) throws Exception { Bundle bundle = bundleContext.getBundle(); pluginRegistryService = bundleContext.getService(bundleContext.getServiceReference(PluginRegistryService.class)); bundleSymbolicName = bundle.getSymbolicName(); pluginId = pluginRegistryService.getPluginIDOfFirstPluginInBundle(bundleSymbolicName); LoggingService loggingService = bundleContext.getService(bundleContext.getServiceReference(LoggingService.class)); Logger.initialize(loggingService); getImplementersAndRegister(bundleContext, bundle, pluginRegistryService.extensionClassesInBundle(bundleSymbolicName)); reportErrorsToHealthService(); }
Example 12
Source File: WorkspaceExecuteCommandHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testRegistryEventListener() throws Exception { loadBundles(Arrays.asList(getBundle("testresources", "jdt.ls.extension-0.0.1.jar"))); String bundleLocation = getBundleLocation(getBundle("testresources", "jdt.ls.extension-0.0.1.jar"), true); BundleContext context = JavaLanguageServerPlugin.getBundleContext(); Bundle installedBundle = context.getBundle(bundleLocation); try { assertNotNull(installedBundle); assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE); installedBundle.loadClass("jdt.ls.extension.Activator"); assertEquals(installedBundle.getState(), Bundle.ACTIVE); Set<String> extensionCommands = WorkspaceExecuteCommandHandler.getInstance().getAllCommands(); assertTrue(extensionCommands.contains("jdt.ls.extension.command1")); assertTrue(extensionCommands.contains("jdt.ls.extension.command2")); loadBundles(Arrays.asList(getBundle("testresources", "jdt.ls.extension-0.0.2.jar"))); bundleLocation = getBundleLocation(getBundle("testresources", "jdt.ls.extension-0.0.2.jar"), true); installedBundle = context.getBundle(bundleLocation); assertNotNull(installedBundle); assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE); installedBundle.loadClass("jdt.ls.extension.Activator"); assertEquals(installedBundle.getState(), Bundle.ACTIVE); extensionCommands = WorkspaceExecuteCommandHandler.getInstance().getAllCommands(); assertTrue(extensionCommands.contains("jdt.ls.extension.command2")); assertTrue(extensionCommands.contains("jdt.ls.extension.command3")); assertFalse(extensionCommands.contains("jdt.ls.extension.command1")); } finally { // Uninstall the bundle to clean up the testing bundle context. installedBundle.uninstall(); } }
Example 13
Source File: XMLMaterialsDatabase.java From ice with Eclipse Public License 1.0 | 5 votes |
/** * The OSGi-based start operation that performs framework-specific start * tasks to determine the location of the database files. * * @param context * The component context */ @Override public void start(BundleContext context) { try { if (context != null) { Bundle bundle = context.getBundle(); URL userDBURL = bundle.getEntry("data/userMatDB.xml"); URL defaultDBURL = bundle.getEntry("data/defaultMatDB.xml"); // Set the file references by converting the bundle:// URLs to // file:// URLs. userDatabase = new File( FileLocator.toFileURL(userDBURL).getPath()); defaultDatabase = new File( FileLocator.toFileURL(defaultDBURL).getPath()); // Once the files are set, just call the other start operation start(); // Register the service registration = context.registerService(IMaterialsDatabase.class, this, null); } } catch (IOException e) { // Complain logger.error("Unable to start the XMLPersistence service!", e); } return; }
Example 14
Source File: PaperUIApp.java From smarthome with Eclipse Public License 2.0 | 5 votes |
protected void activate(BundleContext bundleContext) { try { Bundle paperuiBundle = bundleContext.getBundle(); httpService.registerResources(WEBAPP_ALIAS, "web", httpContextFactoryService.createDefaultHttpContext(paperuiBundle)); logger.info("Started Paper UI at " + WEBAPP_ALIAS); } catch (NamespaceException e) { logger.error("Error during servlet startup", e); } }
Example 15
Source File: EventDistributorHandler.java From camunda-bpm-platform-osgi with Apache License 2.0 | 4 votes |
public EventDistributorHandler(BundleContext context) { this.systemBundle = context.getBundle(0); }
Example 16
Source File: BundleUtilsTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Test public void testUpdateExtensionsDependingOnTheSameBundle() throws Exception { Bundle oldBundle = null; Bundle oldDependency = null; Bundle anotherBundle = null; Bundle newBundle = null; Bundle newDependency = null; try { // First, we load a bundle depends on dependency bundle String oldBundlePath = getBundle("testresources/extension-with-dependency-0.0.1", "jdt.ls.extension.with.dependency_0.0.1.jar"); String oldDependencyPath = getBundle("testresources/extension-with-dependency-0.0.1", "dependency_0.0.1.201911081535.jar"); String anotherBundlePath = getBundle("testresources/another-extension-with-dependency-0.0.1", "jdt.ls.another.extension.with.dependency_0.0.1.jar"); BundleUtils.loadBundles(Arrays.asList(oldBundlePath, oldDependencyPath, anotherBundlePath)); String oldBundleLocation = getBundleLocation(oldBundlePath, true); String oldDependencyLocation = getBundleLocation(oldDependencyPath, true); String anotherBundleLocation = getBundleLocation(anotherBundlePath, true); BundleContext context = JavaLanguageServerPlugin.getBundleContext(); oldBundle = context.getBundle(oldBundleLocation); oldDependency = context.getBundle(oldDependencyLocation); anotherBundle = context.getBundle(anotherBundleLocation); assertNotNull(oldBundle); assertTrue(oldBundle.getState() == Bundle.STARTING || oldBundle.getState() == Bundle.ACTIVE); assertTrue(oldDependency.getState() == Bundle.ACTIVE); assertTrue(anotherBundle.getState() == Bundle.STARTING || oldBundle.getState() == Bundle.ACTIVE); oldBundle.loadClass("jdt.ls.extension.with.dependency.Activator"); assertEquals(oldBundle.getState(), Bundle.ACTIVE); anotherBundle.loadClass("jdt.ls.another.extension.with.dependency.Activator"); assertEquals(anotherBundle.getState(), Bundle.ACTIVE); // Now we load bundles from another location, this may happen when the LS extensions get updated. String newBundlePath = getBundle("testresources/extension-with-dependency-0.0.2", "jdt.ls.extension.with.dependency_0.0.2.jar"); String newDependencyPath = getBundle("testresources/extension-with-dependency-0.0.2", "dependency_0.0.2.201911081538.jar"); BundleUtils.loadBundles(Arrays.asList(newBundlePath, newDependencyPath)); String newBundleLocation = getBundleLocation(newBundlePath, true); String newDependencyLocation = getBundleLocation(newDependencyPath, true); newBundle = context.getBundle(newBundleLocation); newDependency = context.getBundle(newDependencyLocation); assertTrue(oldBundle.getState() == Bundle.UNINSTALLED); assertTrue(oldDependency.getState() == Bundle.UNINSTALLED); assertTrue(newBundle.getState() == Bundle.STARTING || oldBundle.getState() == Bundle.ACTIVE); assertTrue(newDependency.getState() == Bundle.ACTIVE); newBundle.loadClass("jdt.ls.extension.with.dependency.Activator"); assertEquals(newBundle.getState(), Bundle.ACTIVE); } finally { // Uninstall the bundle to clean up the testing bundle context. uninstallBundles(Arrays.asList(oldBundle, oldDependency, anotherBundle, newBundle, newDependency)); } }
Example 17
Source File: NexusBundleTracker.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
public NexusBundleTracker(final BundleContext context, final MutableBeanLocator locator) { super(context, Bundle.STARTING | Bundle.ACTIVE, locator); systemBundle = context.getBundle(0); }
Example 18
Source File: CheckstyleUIPlugin.java From eclipse-cs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void start(BundleContext context) throws Exception { super.start(context); mQuickfixExtensionClassLoader = new ExtensionClassLoader(context.getBundle(), QUICKFIX_PROVIDER_EXT_PT_ID); // add listeners for the Check-On-Open support final IWorkbench workbench = getWorkbench(); workbench.getDisplay().asyncExec(new Runnable() { @Override public void run() { IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { if (window != null) { // collect open editors and have then run against Checkstyle if // appropriate Collection<IWorkbenchPartReference> parts = new HashSet<>(); // add already opened files to the filter // bugfix for 2923044 IWorkbenchPage[] pages = window.getPages(); for (IWorkbenchPage page : pages) { IEditorReference[] editorRefs = page.getEditorReferences(); for (IEditorReference ref : editorRefs) { parts.add(ref); } } mPartListener.partsOpened(parts); // remove listener first for safety, we don't want // register the same listener twice accidently window.getPartService().removePartListener(mPartListener); window.getPartService().addPartListener(mPartListener); } } workbench.addWindowListener(mWindowListener); } }); }
Example 19
Source File: XMLParserActivator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Called when this bundle is started so the Framework can perform the * bundle-specific activities necessary to start this bundle. This method * can be used to register services or to allocate any resources that this * bundle needs. * * <p> * This method must complete and return to its caller in a timely manner. * * <p> * This method attempts to register a SAX and DOM parser with the * Framework's service registry. * * @param context The execution context of the bundle being started. * @throws java.lang.Exception If this method throws an exception, this * bundle is marked as stopped and the Framework will remove this * bundle's listeners, unregister all services registered by this * bundle, and release all services used by this bundle. */ public void start(BundleContext context) throws Exception { this.context = context; Bundle parserBundle = context.getBundle(); // check for sax parsers registerSAXParsers(getParserFactoryClassNames(parserBundle.getResource(SAXCLASSFILE))); // check for dom parsers registerDOMParsers(getParserFactoryClassNames(parserBundle.getResource(DOMCLASSFILE))); }
Example 20
Source File: XMLParserActivator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Called when this bundle is started so the Framework can perform the * bundle-specific activities necessary to start this bundle. This method * can be used to register services or to allocate any resources that this * bundle needs. * * <p> * This method must complete and return to its caller in a timely manner. * * <p> * This method attempts to register a SAX and DOM parser with the * Framework's service registry. * * @param context The execution context of the bundle being started. * @throws java.lang.Exception If this method throws an exception, this * bundle is marked as stopped and the Framework will remove this * bundle's listeners, unregister all services registered by this * bundle, and release all services used by this bundle. */ public void start(BundleContext context) throws Exception { this.context = context; Bundle parserBundle = context.getBundle(); // check for sax parsers registerSAXParsers(getParserFactoryClassNames(parserBundle .getResource(SAXCLASSFILE))); // check for dom parsers registerDOMParsers(getParserFactoryClassNames(parserBundle .getResource(DOMCLASSFILE))); }