--- old/test/ProblemList.txt 2017-05-24 10:53:06.000000000 +0800 +++ new/test/ProblemList.txt 2017-05-24 10:53:06.000000000 +0800 @@ -258,8 +258,6 @@ tools/jimage/JImageListTest.java 8170120 generic-all tools/jimage/JImageVerifyTest.java 8170120 generic-all -tools/jar/multiRelease/RuntimeTest.java 8173905 generic-all - tools/schemagen/MultiReleaseJarTest.java 8174692 generic-all tools/wsgen/MultiReleaseJarTest.java 8174692 generic-all --- old/test/tools/jar/multiRelease/RuntimeTest.java 2017-05-24 10:53:07.000000000 +0800 +++ new/test/tools/jar/multiRelease/RuntimeTest.java 2017-05-24 10:53:06.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,12 +25,7 @@ * @test * @summary Test Multi-Release jar usage in runtime * @library /test/lib - * @library /lib/testlibrary * @modules jdk.compiler - * @build jdk.test.lib.JDKToolFinder jdk.test.lib.JDKToolLauncher - * jdk.test.lib.process.OutputAnalyzer - * jdk.test.lib.process.ProcessTools - * CompilerUtils RuntimeTest * @run testng RuntimeTest */ @@ -51,7 +46,10 @@ import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import java.util.stream.Stream; import org.testng.annotations.BeforeClass; @@ -60,37 +58,60 @@ import jdk.test.lib.JDKToolFinder; import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; public class RuntimeTest { public static final int SUCCESS = 0; - private final String src = System.getProperty("test.src", "."); - private final String usr = System.getProperty("user.dir", "."); + private static final String src = System.getProperty("test.src", "."); + private static final String usr = System.getProperty("user.dir", "."); + + private static final Path srcFileRoot = Paths.get(src, "data", "runtimetest"); + private static final Path genFileRoot = Paths.get(usr, "data", "runtimetest"); + + private static final int OLD_RELEASE = 8; + private static final int CURRENT_RELEASE = Runtime.version().major(); + private static final int FUTURE_RELEASE = CURRENT_RELEASE + 1; + private static final String MRJAR_BOTH_RELEASES = "MV_BOTH.jar"; + private static final String MRJAR_CURRENT_RELEASE = "MV_ONLY_" + CURRENT_RELEASE + ".jar"; + private static final String NON_MRJAR_OLD_RELEASE = "NON_MV.jar"; + + private static final int[] versions = {OLD_RELEASE, CURRENT_RELEASE, FUTURE_RELEASE}; + private static final Map templateSourceMap = new HashMap<>() { + { + put("helper.template", "Helper.java"); + put("main.template", "Main.java"); + put("resource.template", "versionResource"); + } + }; @DataProvider(name = "jarFiles") Object[][] jarFiles() { - return new Object[][] { { "MV_BOTH.jar", 9, 9, 9 }, - { "MV_ONLY_9.jar", 9, 9, 9 }, - { "NON_MV.jar", 8, 8, 8 } }; + return new Object[][]{ + {MRJAR_BOTH_RELEASES, CURRENT_RELEASE, CURRENT_RELEASE, CURRENT_RELEASE}, + {MRJAR_CURRENT_RELEASE, CURRENT_RELEASE, CURRENT_RELEASE, CURRENT_RELEASE}, + {NON_MRJAR_OLD_RELEASE, OLD_RELEASE, OLD_RELEASE, OLD_RELEASE} + }; } @BeforeClass protected void setUpTest() throws Throwable { + createJarSourceFiles(); compile(); Path classes = Paths.get("classes"); - jar("cfm", "MV_BOTH.jar", "manifest.txt", - "-C", classes.resolve("base").toString(), ".", - "--release", "9", "-C", classes.resolve("v9").toString(), ".", - "--release", "10", "-C", classes.resolve("v10").toString(), ".") + jar("cfm", MRJAR_BOTH_RELEASES, "manifest.txt", + "-C", classes.resolve("v" + OLD_RELEASE).toString(), ".", + "--release", "" + CURRENT_RELEASE, "-C", classes.resolve("v" + CURRENT_RELEASE).toString(), ".", + "--release", "" + FUTURE_RELEASE, "-C", classes.resolve("v" + FUTURE_RELEASE).toString(), ".") .shouldHaveExitValue(0); - jar("cfm", "MV_ONLY_9.jar", "manifest.txt", - "-C", classes.resolve("base").toString(), ".", - "--release", "9", "-C", classes.resolve("v9").toString(), ".") + jar("cfm", MRJAR_CURRENT_RELEASE, "manifest.txt", + "-C", classes.resolve("v" + OLD_RELEASE).toString(), ".", + "--release", "" + CURRENT_RELEASE, "-C", classes.resolve("v" + CURRENT_RELEASE).toString(), ".") .shouldHaveExitValue(0); - jar("cfm", "NON_MV.jar", "manifest.txt", - "-C", classes.resolve("base").toString(), ".") + jar("cfm", NON_MRJAR_OLD_RELEASE, "manifest.txt", + "-C", classes.resolve("v" + OLD_RELEASE).toString(), ".") .shouldHaveExitValue(0); } @@ -203,12 +224,32 @@ return ProcessTools.executeCommand(launcher.getCommand()); } + private static String platformPath(String p) { + return p.replace("/", File.separator); + } + + private static void createJarSourceFiles() throws IOException { + for (int ver : versions) { + for (Map.Entry fileMap : templateSourceMap.entrySet()) { + String genFileName = fileMap.getValue(); + Path template = srcFileRoot.resolve(fileMap.getKey()); + Path out = genFileName.endsWith("java") + ? genFileRoot.resolve(platformPath("v" + ver + "/testpackage/" + genFileName)) + : genFileRoot.resolve(platformPath("v" + ver + "/" + genFileName)); + Files.createDirectories(out.getParent()); + List lines = Files.lines(template) + .map(s -> s.replaceAll("\\$version", String.valueOf(ver))) + .collect(Collectors.toList()); + Files.write(out, lines); + } + } + } + private void compile() throws Throwable { - String[] vers = { "base", "v9", "v10" }; - for (String ver : vers) { - Path classes = Paths.get(usr, "classes", ver); + for (int ver : versions) { + Path classes = Paths.get(usr, "classes", "v" + ver); Files.createDirectories(classes); - Path source = Paths.get(src, "data", "runtimetest", ver); + Path source = genFileRoot.resolve("v" + ver); assertTrue(CompilerUtils.compile(source, classes)); Files.copy(source.resolve("versionResource"), classes.resolve("versionResource"), @@ -217,10 +258,10 @@ Path classes = Paths.get(usr, "classes", "test"); Files.createDirectory(classes); - Path source = Paths.get(src, "data", "runtimetest", "test"); + Path source = srcFileRoot.resolve("test"); assertTrue( - CompilerUtils.compile(source, classes, "-cp", "classes/base/")); - Files.copy(Paths.get(src, "data", "runtimetest", "manifest.txt"), + CompilerUtils.compile(source, classes, "-cp", "classes/v" + OLD_RELEASE)); + Files.copy(srcFileRoot.resolve("manifest.txt"), Paths.get(usr, "manifest.txt"), StandardCopyOption.REPLACE_EXISTING); } --- old/test/tools/jar/multiRelease/data/runtimetest/v9/testpackage/Helper.java 2017-05-24 10:53:07.000000000 +0800 +++ /dev/null 2017-05-24 10:53:07.000000000 +0800 @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package testpackage; - -public class Helper { - - private static final int HELPER_VERSION = 9; - - public static int getHelperVersion() { - return HELPER_VERSION; - } -} --- /dev/null 2017-05-24 10:53:07.000000000 +0800 +++ new/test/tools/jar/multiRelease/data/runtimetest/helper.template 2017-05-24 10:53:07.000000000 +0800 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package testpackage; + +public class Helper { + + private static final int HELPER_VERSION = $version; + + public static int getHelperVersion() { + return HELPER_VERSION; + } +} --- old/test/tools/jar/multiRelease/data/runtimetest/v9/testpackage/Main.java 2017-05-24 10:53:08.000000000 +0800 +++ /dev/null 2017-05-24 10:53:08.000000000 +0800 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package testpackage; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class Main { - - private static final int MAIN_VERSION = 9; - - public static void main(String[] args) { - System.out.println("Main version: " + getMainVersion()); - System.out.println("Helpers version: " + getHelperVersion()); - System.out.println("Resource version: " + getResourceVersion()); - } - - public static int getMainVersion() { - return MAIN_VERSION; - } - - public static int getHelperVersion() { - return testpackage.Helper.getHelperVersion(); - } - - public static int getResourceVersion() { - ClassLoader cl = Main.class.getClassLoader(); - InputStream ris = cl.getResourceAsStream("versionResource"); - if (ris == null) { - throw new Error("Test issue: resource versionResource" - + " cannot be loaded!"); - } - try (BufferedReader br = new BufferedReader(new InputStreamReader(ris))) { - return Integer.parseInt(br.readLine()); - } catch (IOException ioe) { - throw new Error("Unexpected issue", ioe); - } - } -} --- /dev/null 2017-05-24 10:53:08.000000000 +0800 +++ new/test/tools/jar/multiRelease/data/runtimetest/main.template 2017-05-24 10:53:08.000000000 +0800 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package testpackage; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class Main { + + private static final int MAIN_VERSION = $version; + + public static void main(String[] args) { + System.out.println("Main version: " + getMainVersion()); + System.out.println("Helpers version: " + getHelperVersion()); + System.out.println("Resource version: " + getResourceVersion()); + } + + public static int getMainVersion() { + return MAIN_VERSION; + } + + public static int getHelperVersion() { + return testpackage.Helper.getHelperVersion(); + } + + public static int getResourceVersion() { + ClassLoader cl = Main.class.getClassLoader(); + InputStream ris = cl.getResourceAsStream("versionResource"); + if (ris == null) { + throw new Error("Test issue: resource versionResource" + + " cannot be loaded!"); + } + try (BufferedReader br = new BufferedReader(new InputStreamReader(ris))) { + return Integer.parseInt(br.readLine()); + } catch (IOException ioe) { + throw new Error("Unexpected issue", ioe); + } + } +} --- old/test/tools/jar/multiRelease/data/runtimetest/v9/versionResource 2017-05-24 10:53:09.000000000 +0800 +++ /dev/null 2017-05-24 10:53:09.000000000 +0800 @@ -1 +0,0 @@ -9 --- /dev/null 2017-05-24 10:53:09.000000000 +0800 +++ new/test/tools/jar/multiRelease/data/runtimetest/resource.template 2017-05-24 10:53:09.000000000 +0800 @@ -0,0 +1 @@ +$version --- old/test/tools/jar/multiRelease/data/runtimetest/base/testpackage/Helper.java 2017-05-24 10:53:10.000000000 +0800 +++ /dev/null 2017-05-24 10:53:10.000000000 +0800 @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package testpackage; - -public class Helper { - - private static final int HELPER_VERSION = 8; - - public static int getHelperVersion() { - return HELPER_VERSION; - } -} --- old/test/tools/jar/multiRelease/data/runtimetest/base/testpackage/Main.java 2017-05-24 10:53:10.000000000 +0800 +++ /dev/null 2017-05-24 10:53:10.000000000 +0800 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package testpackage; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class Main { - - private static final int MAIN_VERSION = 8; - - public static void main(String[] args) { - System.out.println("Main version: " + getMainVersion()); - System.out.println("Helpers version: " + getHelperVersion()); - System.out.println("Resource version: " + getResourceVersion()); - } - - public static int getMainVersion() { - return MAIN_VERSION; - } - - public static int getHelperVersion() { - return testpackage.Helper.getHelperVersion(); - } - - public static int getResourceVersion() { - ClassLoader cl = Main.class.getClassLoader(); - InputStream ris = cl.getResourceAsStream("versionResource"); - if (ris == null) { - throw new Error("Test issue: resource versionResource" - + " cannot be loaded!"); - } - try (BufferedReader br = new BufferedReader(new InputStreamReader(ris))) { - return Integer.parseInt(br.readLine()); - } catch (IOException ioe) { - throw new Error("Unexpected issue", ioe); - } - } -} --- old/test/tools/jar/multiRelease/data/runtimetest/base/versionResource 2017-05-24 10:53:11.000000000 +0800 +++ /dev/null 2017-05-24 10:53:11.000000000 +0800 @@ -1 +0,0 @@ -8 \ No newline at end of file --- old/test/tools/jar/multiRelease/data/runtimetest/v10/testpackage/Helper.java 2017-05-24 10:53:11.000000000 +0800 +++ /dev/null 2017-05-24 10:53:11.000000000 +0800 @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package testpackage; - -public class Helper { - - private static final int HELPER_VERSION = 10; - - public static int getHelperVersion() { - return HELPER_VERSION; - } -} --- old/test/tools/jar/multiRelease/data/runtimetest/v10/testpackage/Main.java 2017-05-24 10:53:12.000000000 +0800 +++ /dev/null 2017-05-24 10:53:12.000000000 +0800 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package testpackage; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class Main { - - private static final int MAIN_VERSION = 10; - - public static void main(String[] args) { - System.out.println("Main version: " + getMainVersion()); - System.out.println("Helpers version: " + getHelperVersion()); - System.out.println("Resource version: " + getResourceVersion()); - } - - public static int getMainVersion() { - return MAIN_VERSION; - } - - public static int getHelperVersion() { - return testpackage.Helper.getHelperVersion(); - } - - public static int getResourceVersion() { - ClassLoader cl = Main.class.getClassLoader(); - InputStream ris = cl.getResourceAsStream("versionResource"); - if (ris == null) { - throw new Error("Test issue: resource versionResource" - + " cannot be loaded!"); - } - try (BufferedReader br = new BufferedReader(new InputStreamReader(ris))) { - return Integer.parseInt(br.readLine()); - } catch (IOException ioe) { - throw new Error("Unexpected issue", ioe); - } - } -} --- old/test/tools/jar/multiRelease/data/runtimetest/v10/versionResource 2017-05-24 10:53:12.000000000 +0800 +++ /dev/null 2017-05-24 10:53:12.000000000 +0800 @@ -1 +0,0 @@ -10