bnd icon indicating copy to clipboard operation
bnd copied to clipboard

Support a `resolution:=conditional` directive for a more flexible and automated way of handling of package-imports based on the classpath

Open laeubi opened this issue 8 months ago • 5 comments

Currently one can use for Import-Package a resolution:=dynamic so an import becomes an DynamicImport-Package, beside that one can add resolution:=optional to make it an optional import. And then there is also conditionalpackage to embed packages (and not import them at all).

What I'm sometimes missing when wrapping third party code (but it can be useful in other cases as well) is something I will call here resolution:=conditional (while maybe computed would also be suitable as a name) that can be used like this:

Import-Package: *;resolution:=conditional

and then behaves in the following way:

  1. Assume we have a package to be imported p
  2. If p is found on the classpath and the jar is an OSGi bundle then p should be imported as usual possibly with a version range
  3. If p is found on the classpath but the jar is not an OSGI bundle then p is considered an conditional package and embedded into the jar
  4. If p is not found on the classpath it is imported with resolution:=optional (e.g. might be some com.sun.* class from the jdk or whatever e.g. a prebuild jar is analyzed and some dependencies are not available at that time)

This would be especially useful for cases where one needs to wrap an existing jar but can't add metadata in the first place, or if metadata should be added but the authors of that jar do not care much about OSGi and are afraid of having to know/manage that stuff individually.

laeubi avatar Feb 13 '25 04:02 laeubi