37 * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarProperties
38 * @run testng/othervm -Djdk.util.jar.version=10 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarProperties
39 * @run testng/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
40 * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
41 * @run testng/othervm -Djdk.util.jar.version=10 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
42 * @run testng/othervm -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarProperties
43 * @run testng/othervm -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
44 */
45
46 import java.io.File;
47 import java.io.IOException;
48 import java.io.InputStream;
49 import java.lang.invoke.MethodHandle;
50 import java.lang.invoke.MethodHandles;
51 import java.lang.invoke.MethodType;
52 import java.net.URL;
53 import java.net.URLClassLoader;
54 import java.nio.file.Files;
55 import java.util.jar.JarEntry;
56 import java.util.jar.JarFile;
57
58 import static sun.misc.Version.jdkMajorVersion; // fixme JEP 223 Version
59
60 import org.testng.Assert;
61 import org.testng.annotations.AfterClass;
62 import org.testng.annotations.BeforeClass;
63 import org.testng.annotations.Test;
64
65 public class MultiReleaseJarProperties {
66 final static int ROOTVERSION = 8; // magic number from knowledge of internals
67 final static String userdir = System.getProperty("user.dir", ".");
68 final static File multirelease = new File(userdir, "multi-release.jar");
69 protected int rtVersion;
70 boolean force;
71 protected ClassLoader cldr;
72 protected Class<?> rootClass;
73
74 @BeforeClass
75 public void initialize() throws Exception {
76 CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars();
77 creator.compileEntries();
78 creator.buildMultiReleaseJar();
79
80 rtVersion = Integer.getInteger("jdk.util.jar.version", jdkMajorVersion());
81 String mrprop = System.getProperty("jdk.util.jar.enableMultiRelease", "");
82 if (mrprop.equals("false")) {
83 rtVersion = ROOTVERSION;
84 } else if (rtVersion < ROOTVERSION) {
85 rtVersion = ROOTVERSION;
86 } else if (rtVersion > jdkMajorVersion()) {
87 rtVersion = jdkMajorVersion();
88 }
89 force = mrprop.equals("force");
90
91 initializeClassLoader();
92 }
93
94 protected void initializeClassLoader() throws Exception {
95 URL[] urls = new URL[]{multirelease.toURI().toURL()};
96 cldr = new URLClassLoader(urls);
97 // load any class, Main is convenient and in the root entries
98 rootClass = cldr.loadClass("version.Main");
99 }
100
101 @AfterClass
102 public void close() throws IOException {
103 ((URLClassLoader)cldr).close();
104 Files.delete(multirelease.toPath());
105 }
106
107 /*
|
37 * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarProperties
38 * @run testng/othervm -Djdk.util.jar.version=10 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarProperties
39 * @run testng/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
40 * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
41 * @run testng/othervm -Djdk.util.jar.version=10 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
42 * @run testng/othervm -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarProperties
43 * @run testng/othervm -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarProperties
44 */
45
46 import java.io.File;
47 import java.io.IOException;
48 import java.io.InputStream;
49 import java.lang.invoke.MethodHandle;
50 import java.lang.invoke.MethodHandles;
51 import java.lang.invoke.MethodType;
52 import java.net.URL;
53 import java.net.URLClassLoader;
54 import java.nio.file.Files;
55 import java.util.jar.JarEntry;
56 import java.util.jar.JarFile;
57 import jdk.Version;
58
59 import org.testng.Assert;
60 import org.testng.annotations.AfterClass;
61 import org.testng.annotations.BeforeClass;
62 import org.testng.annotations.Test;
63
64 public class MultiReleaseJarProperties {
65
66 static final int MAJOR_VERSION = Version.current().major();
67
68 final static int ROOTVERSION = 8; // magic number from knowledge of internals
69 final static String userdir = System.getProperty("user.dir", ".");
70 final static File multirelease = new File(userdir, "multi-release.jar");
71 protected int rtVersion;
72 boolean force;
73 protected ClassLoader cldr;
74 protected Class<?> rootClass;
75
76 @BeforeClass
77 public void initialize() throws Exception {
78 CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars();
79 creator.compileEntries();
80 creator.buildMultiReleaseJar();
81
82 rtVersion = Integer.getInteger("jdk.util.jar.version", MAJOR_VERSION);
83 String mrprop = System.getProperty("jdk.util.jar.enableMultiRelease", "");
84 if (mrprop.equals("false")) {
85 rtVersion = ROOTVERSION;
86 } else if (rtVersion < ROOTVERSION) {
87 rtVersion = ROOTVERSION;
88 } else if (rtVersion > MAJOR_VERSION) {
89 rtVersion = MAJOR_VERSION;
90 }
91 force = mrprop.equals("force");
92
93 initializeClassLoader();
94 }
95
96 protected void initializeClassLoader() throws Exception {
97 URL[] urls = new URL[]{multirelease.toURI().toURL()};
98 cldr = new URLClassLoader(urls);
99 // load any class, Main is convenient and in the root entries
100 rootClass = cldr.loadClass("version.Main");
101 }
102
103 @AfterClass
104 public void close() throws IOException {
105 ((URLClassLoader)cldr).close();
106 Files.delete(multirelease.toPath());
107 }
108
109 /*
|