1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4087295 4785472 27 * @library /test/lib 28 * @build jdk.test.lib.compiler.CompilerUtils 29 * @build jdk.test.lib.process.ProcessTools 30 * @build RenamePackageTest 31 * @run main RenamePackageTest 32 * @summary Enable resolveClass() to accommodate package renaming. 33 * This fix enables one to implement a resolveClass method that maps a 34 * Serialiazable class within a serialization stream to the same class 35 * in a different package within the JVM runtime. See run shell script 36 * for instructions on how to run this test. 37 */ 38 39 import java.io.File; 40 import java.nio.file.Path; 41 import java.nio.file.Paths; 42 43 import jdk.test.lib.compiler.CompilerUtils; 44 import jdk.test.lib.process.ProcessTools; 45 46 public class RenamePackageTest { 47 public static void main(String args[]) throws Exception { 48 setup(); 49 50 runTestSerialDriver(); 51 runInstallSerialDriver(); 52 53 runInstallSerialDriver(); 54 runTestSerialDriver(); 55 } 56 57 private static final Path SHARE = Paths.get(System.getProperty("test.classes"), "share"); 58 private static final Path OCLASSES = Paths.get(System.getProperty("test.classes"), "oclasses"); 59 private static final Path NCLASSES = Paths.get(System.getProperty("test.classes"), "nclasses"); 60 61 private static void setup() throws Exception { 62 63 boolean b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "extension"), 64 SHARE); 65 assertTrue(b); 66 b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "test"), 67 OCLASSES, 68 "-classpath", 69 SHARE.toString()); 70 assertTrue(b); 71 b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "install"), 72 NCLASSES, 73 "-classpath", 74 SHARE.toString()); 75 assertTrue(b); 76 } 77 78 private static void runTestSerialDriver() throws Exception { 79 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, 80 "-classpath", 81 SHARE.toString() 82 + File.pathSeparator 83 + OCLASSES.toString(), 84 "test.SerialDriver", "-s"); 85 Process p = ProcessTools.startProcess("test SerialDriver", pb); 86 p.waitFor(); 87 assertTrue(p.exitValue() == 0); 88 } 89 90 private static void runInstallSerialDriver() throws Exception { 91 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, 92 "-classpath", 93 SHARE.toString() 94 + File.pathSeparator 95 + NCLASSES.toString(), 96 "install.SerialDriver", "-d"); 97 Process p = ProcessTools.startProcess("install SerialDriver", pb); 98 p.waitFor(); 99 assertTrue(p.exitValue() == 0); 100 } 101 102 private static void assertTrue(boolean b) { 103 if (!b) { 104 throw new RuntimeException("expected true, get false"); 105 } 106 } 107 }