Reputation: 169
The question asked here shows how a file from a bundle can be referenced via a URL such as platform:/plugin/de.vogella.rcp.plugin.filereader/files/test.txt
.
I would like to have two versions of the same bundle running simultaneously and the file I am retrieving will be different across versions. Is it possible to reference a bundle with the above URL scheme using version information as well so I can get the correct version of the file?
If this is not possible, can a specific version of a bundle be retrieved by another means?
Upvotes: 2
Views: 234
Reputation: 11492
You have a few options. Appending the version to the plugin name, separated by an underscore, should work, although I can't try it out right now to confirm that form works with the platform URL handler. For example: platform://my.bundle_3.1/some/file.txt
.
Failing that, you can use the OSGi APIs directly. If you have a BundleContext
, you can use it to look up the exact bundle you want, and then call bundle.getResource()
to get the resource you want.
Upvotes: 2
Reputation: 15372
Look at the BundleTracker, this makes it trivial to track bundles regardless of version. In general it is better to not look at the name or version of a bundle but react to resources they contain. That is, search for the OSGi extender pattern.
Upvotes: 1
Reputation: 200168
It is not possible to run two versions of the same bundle simultaneously. There is a process at OSGi startup called bundle resolution that will choose a single version of a bundle from all those available, so as to best satisfy all its dependents. If you really need two versions, you will need to fake it some way by pushing the version number into the bundle id, at which point it will be clear how to distinguish them.
Upvotes: 0