38 |
38 |
39 public class ArgsEnvVar extends TestHelper { |
39 public class ArgsEnvVar extends TestHelper { |
40 private static File testJar = null; |
40 private static File testJar = null; |
41 private static Map<String, String> env = new HashMap<>(); |
41 private static Map<String, String> env = new HashMap<>(); |
42 |
42 |
43 private static String JAVA_OPTIONS = "JAVA_OPTIONS"; |
43 private static String JDK_JAVA_OPTIONS = "JDK_JAVA_OPTIONS"; |
44 |
44 |
45 static void init() throws IOException { |
45 static void init() throws IOException { |
46 if (testJar != null) { |
46 if (testJar != null) { |
47 return; |
47 return; |
48 } |
48 } |
103 public void basic() throws IOException { |
103 public void basic() throws IOException { |
104 File argFile1 = createArgFile("argFile1", List.of("-Xmx32m")); |
104 File argFile1 = createArgFile("argFile1", List.of("-Xmx32m")); |
105 File argFile2 = createArgFile("argFile2", List.of("-Darg.file2=TWO")); |
105 File argFile2 = createArgFile("argFile2", List.of("-Darg.file2=TWO")); |
106 File argFile3 = createArgFile("argFile3", List.of("-Darg.file3=THREE")); |
106 File argFile3 = createArgFile("argFile3", List.of("-Darg.file3=THREE")); |
107 |
107 |
108 env.put(JAVA_OPTIONS, "@argFile1\n-Xint\r-cp @@escaped\t@argFile2"); |
108 env.put(JDK_JAVA_OPTIONS, "@argFile1\n-Xint\r-cp @@escaped\t@argFile2"); |
109 |
109 |
110 TestResult tr = doExec(env, javaCmd, "@argFile3", "-cp", "test.jar", "Foo", "uarg1", "@uarg2"); |
110 TestResult tr = doExec(env, javaCmd, "@argFile3", "-cp", "test.jar", "Foo", "uarg1", "@uarg2"); |
111 |
111 |
112 List<String> appArgs = new ArrayList<>(); |
112 List<String> appArgs = new ArrayList<>(); |
113 appArgs.add("uarg1"); |
113 appArgs.add("uarg1"); |
131 argFile2.delete(); |
131 argFile2.delete(); |
132 argFile3.delete(); |
132 argFile3.delete(); |
133 } |
133 } |
134 |
134 |
135 private TestResult testInEnv(List<String> options) { |
135 private TestResult testInEnv(List<String> options) { |
136 env.put(JAVA_OPTIONS, String.join(" ", options)); |
136 env.put(JDK_JAVA_OPTIONS, String.join(" ", options)); |
137 return doExec(env, javaCmd, "-jar", "test.jar"); |
137 return doExec(env, javaCmd, "-jar", "test.jar"); |
138 } |
138 } |
139 |
139 |
140 private TestResult testInEnvAsArgFile(List<String> options) throws IOException { |
140 private TestResult testInEnvAsArgFile(List<String> options) throws IOException { |
141 File argFile = createArgFile("argFile", options); |
141 File argFile = createArgFile("argFile", options); |
142 env.put(JAVA_OPTIONS, "@argFile"); |
142 env.put(JDK_JAVA_OPTIONS, "@argFile"); |
143 TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
143 TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
144 argFile.delete(); |
144 argFile.delete(); |
145 return tr; |
145 return tr; |
146 } |
146 } |
147 |
147 |
185 @Test |
185 @Test |
186 public void quote() throws IOException { |
186 public void quote() throws IOException { |
187 File argFile1 = createArgFile("arg File 1", List.of("-Xint")); |
187 File argFile1 = createArgFile("arg File 1", List.of("-Xint")); |
188 File argFile2 = createArgFile("arg File 2", List.of("-Dprop='value with spaces'")); |
188 File argFile2 = createArgFile("arg File 2", List.of("-Dprop='value with spaces'")); |
189 File argFile3 = createArgFile("arg File 3", List.of("-Xmx32m")); |
189 File argFile3 = createArgFile("arg File 3", List.of("-Xmx32m")); |
190 env.put(JAVA_OPTIONS, "'@arg File 1' @\"arg File 2\" @'arg File'\" 3\""); |
190 env.put(JDK_JAVA_OPTIONS, "'@arg File 1' @\"arg File 2\" @'arg File'\" 3\""); |
191 |
191 |
192 TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
192 TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
193 List<String> options = new ArrayList<>(); |
193 List<String> options = new ArrayList<>(); |
194 options.add("-Xint"); |
194 options.add("-Xint"); |
195 options.add("-Dprop=value with spaces"); |
195 options.add("-Dprop=value with spaces"); |
202 argFile3.delete(); |
202 argFile3.delete(); |
203 } |
203 } |
204 |
204 |
205 @Test |
205 @Test |
206 public void openQuoteShouldFail() { |
206 public void openQuoteShouldFail() { |
207 env.put(JAVA_OPTIONS, "-Dprop='value missing close quote"); |
207 env.put(JDK_JAVA_OPTIONS, "-Dprop='value missing close quote"); |
208 TestResult tr = doExec(env, javaCmd, "-version"); |
208 TestResult tr = doExec(env, javaCmd, "-version"); |
209 tr.checkNegative(); |
209 tr.checkNegative(); |
210 if (!tr.testStatus) { |
210 if (!tr.testStatus) { |
211 System.out.println(tr); |
211 System.out.println(tr); |
212 throw new RuntimeException("test fails"); |
212 throw new RuntimeException("test fails"); |
213 } |
213 } |
214 } |
214 } |
215 |
215 |
216 @Test |
216 @Test |
217 public void noWildcard() { |
217 public void noWildcard() { |
218 env.put(JAVA_OPTIONS, "-cp *"); |
218 env.put(JDK_JAVA_OPTIONS, "-cp *"); |
219 TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
219 TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); |
220 verifyOptions(List.of("-cp", "*", "-jar", "test.jar"), tr); |
220 verifyOptions(List.of("-cp", "*", "-jar", "test.jar"), tr); |
221 |
221 |
222 env.put(JAVA_OPTIONS, "-p ?"); |
222 env.put(JDK_JAVA_OPTIONS, "-p ?"); |
223 tr = doExec(env, javaCmd, "-jar", "test.jar", "one", "two"); |
223 tr = doExec(env, javaCmd, "-jar", "test.jar", "one", "two"); |
224 verifyOptions(List.of("-p", "?", "-jar", "test.jar", "one", "two"), tr); |
224 verifyOptions(List.of("-p", "?", "-jar", "test.jar", "one", "two"), tr); |
225 } |
225 } |
226 |
226 |
227 public static void main(String... args) throws Exception { |
227 public static void main(String... args) throws Exception { |