jdk
1/*
2* Copyright (c) 2019, Google Inc. 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* @summary Test with symbolic linked lib/modules
27* @bug 8220095
28* @requires os.family == "linux" | os.family == "mac"
29* @requires vm.flagless
30* @library /test/lib
31* @modules java.management
32* jdk.jlink
33* @run driver ModulesSymLink
34*/
35
36import java.io.File;37import java.nio.file.Files;38import java.nio.file.Path;39import java.nio.file.Paths;40import jdk.test.lib.process.ProcessTools;41import jdk.test.lib.process.OutputAnalyzer;42
43public class ModulesSymLink {44static String java_home;45static String test_jdk;46
47public static void main(String[] args) throws Throwable {48java_home = System.getProperty("java.home");49test_jdk = System.getProperty("user.dir") + File.separator +50"modulessymlink_jdk" + Long.toString(System.currentTimeMillis());51
52constructTestJDK();53
54ProcessBuilder pb = new ProcessBuilder(55test_jdk + File.separator + "bin" + File.separator + "java",56"-version");57OutputAnalyzer out = new OutputAnalyzer(pb.start());58out.shouldHaveExitValue(0);59}60
61// 1) Create a test JDK binary (jlink is used to help simplify the process,62// alternatively a test JDK could be copied from JAVA_HOME.)63// 2) Rename the test JDK's lib/modules to lib/0.64// 3) Then create a link to lib/0 as lib/modules.65static void constructTestJDK() throws Throwable {66Path jlink = Paths.get(java_home, "bin", "jlink");67System.out.println("Jlink = " + jlink);68OutputAnalyzer out = ProcessTools.executeProcess(jlink.toString(),69"--output", test_jdk,70"--add-modules", "java.base");71out.shouldHaveExitValue(0);72
73Path modules = Paths.get(test_jdk, "lib", "modules");74Path renamed_modules = Paths.get(test_jdk, "lib", "0");75Files.move(modules, renamed_modules);76Files.createSymbolicLink(modules, renamed_modules);77}78}
79