Community
Participate
Working Groups
I was trying to embed Equinox into a larger Java application, and ideally wanted to expose the functionality to start/stop and install bundles into the Java app. Although the EclipseStarter holds a reference to the OSGi, and the startup() method has a reference to the BundleContext, it's not possible to obtain if just invoking main() to bring the framework up.
Created attachment 58301 [details] Provides EclipseStarter.getSystemBundleContext() This adds EclipseStarter.getSystemBundleContext() to allow access to this from other applications.
We have discussed this before. In the past we have been reluctant to add a public static method to get the system bundle context because of the security issues. I'm not sure this is such a big security issue any more now that OSGi R4.1 is adding the Bundle.getBundleContext method with a permission check. If we decide to do this then we should probably use the proper calls to cause a permission check if the security manager is enabled ... context.getBundle().getBundleContext()
Note that you can already get it via the return result from the startup() call, and also if you supply a subclass of Console then the OSGi gets passed in as a constructor arg anyway which can be overridden (or cached). It's just it would be nice if the class provided a mechanism for clients who want to interact with the system to do so, without having to resort to workaround/hacks like this. Not having the method doesn't really change much with what can be done, but it does make it easier for the use case of embedding Equinox in an existing Java system. And note also that the Servlet stuff also goes around great hacks to provide public access to the OSGi context too. But yeah, having context.getBundle().getBundleContext() would also work :-) Alex.
Created attachment 58389 [details] Patch to provide context.getBundle().getBundleContext() as requested Attempt II ... the first time it failed (so if there's multiple attachments, that explains why)
Consider for M6. Need Jeff's approval for new API.
+1
Note the copyright statement should be updated if Alex's contribution is being used.
I'm having a hard time getting Alex's patch to apply. Eclipse keeps saying the patch file does not contain a valid patch. I was just going to do it manually. But I would like to add Alex to the copyright. Alex, do you want me to add you as a contributor? If so what text would you like me to use for you?
Fix released to HEAD. Alex I added your name to the copyright. Let me know if you want something else besides your name in the copyright.
Thanks, Tom. My name's fine in the copyright. Alex.