How to warp a bundle such that its BCP persists

Hello everyone,

I’ve been trying to wrap an existing OSGI-bundle B, adding content in the process (yes has to be in the existing bundle) and maintain the original Bundle-Classpath (BCP).

My approach currently is that I unroll bundle B like so:
-includeresource: @B*.jar

This results in a wrapped bundle that contains all the data we want to have it contain. Unfortunately, by doing so the original BCP is lost.

I tried setting the BCP manually via:
Bundle-ClassPath: .,${lsr;./target/classes/;*.jar}

This approach only works if the bundle B was already unrolled previously, or in other words:
The includeresouce instruction is executed after the BCP-Header field is evaluated.

I am sure that I am missing something here but I couldn’t find another way of getting the correct result.
Does anybody know a better approach? Or how I could tell bndtools to evaluate the BCP-Header after the includeresource instruction?

Thank you very much and have a great weekend!
Nuw

P.S. I also tried out if I could use the -includeresource instruction to include and add the contained jars of the original bundle directly, but the lib:=true flag doesn’t seem to work for files from within another depency.
Example:

-includeresource: \
	@B*.jar!/!*.jar,\
	@B*.jar!/*.jar;lib:=true

Hi @Nuw ,

in @B*.jar the @ refers to extractFromJar() which currently does not handle the lib:=true directive. And lib:=true basically seems to mean “append to the Bundle-Classpath”.

lib:=true seems only to be handled without the @ when you copy directly without extracting it, and then the Bundle-Classpath is appended.
Basically as in those examples:

Question:

Would something like

if (isTrue(extra.get(LIB_DIRECTIVE))) {
			setProperty(BUNDLE_CLASSPATH, append(getProperty(BUNDLE_CLASSPATH, "."), path));
		}

also make sense for the extract / unroll .jar case?
e.g.

@B*.jar!/*.jar;lib:=true

I am currently deep in another -includeresource PR and could have a look.

@pkriens

Hi chrisrueger!

As some food for thought: If you unroll a bundle that itself has a BCP, why not use that as the initial BCP when processing the bnd-instructions?

In that case there’s no need for the LIB_DIRECTIVE support for my use-case. But IMHO it still makes sense for others.

Thanks and have a great day!
Nuw