test/jdk/tools/launcher/JliLaunchTest.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 52989 18f36a093334
child 53273 bbc79e0ec9ee
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52788
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     1
/*
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     4
 *
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     7
 * published by the Free Software Foundation.
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     8
 *
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    13
 * accompanied this code).
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    14
 *
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    18
 *
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    21
 * questions.
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    22
 *
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    23
 */
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    24
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    25
/**
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    26
 * @test
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    27
 * @bug 8213362
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    28
 * @comment Test JLI_Launch for tools distributed outside JDK
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    29
 * @library /test/lib
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    30
 * @run main/native JliLaunchTest
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    31
 */
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    32
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    33
import java.util.Map;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    34
import jdk.test.lib.Utils;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    35
import jdk.test.lib.Platform;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    37
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    38
import java.io.IOException;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    39
import java.nio.file.Files;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    40
import java.nio.file.Path;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    41
import java.nio.file.Paths;
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    42
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    43
public class JliLaunchTest {
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    44
    public static void main(String[] args) throws IOException {
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    45
        Path launcher = Paths.get(System.getProperty("test.nativepath"),
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    46
            "JliLaunchTest" + (Platform.isWindows() ? ".exe" : ""));
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    47
        System.out.println("Launcher = " + launcher + (Files.exists(launcher) ? " (exists)" : " (not exists)"));
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    48
        ProcessBuilder pb = new ProcessBuilder(launcher.toString(), "--version");
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    49
        Map<String, String> env = pb.environment();
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    50
        if (Platform.isWindows()) {
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    51
            // The DLL should be in JDK/bin
52989
18f36a093334 8215000: tools/launcher/JliLaunchTest.java fails on Windows
henryjen
parents: 52788
diff changeset
    52
            String libdir = Paths.get(Utils.TEST_JDK).resolve("bin").toAbsolutePath().toString();
18f36a093334 8215000: tools/launcher/JliLaunchTest.java fails on Windows
henryjen
parents: 52788
diff changeset
    53
            env.compute("PATH", (k, v) -> (v == null) ? libdir : libdir + ";" + v);
52788
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    54
        } else {
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    55
            String libdir = Paths.get(Utils.TEST_JDK).resolve("lib").toAbsolutePath().toString();
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    56
            String LD_LIBRARY_PATH = Platform.isOSX() ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH";
52989
18f36a093334 8215000: tools/launcher/JliLaunchTest.java fails on Windows
henryjen
parents: 52788
diff changeset
    57
            env.compute(LD_LIBRARY_PATH, (k, v) -> (v == null) ? libdir : libdir + ":" + v);
52788
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    58
        }
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    59
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    60
        OutputAnalyzer outputf = new OutputAnalyzer(pb.start());
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    61
        outputf.shouldHaveExitValue(0);
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    62
    }
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    63
}
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents:
diff changeset
    64