8150163: JarFileSystem support for MRJARs should use the JDK specific Version API
Reviewed-by: alanb, iris, sherman
--- a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java Fri Feb 19 07:55:05 2016 +0000
+++ b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java Fri Feb 19 07:56:25 2016 +0000
@@ -36,6 +36,7 @@
import java.util.function.Function;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
+import jdk.Version;
/**
* Adds aliasing to ZipFileSystem to support multi-release jar files. An alias map
@@ -68,14 +69,14 @@
if (o instanceof String) {
String s = (String)o;
if (s.equals("runtime")) {
- version = sun.misc.Version.jdkMajorVersion(); // fixme waiting for jdk.util.Version
+ version = jdk.Version.current().major();
} else {
version = Integer.parseInt(s);
}
} else if (o instanceof Integer) {
version = (Integer)o;
- } else if (false /*o instanceof Version*/) { // fixme waiting for jdk.util.Version
-// version = ((Version)o).major();
+ } else if (o instanceof Version) {
+ version = ((Version)o).major();
} else {
throw new IllegalArgumentException("env parameter must be String, Integer, "
+ "or Version");
--- a/jdk/test/jdk/nio/zipfs/MultiReleaseJarTest.java Fri Feb 19 07:55:05 2016 +0000
+++ b/jdk/test/jdk/nio/zipfs/MultiReleaseJarTest.java Fri Feb 19 07:56:25 2016 +0000
@@ -38,16 +38,18 @@
import java.nio.file.*;
import java.util.HashMap;
import java.util.Map;
-
-import static sun.misc.Version.jdkMajorVersion;
+import jdk.Version;
import org.testng.Assert;
import org.testng.annotations.*;
public class MultiReleaseJarTest {
+ final private int MAJOR_VERSION= Version.current().major();
+
final private String userdir = System.getProperty("user.dir",".");
final private Map<String,String> stringEnv = new HashMap<>();
final private Map<String,Integer> integerEnv = new HashMap<>();
+ final private Map<String,Version> versionEnv = new HashMap<>();
final private String className = "version.Version";
final private MethodType mt = MethodType.methodType(int.class);
@@ -81,7 +83,7 @@
@DataProvider(name="strings")
public Object[][] createStrings() {
return new Object[][]{
- {"runtime", jdkMajorVersion()},
+ {"runtime", MAJOR_VERSION},
{"-20", 8},
{"0", 8},
{"8", 8},
@@ -105,6 +107,17 @@
};
}
+ @DataProvider(name="versions")
+ public Object[][] createVersions() {
+ return new Object[][] {
+ {Version.parse("8"), 8},
+ {Version.parse("9"), 9},
+ {Version.parse("10"), 10},
+ {Version.parse("11"), 10},
+ {Version.parse("100"), 10}
+ };
+ }
+
// Not the best test but all I can do since ZipFileSystem and JarFileSystem
// are not public, so I can't use (fs instanceof ...)
@Test
@@ -117,7 +130,7 @@
env.put("multi-release", "runtime");
// a configuration and jar file is multi-release
try (FileSystem fs = FileSystems.newFileSystem(mruri, env)) {
- Assert.assertTrue(readAndCompare(fs, jdkMajorVersion()));
+ Assert.assertTrue(readAndCompare(fs, MAJOR_VERSION));
}
// a configuration but jar file is unversioned
try (FileSystem fs = FileSystems.newFileSystem(uvuri, env)) {
@@ -143,6 +156,12 @@
runTest(integerEnv, expected);
}
+ @Test(dataProvider="versions")
+ public void testVersions(Version value, int expected) throws Throwable {
+ versionEnv.put("multi-release", value);
+ runTest(versionEnv, expected);
+ }
+
@Test
public void testShortJar() throws Throwable {
integerEnv.put("multi-release", Integer.valueOf(10));