Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/launcher/JliLaunchTest.java
41144 views
1
/*
2
* Copyright (c) 2016, 2020, 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 8238225
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.File;
39
import java.io.IOException;
40
import java.nio.file.Files;
41
import java.nio.file.Path;
42
import java.nio.file.Paths;
43
44
public class JliLaunchTest {
45
public static void main(String[] args) throws IOException {
46
Path launcher = Paths.get(System.getProperty("test.nativepath"),
47
"JliLaunchTest" + (Platform.isWindows() ? ".exe" : ""));
48
System.out.println("Launcher = " + launcher + (Files.exists(launcher) ? " (exists)" : " (not exists)"));
49
ProcessBuilder pb = new ProcessBuilder(launcher.toString(), "--version");
50
Map<String, String> env = pb.environment();
51
// On windows, the DLL should be in JDK/bin, else in JDK/lib.
52
String libdir = Paths.get(Utils.TEST_JDK).resolve(Platform.isWindows() ? "bin" : "lib")
53
.toAbsolutePath().toString();
54
String pathEnvVar = Platform.sharedLibraryPathVariableName();
55
env.compute(pathEnvVar, (k, v) -> (v == null) ? libdir : libdir + File.pathSeparator + v);
56
57
OutputAnalyzer outputf = new OutputAnalyzer(pb.start());
58
outputf.shouldHaveExitValue(0);
59
60
if (Platform.isOSX()) {
61
Path javaHome = Paths.get(Utils.TEST_JDK);
62
if (javaHome.getFileName().toString().equals("Home")) {
63
// To exercise this test path you need to make sure the JDK under test is
64
// the MacOS bundle and not the simple jdk image. This can currently be
65
// achieved by running something like this (from the build output dir):
66
// $ make test-only TEST=test/jdk/tools/launcher/JliLaunchTest.java \
67
// JDK_IMAGE_DIR=$PWD/images/jdk-bundle/jdk-15.jdk/Contents/Home
68
System.out.println("MacOS bundle distribution detected, also testing Contents/MacOS/libjli.dylib");
69
String macosDir = javaHome.getParent().resolve("MacOS").toString();
70
ProcessBuilder pb2 = new ProcessBuilder(launcher.toString(), "--version");
71
env = pb2.environment();
72
env.compute(pathEnvVar, (k, v) -> (v == null) ? macosDir : macosDir + File.pathSeparator + v);
73
74
OutputAnalyzer output2 = new OutputAnalyzer(pb2.start());
75
output2.shouldHaveExitValue(0);
76
} else {
77
System.out.println("Not a MacOS bundle distribution, not testing Contents/MacOS/libjli.dylib");
78
}
79
}
80
}
81
}
82
83