author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
1 |
/* |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
4 |
* |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
8 |
* |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
13 |
* accompanied this code). |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
14 |
* |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
18 |
* |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
21 |
* questions. |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
22 |
*/ |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
23 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
24 |
/** |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
25 |
* @test |
45252
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
26 |
* @bug 8170832 8180447 |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
27 |
* @summary Arguments passed in environment variable |
45944
882cea808912
8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents:
45252
diff
changeset
|
28 |
* @modules jdk.compiler |
882cea808912
8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents:
45252
diff
changeset
|
29 |
* jdk.zipfs |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
30 |
* @build TestHelper |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
31 |
* @run main ArgsEnvVar |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
32 |
*/ |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
33 |
import java.io.File; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
34 |
import java.io.IOException; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
36 |
import java.util.HashMap; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
37 |
import java.util.List; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
38 |
import java.util.Map; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
39 |
import java.util.regex.Pattern; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
40 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
41 |
public class ArgsEnvVar extends TestHelper { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
42 |
private static File testJar = null; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
43 |
private static Map<String, String> env = new HashMap<>(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
44 |
|
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
45 |
private static String JDK_JAVA_OPTIONS = "JDK_JAVA_OPTIONS"; |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
46 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
47 |
static void init() throws IOException { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
48 |
if (testJar != null) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
49 |
return; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
50 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
51 |
testJar = new File("test.jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
52 |
StringBuilder tsrc = new StringBuilder(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
53 |
tsrc.append("public static void main(String... args) {\n"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
54 |
tsrc.append(" for (String x : args) {\n"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
55 |
tsrc.append(" System.out.println(x);\n"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
56 |
tsrc.append(" }\n"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
57 |
tsrc.append("}\n"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
58 |
createJar(testJar, new File("Foo"), tsrc.toString()); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
59 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
60 |
env.put(JLDEBUG_KEY, "true"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
61 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
62 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
63 |
private File createArgFile(String fname, List<String> lines) throws IOException { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
64 |
File argFile = new File(fname); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
65 |
argFile.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
66 |
createAFile(argFile, lines); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
67 |
return argFile; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
68 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
69 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
70 |
private void verifyOptions(List<String> args, TestResult tr) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
71 |
if (args.isEmpty()) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
72 |
return; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
73 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
74 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
75 |
int i = 1; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
76 |
for (String x : args) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
77 |
tr.matches(".*argv\\[" + i + "\\] = " + Pattern.quote(x) + ".*"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
78 |
i++; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
79 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
80 |
if (! tr.testStatus) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
81 |
System.out.println(tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
82 |
throw new RuntimeException("test fails"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
83 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
84 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
85 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
86 |
private void verifyUserArgs(List<String> args, TestResult tr, int index) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
87 |
if (javaCmd != TestHelper.javaCmd) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
88 |
tr.contains("\tFirst application arg index: 1"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
89 |
} else { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
90 |
tr.contains("\tFirst application arg index: " + index); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
91 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
92 |
for (String arg: args) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
93 |
tr.matches("^" + Pattern.quote(arg) + "$"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
94 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
95 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
96 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
97 |
if (! tr.testStatus) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
98 |
System.out.println(tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
99 |
throw new RuntimeException("test fails"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
100 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
101 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
102 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
103 |
@Test |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
104 |
// Verify prepend and @argfile expansion |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
105 |
public void basic() throws IOException { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
106 |
File argFile1 = createArgFile("argFile1", List.of("-Xmx32m")); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
107 |
File argFile2 = createArgFile("argFile2", List.of("-Darg.file2=TWO")); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
108 |
File argFile3 = createArgFile("argFile3", List.of("-Darg.file3=THREE")); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
109 |
|
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
110 |
env.put(JDK_JAVA_OPTIONS, "@argFile1\n-Xint\r-cp @@escaped\t@argFile2"); |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
111 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
112 |
TestResult tr = doExec(env, javaCmd, "@argFile3", "-cp", "test.jar", "Foo", "uarg1", "@uarg2"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
113 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
114 |
List<String> appArgs = new ArrayList<>(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
115 |
appArgs.add("uarg1"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
116 |
appArgs.add("@uarg2"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
117 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
118 |
List<String> options = new ArrayList<>(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
119 |
options.add("-Xmx32m"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
120 |
options.add("-Xint"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
121 |
options.add("-cp"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
122 |
options.add("@escaped"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
123 |
options.add("-Darg.file2=TWO"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
124 |
options.add("-Darg.file3=THREE"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
125 |
options.add("-cp"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
126 |
options.add("test.jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
127 |
options.add("Foo"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
128 |
options.addAll(appArgs); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
129 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
130 |
verifyOptions(options, tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
131 |
verifyUserArgs(appArgs, tr, 10); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
132 |
argFile1.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
133 |
argFile2.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
134 |
argFile3.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
135 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
136 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
137 |
private TestResult testInEnv(List<String> options) { |
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
138 |
env.put(JDK_JAVA_OPTIONS, String.join(" ", options)); |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
139 |
return doExec(env, javaCmd, "-jar", "test.jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
140 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
141 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
142 |
private TestResult testInEnvAsArgFile(List<String> options) throws IOException { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
143 |
File argFile = createArgFile("argFile", options); |
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
144 |
env.put(JDK_JAVA_OPTIONS, "@argFile"); |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
145 |
TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
146 |
argFile.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
147 |
return tr; |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
148 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
149 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
150 |
@Test |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
151 |
public void noTerminalOpt() throws IOException { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
152 |
List<List<String>> terminal_opts = List.of( |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
153 |
List.of("-jar", "test.jar"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
154 |
List.of("-m", "test/Foo"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
155 |
List.of("--module", "test/Foo"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
156 |
List.of("--dry-run"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
157 |
List.of("-h"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
158 |
List.of("-?"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
159 |
List.of("-help"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
160 |
List.of("--help"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
161 |
List.of("-X"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
162 |
List.of("--help-extra"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
163 |
List.of("-version"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
164 |
List.of("--version"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
165 |
List.of("-fullversion"), |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
166 |
List.of("--full-version")); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
167 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
168 |
for (List<String> options: terminal_opts) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
169 |
// terminal opt in environment variable |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
170 |
TestResult tr = testInEnv(options); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
171 |
tr.checkNegative(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
172 |
if (!tr.testStatus) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
173 |
System.out.println(tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
174 |
throw new RuntimeException("test fails"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
175 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
176 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
177 |
// terminal opt in environment variable through @file |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
178 |
tr = testInEnvAsArgFile(options); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
179 |
tr.checkNegative(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
180 |
if (!tr.testStatus) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
181 |
System.out.println(tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
182 |
throw new RuntimeException("test fails"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
183 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
184 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
185 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
186 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
187 |
@Test |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
188 |
public void quote() throws IOException { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
189 |
File argFile1 = createArgFile("arg File 1", List.of("-Xint")); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
190 |
File argFile2 = createArgFile("arg File 2", List.of("-Dprop='value with spaces'")); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
191 |
File argFile3 = createArgFile("arg File 3", List.of("-Xmx32m")); |
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
192 |
env.put(JDK_JAVA_OPTIONS, "'@arg File 1' @\"arg File 2\" @'arg File'\" 3\""); |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
193 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
194 |
TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
195 |
List<String> options = new ArrayList<>(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
196 |
options.add("-Xint"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
197 |
options.add("-Dprop=value with spaces"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
198 |
options.add("-Xmx32m"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
199 |
options.add("-jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
200 |
options.add("test.jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
201 |
verifyOptions(options, tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
202 |
argFile1.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
203 |
argFile2.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
204 |
argFile3.delete(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
205 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
206 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
207 |
@Test |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
208 |
public void openQuoteShouldFail() { |
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
209 |
env.put(JDK_JAVA_OPTIONS, "-Dprop='value missing close quote"); |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
210 |
TestResult tr = doExec(env, javaCmd, "-version"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
211 |
tr.checkNegative(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
212 |
if (!tr.testStatus) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
213 |
System.out.println(tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
214 |
throw new RuntimeException("test fails"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
215 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
216 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
217 |
|
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
218 |
@Test |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
219 |
public void noWildcard() { |
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
220 |
env.put(JDK_JAVA_OPTIONS, "-cp *"); |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
221 |
TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
222 |
verifyOptions(List.of("-cp", "*", "-jar", "test.jar"), tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
223 |
|
43691
f3c0d65c7b17
8173712: Rename JAVA_OPTIONS environment variable to JDK_JAVA_OPTIONS
mchung
parents:
43325
diff
changeset
|
224 |
env.put(JDK_JAVA_OPTIONS, "-p ?"); |
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
225 |
tr = doExec(env, javaCmd, "-jar", "test.jar", "one", "two"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
226 |
verifyOptions(List.of("-p", "?", "-jar", "test.jar", "one", "two"), tr); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
227 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
228 |
|
45252
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
229 |
@Test |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
230 |
public void testTrailingSpaces() { |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
231 |
env.put(JDK_JAVA_OPTIONS, "--add-exports java.base/jdk.internal.misc=ALL-UNNAMED "); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
232 |
TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
233 |
verifyOptions(List.of("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", "-jar", "test.jar"), tr); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
234 |
|
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
235 |
env.put(JDK_JAVA_OPTIONS, "--class-path ' '"); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
236 |
tr = doExec(env, javaCmd, "-jar", "test.jar"); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
237 |
verifyOptions(List.of("--class-path", " ", "-jar", "test.jar"), tr); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
238 |
|
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
239 |
env.put(JDK_JAVA_OPTIONS, " --add-exports java.base/jdk.internal.misc=ALL-UNNAMED "); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
240 |
tr = doExec(env, javaCmd, "-jar", "test.jar"); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
241 |
verifyOptions(List.of("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", "-jar", "test.jar"), tr); |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
242 |
} |
654115968257
8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch
henryjen
parents:
43691
diff
changeset
|
243 |
|
43325
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
244 |
public static void main(String... args) throws Exception { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
245 |
init(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
246 |
ArgsEnvVar a = new ArgsEnvVar(); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
247 |
a.run(args); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
248 |
if (testExitValue > 0) { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
249 |
System.out.println("Total of " + testExitValue + " failed"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
250 |
System.exit(1); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
251 |
} else { |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
252 |
System.out.println("All tests pass"); |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
253 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
254 |
} |
033e4cced1dc
8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents:
diff
changeset
|
255 |
} |