-
-
Notifications
You must be signed in to change notification settings - Fork 300
more lenient osgi.ee=JavaSE for unknown JDKs #6859
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,16 +6,20 @@ | |||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||
| import static org.junit.jupiter.api.Assertions.fail; | ||||||
|
|
||||||
| import java.io.ByteArrayInputStream; | ||||||
| import java.io.File; | ||||||
| import java.io.FileInputStream; | ||||||
| import java.io.Serializable; | ||||||
| import java.lang.annotation.ElementType; | ||||||
| import java.lang.annotation.Target; | ||||||
| import java.nio.file.Files; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.EnumSet; | ||||||
| import java.util.List; | ||||||
| import java.util.Set; | ||||||
| import java.util.concurrent.atomic.AtomicReference; | ||||||
| import java.util.jar.Attributes; | ||||||
| import java.util.jar.Manifest; | ||||||
|
|
||||||
| import org.junit.jupiter.api.Test; | ||||||
| import org.junit.jupiter.api.condition.EnabledForJreRange; | ||||||
|
|
@@ -30,16 +34,21 @@ | |||||
| import aQute.bnd.osgi.ClassDataCollector; | ||||||
| import aQute.bnd.osgi.Clazz; | ||||||
| import aQute.bnd.osgi.Clazz.FieldDef; | ||||||
| import aQute.bnd.osgi.Clazz.JAVA; | ||||||
| import aQute.bnd.osgi.Clazz.MethodDef; | ||||||
| import aQute.bnd.osgi.Clazz.QUERY; | ||||||
| import aQute.bnd.osgi.Constants; | ||||||
| import aQute.bnd.osgi.Descriptors; | ||||||
| import aQute.bnd.osgi.Descriptors.PackageRef; | ||||||
| import aQute.bnd.osgi.EmbeddedResource; | ||||||
| import aQute.bnd.osgi.FileResource; | ||||||
| import aQute.bnd.osgi.Instruction; | ||||||
| import aQute.bnd.osgi.Jar; | ||||||
| import aQute.bnd.osgi.Macro; | ||||||
| import aQute.bnd.osgi.Resource; | ||||||
| import aQute.bnd.xmlattribute.XMLAttributeFinder; | ||||||
| import aQute.lib.io.IO; | ||||||
| import aQute.lib.manifest.ManifestUtil; | ||||||
|
|
||||||
| public class ClazzTest { | ||||||
|
|
||||||
|
|
@@ -1111,4 +1120,77 @@ public void kotlin_LambdaClass() throws Exception { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * This test creates a fake java .class file with an imaginary large major | ||||||
| * version (10000) to test how our Analyzer handles class files of a yet | ||||||
| * unknown future JDK. | ||||||
| */ | ||||||
| @Test | ||||||
| void testUnknownJDKClass() throws Exception { | ||||||
|
|
||||||
|
|
||||||
| File file = IO.getFile("bin_test/test/ClazzTest$Inner.class"); | ||||||
| byte[] fakeClassBytes = Files.readAllBytes(file.toPath()); | ||||||
|
|
||||||
| int newMajor = 10_000; | ||||||
| int expected = 9955; // newMajor - 45; | ||||||
| // Patch major version (u2 big-endian) | ||||||
| // https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html | ||||||
| fakeClassBytes[6] = (byte) ((newMajor >> 8) & 0xFF); | ||||||
| fakeClassBytes[7] = (byte) (newMajor & 0xFF); | ||||||
|
|
||||||
| try (Jar jar = new Jar("future"); | ||||||
| Analyzer a = new Analyzer(jar)) { | ||||||
|
|
||||||
| Resource r = new EmbeddedResource(fakeClassBytes, fakeClassBytes.length); | ||||||
|
|
||||||
| Clazz c = new Clazz(a, "", r); | ||||||
| c.parseClassFile(new ByteArrayInputStream(fakeClassBytes), new ClassDataCollector() {}); | ||||||
| a.getClassspace() | ||||||
| .put(c.getClassName(), c); | ||||||
|
|
||||||
| assertThat(c.getMajorVersion()).isEqualTo(newMajor); | ||||||
|
|
||||||
| Manifest calcManifest = a.calcManifest(); | ||||||
| ManifestUtil.write(calcManifest, System.out); | ||||||
| Attributes mainAttributes = calcManifest.getMainAttributes(); | ||||||
| assertThat(mainAttributes.getValue(Constants.REQUIRE_CAPABILITY)) | ||||||
| .contains("(&(osgi.ee=JavaSE)(version=" + expected + "))"); | ||||||
| assertThat(a.getEEs()).containsExactly(JAVA.UNKNOWN); | ||||||
|
|
||||||
|
|
||||||
chrisrueger marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
| catch (Exception e) { | ||||||
| e.printStackTrace(); | ||||||
| throw e; | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void testBuildEEFilter_lenientKnown() { | ||||||
| // lenient = true but version within known range | ||||||
| String result = Clazz.JAVA.buildEEFilterLenient(55); // within range | ||||||
| assertEquals("(&(osgi.ee=JavaSE)(version=11))", result); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
chrisrueger marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| @Test | ||||||
| void testBuildEEFilter_lenientTooLow() { | ||||||
| // version < 0 -> UNKNOWN | ||||||
| String result = Clazz.JAVA.buildEEFilterLenient(40); | ||||||
| assertEquals("(&(osgi.ee=JavaSE)(version=UNKNOWN))", result); | ||||||
|
||||||
| assertEquals("(&(osgi.ee=JavaSE)(version=UNKNOWN))", result); | |
| assertEquals("(osgi.ee=UNKNOWN)", result); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -199,7 +199,7 @@ public Map<String, Set<String>> getProfiles() throws IOException { | |||||
| this.major = ordinal() + 45; | ||||||
| String version = Integer.toString(ordinal() + 1); | ||||||
| this.ee = "JavaSE-" + version; | ||||||
| this.filter = "(&(osgi.ee=JavaSE)(version=" + version + "))"; | ||||||
| this.filter = eeFilter(version); | ||||||
| } | ||||||
|
|
||||||
| JAVA(String ee, String filter) { | ||||||
|
|
@@ -249,6 +249,28 @@ public String getEE() { | |||||
| return ee; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Returns an eeFilter String also supporting yet unknown JDKs (lenient) | ||||||
| */ | ||||||
| public static String buildEEFilterLenient(int major) { | ||||||
|
|
||||||
| // lenient: We try to return a useful filter | ||||||
| // even for yet unknown JDKs | ||||||
| int version = major - 45; | ||||||
| if ((version < 0)) { | ||||||
chrisrueger marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| return eeFilter("UNKNOWN"); | ||||||
|
||||||
| return eeFilter("UNKNOWN"); | |
| return "(osgi.ee=UNKNOWN)"; |
Uh oh!
There was an error while loading. Please reload this page.