Skip to content

Commit

Permalink
Add support for building MR jars
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
laeubi committed Aug 27, 2022
1 parent 9361381 commit 51a4947
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 204 deletions.
39 changes: 39 additions & 0 deletions biz.aQute.bndlib.tests/test/aQute/bnd/osgi/AnalyzerTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package aQute.bnd.osgi;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Optional;
import java.util.jar.Manifest;

import org.junit.jupiter.api.Test;

import aQute.lib.io.IO;

public class AnalyzerTest {

@Test
Expand All @@ -13,4 +20,36 @@ public void testdoNameSection() throws Exception {
}
}

@Test
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))");
}
}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 51a4947

Please sign in to comment.