Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multi-release processing support
Currently bnd is not a capable of processing multi-release jars, this adds support of multi-release processing by a new directive -release where one can select what release version should be processed by bnd. Fixes #5346 Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
- Loading branch information
Showing
5 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package aQute.bnd.build; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.JarFile; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import aQute.bnd.osgi.Jar; | ||
import aQute.bnd.osgi.Resource; | ||
|
||
public class JarTest { | ||
|
||
private static final String TEST_CLASS_PATH = "a/test/package/Test.class"; | ||
|
||
private static final String VERSIONED_TEST_CLASS_PATH = "META-INF/versions/9/" + TEST_CLASS_PATH; | ||
|
||
@TempDir | ||
File tempDir; | ||
|
||
@Test | ||
public void testMultiReleaseJar() throws Exception { | ||
File jarfile = new File(tempDir, "packed.jar"); | ||
try (Jar jar = new Jar("testme")) { | ||
jar.ensureManifest(); | ||
Resource java8Class = resource(); | ||
Resource java9Class = resource(); | ||
jar.putResource(TEST_CLASS_PATH, java8Class); | ||
jar.putResource(VERSIONED_TEST_CLASS_PATH, java9Class); | ||
// without a release, content must be returned as-is | ||
assertEquals(java8Class, jar.getResource(TEST_CLASS_PATH)); | ||
assertEquals(java9Class, jar.getResource(VERSIONED_TEST_CLASS_PATH)); | ||
// with a release set below 9 we should only see the default content | ||
jar.setRelease(0); | ||
assertEquals(java8Class, jar.getResource(TEST_CLASS_PATH)); | ||
assertNull(jar.getResource(VERSIONED_TEST_CLASS_PATH)); | ||
// with release 9 set, we now should see the java 9 content | ||
jar.setRelease(9); | ||
assertEquals(java9Class, jar.getResource(TEST_CLASS_PATH)); | ||
// if we write the jar out, all content should be present | ||
jar.writeFolder(tempDir); | ||
File defaultFile = new File(tempDir, TEST_CLASS_PATH); | ||
assertTrue(defaultFile.isFile(), defaultFile.getAbsolutePath() + " is missing"); | ||
File versionedFile = new File(tempDir, VERSIONED_TEST_CLASS_PATH); | ||
assertTrue(versionedFile.isFile(), versionedFile.getAbsolutePath() + " is missing"); | ||
jar.write(jarfile); | ||
} | ||
try (JarFile jar = new JarFile(jarfile)) { | ||
Set<String> collect = Collections.list(jar.entries()) | ||
.stream() | ||
.map(JarEntry::getName) | ||
.collect(Collectors.toSet()); | ||
assertTrue(collect.contains(TEST_CLASS_PATH)); | ||
assertTrue(collect.contains(VERSIONED_TEST_CLASS_PATH)); | ||
} | ||
} | ||
|
||
private Resource resource() { | ||
return new aQute.bnd.osgi.EmbeddedResource(new byte[0], System.currentTimeMillis()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
layout: default | ||
class: Analyzer | ||
title: -release NUMBER | ||
summary: Specify the java release for which the Analyzer should generate meta-data. | ||
--- | ||
The `-release` instruction is very similar to the `--release` option of javac and instructs the Analyser to process Multi-Release-JARs with the specified release as defined in [JEP 238: Multi-Release JAR Files](https://openjdk.org/jeps/238). | ||
|
||
If the `-release` is not specified or NUMBER is smaller than 0 then release processing is **disabled** no further processing is done | ||
|
||
If the `-release` is specified and NUMBER is smaller than or equal to 8 the **default content** is processed, that means for every jar entries in the META-INF/versions/* directories are effectively ignored by the processor. | ||
|
||
If the `-release` is specified and NUMBER is larger or equal than 9 the content is processed as with the rules from JEP 238 possibly hiding some of the default content. |