Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building multi-release jars (automatic!) #5359

Closed
wants to merge 2 commits into from

Conversation

laeubi
Copy link
Contributor

@laeubi laeubi commented Aug 25, 2022

This is based on:

so to see the actual changes from this PR simply select the last commit on the review tab.

an allows to specify
Multi-Release: true
in a BND file to instruct BND building an OSGi Multi-Release Bundle based on the detected versions.

@timothyjward this also includes fixing general processing of BND in cases where multi-release is off, and methods for Jar to put versioned resources / supplemental manifests. If you think it helps, both aspects could be split into separate PRs as well.

This will fix #5346

@laeubi laeubi changed the title Add support for building multi-release jars Add support for building multi-release jars (automatic!) Aug 25, 2022
@laeubi
Copy link
Contributor Author

laeubi commented Aug 25, 2022

I have adjusted the example here to reflect the changes, the
clickhouse-http-client-0.3.3-SNAPSHOT.jar.zip shows the result for such a bundle build by bnd with supplemental manifests for version 9 and 11.

This adds methods to the Jar class to read versioned content of a
multi-release jar for the following cases:

- get a resource or a map of resources for a given release version
- get a merged manifest according to the OSGi specification
- get module name/version for a given given release version
- list all contained release alternative versions

Beside this a unit-test is added to cover these new functions.

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
@timothyjward
Copy link
Contributor

I think the direction here is good. We probably need some more multi-release bundle generation tests before it can be merged though.
One feature that seems likely to have issues is the generation of java.* imports for multi release manifests at versions greater than 11.

@laeubi
Copy link
Contributor Author

laeubi commented Aug 26, 2022

We probably need some more multi-release bundle generation tests before it can be merged though.

Can you suggest a test-case that might be adapted for this purpose?

One feature that seems likely to have issues is the generation of java.* imports for multi release manifests at versions greater than 11.

According to my tests (see attached generated bundle) it simply "works", e.g. I see java.* imports for the java 11 variant.

This changes enable BND user to set

Multi-Release: true

in a BND file and then creates a bundle that conforms to the OSGi
Multi-release JAR specification

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
@laeubi
Copy link
Contributor Author

laeubi commented Aug 27, 2022

We probably need some more multi-release bundle generation tests before it can be merged though.

I have added now a test here:

public void multiRelease() throws Exception {
try (Analyzer a = new Analyzer(new Jar("test"))) {
a.setProperty("Multi-Release", "true");
assertThat(a.check()).isTrue();
Jar jar = a.getJar();
String fooPath = "test/Foo.class";
String barPath = "test/Bar.class";
jar.putResource(fooPath,
new FileResource(IO.getFile("testresources/mr/java8/Foo.class")));
jar.putResource(barPath,
new FileResource(IO.getFile("testresources/mr/java8/Bar.class")));
jar.putVersionedResource(fooPath, 9, new FileResource(IO.getFile("testresources/mr/java9/Foo.class")));
jar.putVersionedResource(barPath, 17, new FileResource(IO.getFile("testresources/mr/java17/Bar.class")));
jar.setManifest(a.calcManifest());
Manifest mainMf = jar.getManifest();
Optional<Manifest> java9Mf = jar.getManifest(9);
Optional<Manifest> java17Mf = jar.getManifest(17);
assertThat(mainMf.getMainAttributes()
.getValue(Constants.REQUIRE_CAPABILITY)).isNotNull()
.contains("(&(osgi.ee=JavaSE)(version=1.8))");
assertThat(java9Mf.get()
.getMainAttributes()
.getValue(Constants.REQUIRE_CAPABILITY)).isNotNull()
.contains("(&(osgi.ee=JavaSE)(version=9))");
assertThat(java17Mf.get()
.getMainAttributes()
.getValue(Constants.REQUIRE_CAPABILITY)).isNotNull()
.contains("(&(osgi.ee=JavaSE)(version=17))");
}
}

@pkriens
Copy link
Member

pkriens commented Feb 23, 2023

I will take over this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bnd] Support processing of Multi-Release-Jars
3 participants