Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/tools/launcher/TestSpecialArgs.java
66643 views
1
/*
2
* Copyright (c) 2012, 2021, 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 7124089 7131021 8042469 8066185 8074373 8258917
27
* @summary Checks for Launcher special flags, such as MacOSX specific flags.
28
* @modules jdk.compiler
29
* jdk.zipfs
30
* @compile -XDignore.symbol.file TestSpecialArgs.java EnvironmentVariables.java
31
* @run main TestSpecialArgs
32
*/
33
import java.io.File;
34
import java.io.FileNotFoundException;
35
import java.util.HashMap;
36
import java.util.HashSet;
37
import java.util.Map;
38
import java.util.Set;
39
40
public class TestSpecialArgs extends TestHelper {
41
42
public static void main(String... args) throws Exception {
43
new TestSpecialArgs().run(args);
44
}
45
46
@Test
47
void testDocking() {
48
final Map<String, String> envMap = new HashMap<>();
49
envMap.put("_JAVA_LAUNCHER_DEBUG", "true");
50
TestResult tr = doExec(envMap, javaCmd, "-XstartOnFirstThread", "-version");
51
if (isMacOSX) {
52
if (!tr.contains("In same thread")) {
53
System.out.println(tr);
54
throw new RuntimeException("Error: not running in the same thread ?");
55
}
56
if (!tr.isOK()) {
57
System.out.println(tr);
58
throw new RuntimeException("Error: arg was rejected ????");
59
}
60
} else {
61
if (tr.isOK()) {
62
System.out.println(tr);
63
throw new RuntimeException("Error: argument was accepted ????");
64
}
65
}
66
67
tr = doExec(javaCmd, "-Xdock:/tmp/not-available", "-version");
68
if (isMacOSX) {
69
if (!tr.isOK()) {
70
System.out.println(tr);
71
throw new RuntimeException("Error: arg was rejected ????");
72
}
73
} else {
74
if (tr.isOK()) {
75
System.out.println(tr);
76
throw new RuntimeException("Error: argument was accepted ????");
77
}
78
}
79
// MacOSX specific tests ensue......
80
if (!isMacOSX) {
81
return;
82
}
83
Set<String> envToRemove = new HashSet<>();
84
Map<String, String> map = System.getenv();
85
for (String s : map.keySet()) {
86
if (s.startsWith("JAVA_MAIN_CLASS_")
87
|| s.startsWith("APP_NAME_")
88
|| s.startsWith("APP_ICON_")) {
89
envToRemove.add(s);
90
}
91
}
92
runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
93
"EnvironmentVariables", "JAVA_MAIN_CLASS_*",
94
"EnvironmentVariables");
95
96
runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
97
"-Xdock:name=TestAppName", "EnvironmentVariables",
98
"APP_NAME_*", "TestAppName");
99
100
runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
101
"-Xdock:icon=TestAppIcon", "EnvironmentVariables",
102
"APP_ICON_*", "TestAppIcon");
103
}
104
105
void runTest(Set<String> envToRemove, String... args) {
106
TestResult tr = doExec(null, envToRemove, args);
107
if (!tr.isOK()) {
108
System.err.println(tr.toString());
109
throw new RuntimeException("Test Fails");
110
}
111
}
112
113
void checkTestResult(TestResult tr) {
114
if (!tr.isOK()) {
115
System.err.println(tr.toString());
116
throw new RuntimeException("Test Fails");
117
}
118
}
119
}
120
121