bnd
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
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:
- Assume we have a package to be imported
p - If
pis found on the classpath and the jar is an OSGi bundle thenpshould be imported as usual possibly with a version range - If
pis found on the classpath but the jar is not an OSGI bundle thenpis considered an conditional package and embedded into the jar - If
pis not found on the classpath it is imported withresolution:=optional(e.g. might be somecom.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.