1 /* 2 * Copyright (c) 2016, 2018, 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 /** 26 * @test 27 * @bug 8213362 28 * @comment Test JLI_Launch for tools distributed outside JDK 29 * @library /test/lib 30 * @run main/native JliLaunchTest 31 */ 32 33 import java.util.Map; 34 import jdk.test.lib.Utils; 35 import jdk.test.lib.Platform; 36 import jdk.test.lib.process.OutputAnalyzer; 37 38 import java.io.IOException; 39 import java.nio.file.Files; 40 import java.nio.file.Path; 41 import java.nio.file.Paths; 42 43 public class JliLaunchTest { main(String[] args)44 public static void main(String[] args) throws IOException { 45 Path launcher = Paths.get(System.getProperty("test.nativepath"), 46 "JliLaunchTest" + (Platform.isWindows() ? ".exe" : "")); 47 System.out.println("Launcher = " + launcher + (Files.exists(launcher) ? " (exists)" : " (not exists)")); 48 ProcessBuilder pb = new ProcessBuilder(launcher.toString(), "--version"); 49 Map<String, String> env = pb.environment(); 50 if (Platform.isWindows()) { 51 // The DLL should be in JDK/bin 52 String libdir = Paths.get(Utils.TEST_JDK).resolve("bin").toAbsolutePath().toString(); 53 env.compute("PATH", (k, v) -> (v == null) ? libdir : libdir + ";" + v); 54 } else { 55 String libdir = Paths.get(Utils.TEST_JDK).resolve("lib").toAbsolutePath().toString(); 56 String LD_LIBRARY_PATH = Platform.isOSX() ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"; 57 env.compute(LD_LIBRARY_PATH, (k, v) -> (v == null) ? libdir : libdir + ":" + v); 58 } 59 60 OutputAnalyzer outputf = new OutputAnalyzer(pb.start()); 61 outputf.shouldHaveExitValue(0); 62 } 63 } 64 65