forked from bndtools/bnd
-
Notifications
You must be signed in to change notification settings - Fork 0
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 bndtools#5346
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
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
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()); | ||
} | ||
|
||
} |