2

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?

Community
  • 1
  • 1
MLE
  • 169
  • 1
  • 8

3 Answers3

2

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.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
Holly Cummins
  • 10,767
  • 3
  • 23
  • 25
1

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.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
0

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.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • 2
    An OSGi framework can run multiple versions of the same bundle, although an individual bundle will usually only be wired to one version of a bundle dependency. – Holly Cummins Apr 21 '12 at 14:51
  • True, this is more precise. Every dependent observes only one version, but different dependents can indeed observe different versions. – Marko Topolnik Apr 21 '12 at 16:05
  • Bundles export packages and packages are the entities that are wired. There can be any number of bundles installed with the same symbolic name and the same (since the last release) version or different version. – Peter Kriens Apr 23 '12 at 06:56
  • @PeterKriens They can be installed, but can one bundle see packages from multiple bundles of the same id? Doesn't that at least depend on the mechanism you use to wire bundles? You can depend on a bundle, or you can import a package. Seems that what you said applies only to the latter. – Marko Topolnik Apr 23 '12 at 08:47