author | ksrini |
Wed, 15 Feb 2017 18:07:28 -0800 | |
changeset 43874 | d49715456f51 |
parent 41438 | 5e21aa284a82 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.main; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.io.Reader; |
|
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
30 |
import java.nio.file.Files; |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
31 |
import java.nio.file.Paths; |
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
32 |
import java.util.ArrayList; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
33 |
import java.util.Arrays; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
34 |
import java.util.List; |
10 | 35 |
|
36 |
/** |
|
37 |
* Various utility methods for processing Java tool command line arguments. |
|
38 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
40 |
* If you write code that depends on this, you do so at your own risk. |
10 | 41 |
* This code and its internal interfaces are subject to change or |
42 |
* deletion without notice.</b> |
|
43 |
*/ |
|
44 |
public class CommandLine { |
|
45 |
/** |
|
46 |
* Process Win32-style command files for the specified command line |
|
47 |
* arguments and return the resulting arguments. A command file argument |
|
48 |
* is of the form '@file' where 'file' is the name of the file whose |
|
49 |
* contents are to be parsed for additional arguments. The contents of |
|
50 |
* the command file are parsed using StreamTokenizer and the original |
|
51 |
* '@file' argument replaced with the resulting tokens. Recursive command |
|
52 |
* files are not supported. The '@' character itself can be quoted with |
|
53 |
* the sequence '@@'. |
|
41438 | 54 |
* @param args the arguments that may contain @files |
55 |
* @return the arguments, with @files expanded |
|
56 |
* @throws IOException if there is a problem reading any of the @files |
|
10 | 57 |
*/ |
41438 | 58 |
public static String[] parse(String[] args) throws IOException { |
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
59 |
List<String> newArgs = new ArrayList<>(); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
60 |
appendParsedCommandArgs(newArgs, Arrays.asList(args)); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
61 |
return newArgs.toArray(new String[newArgs.size()]); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
62 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
63 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
64 |
private static void appendParsedCommandArgs(List<String> newArgs, List<String> args) throws IOException { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
7681
diff
changeset
|
65 |
for (String arg : args) { |
10 | 66 |
if (arg.length() > 1 && arg.charAt(0) == '@') { |
67 |
arg = arg.substring(1); |
|
68 |
if (arg.charAt(0) == '@') { |
|
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
69 |
newArgs.add(arg); |
10 | 70 |
} else { |
71 |
loadCmdFile(arg, newArgs); |
|
72 |
} |
|
73 |
} else { |
|
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
74 |
newArgs.add(arg); |
10 | 75 |
} |
76 |
} |
|
77 |
} |
|
78 |
||
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
79 |
/** |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
80 |
* Process the given environment variable and appends any Win32-style |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
81 |
* command files for the specified command line arguments and return |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
82 |
* the resulting arguments. A command file argument |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
83 |
* is of the form '@file' where 'file' is the name of the file whose |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
84 |
* contents are to be parsed for additional arguments. The contents of |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
85 |
* the command file are parsed using StreamTokenizer and the original |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
86 |
* '@file' argument replaced with the resulting tokens. Recursive command |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
87 |
* files are not supported. The '@' character itself can be quoted with |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
88 |
* the sequence '@@'. |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
89 |
* @param envVariable the env variable to process |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
90 |
* @param args the arguments that may contain @files |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
91 |
* @return the arguments, with environment variable's content and expansion of @files |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
92 |
* @throws IOException if there is a problem reading any of the @files |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
93 |
* @throws com.sun.tools.javac.main.CommandLine.UnmatchedQuote |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
94 |
*/ |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
95 |
public static List<String> parse(String envVariable, List<String> args) |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
96 |
throws IOException, UnmatchedQuote { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
97 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
98 |
List<String> inArgs = new ArrayList<>(); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
99 |
appendParsedEnvVariables(inArgs, envVariable); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
100 |
inArgs.addAll(args); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
101 |
List<String> newArgs = new ArrayList<>(); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
102 |
appendParsedCommandArgs(newArgs, inArgs); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
103 |
return newArgs; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
104 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
105 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
106 |
/** |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
107 |
* Process the given environment variable and appends any Win32-style |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
108 |
* command files for the specified command line arguments and return |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
109 |
* the resulting arguments. A command file argument |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
110 |
* is of the form '@file' where 'file' is the name of the file whose |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
111 |
* contents are to be parsed for additional arguments. The contents of |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
112 |
* the command file are parsed using StreamTokenizer and the original |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
113 |
* '@file' argument replaced with the resulting tokens. Recursive command |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
114 |
* files are not supported. The '@' character itself can be quoted with |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
115 |
* the sequence '@@'. |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
116 |
* @param envVariable the env variable to process |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
117 |
* @param args the arguments that may contain @files |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
118 |
* @return the arguments, with environment variable's content and expansion of @files |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
119 |
* @throws IOException if there is a problem reading any of the @files |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
120 |
* @throws com.sun.tools.javac.main.CommandLine.UnmatchedQuote |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
121 |
*/ |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
122 |
public static String[] parse(String envVariable, String[] args) throws IOException, UnmatchedQuote { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
123 |
List<String> out = parse(envVariable, Arrays.asList(args)); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
124 |
return out.toArray(new String[out.size()]); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
125 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
126 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
127 |
private static void loadCmdFile(String name, List<String> args) throws IOException { |
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
128 |
try (Reader r = Files.newBufferedReader(Paths.get(name))) { |
41438 | 129 |
Tokenizer t = new Tokenizer(r); |
130 |
String s; |
|
131 |
while ((s = t.nextToken()) != null) { |
|
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
132 |
args.add(s); |
41438 | 133 |
} |
134 |
} |
|
135 |
} |
|
136 |
||
137 |
public static class Tokenizer { |
|
138 |
private final Reader in; |
|
139 |
private int ch; |
|
140 |
||
141 |
public Tokenizer(Reader in) throws IOException { |
|
142 |
this.in = in; |
|
143 |
ch = in.read(); |
|
144 |
} |
|
145 |
||
146 |
public String nextToken() throws IOException { |
|
147 |
skipWhite(); |
|
148 |
if (ch == -1) { |
|
149 |
return null; |
|
150 |
} |
|
151 |
||
152 |
StringBuilder sb = new StringBuilder(); |
|
153 |
char quoteChar = 0; |
|
154 |
||
155 |
while (ch != -1) { |
|
156 |
switch (ch) { |
|
157 |
case ' ': |
|
158 |
case '\t': |
|
159 |
case '\f': |
|
160 |
if (quoteChar == 0) { |
|
161 |
return sb.toString(); |
|
162 |
} |
|
163 |
sb.append((char) ch); |
|
164 |
break; |
|
165 |
||
166 |
case '\n': |
|
167 |
case '\r': |
|
168 |
return sb.toString(); |
|
169 |
||
170 |
case '\'': |
|
171 |
case '"': |
|
172 |
if (quoteChar == 0) { |
|
173 |
quoteChar = (char) ch; |
|
174 |
} else if (quoteChar == ch) { |
|
175 |
quoteChar = 0; |
|
176 |
} else { |
|
177 |
sb.append((char) ch); |
|
178 |
} |
|
179 |
break; |
|
180 |
||
181 |
case '\\': |
|
182 |
if (quoteChar != 0) { |
|
183 |
ch = in.read(); |
|
184 |
switch (ch) { |
|
185 |
case '\n': |
|
186 |
case '\r': |
|
187 |
while (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f') { |
|
188 |
ch = in.read(); |
|
189 |
} |
|
190 |
continue; |
|
191 |
||
192 |
case 'n': |
|
193 |
ch = '\n'; |
|
194 |
break; |
|
195 |
case 'r': |
|
196 |
ch = '\r'; |
|
197 |
break; |
|
198 |
case 't': |
|
199 |
ch = '\t'; |
|
200 |
break; |
|
201 |
case 'f': |
|
202 |
ch = '\f'; |
|
203 |
break; |
|
204 |
} |
|
205 |
} |
|
206 |
sb.append((char) ch); |
|
207 |
break; |
|
208 |
||
209 |
default: |
|
210 |
sb.append((char) ch); |
|
211 |
} |
|
212 |
||
213 |
ch = in.read(); |
|
214 |
} |
|
215 |
||
216 |
return sb.toString(); |
|
217 |
} |
|
218 |
||
219 |
void skipWhite() throws IOException { |
|
220 |
while (ch != -1) { |
|
221 |
switch (ch) { |
|
222 |
case ' ': |
|
223 |
case '\t': |
|
224 |
case '\n': |
|
225 |
case '\r': |
|
226 |
case '\f': |
|
227 |
break; |
|
228 |
||
229 |
case '#': |
|
230 |
ch = in.read(); |
|
231 |
while (ch != '\n' && ch != '\r' && ch != -1) { |
|
232 |
ch = in.read(); |
|
233 |
} |
|
234 |
break; |
|
235 |
||
236 |
default: |
|
237 |
return; |
|
238 |
} |
|
239 |
||
240 |
ch = in.read(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
7681
diff
changeset
|
241 |
} |
10 | 242 |
} |
243 |
} |
|
43874
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
244 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
245 |
@SuppressWarnings("fallthrough") |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
246 |
private static void appendParsedEnvVariables(List<String> newArgs, String envVariable) |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
247 |
throws UnmatchedQuote { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
248 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
249 |
if (envVariable == null) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
250 |
return; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
251 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
252 |
String in = System.getenv(envVariable); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
253 |
if (in == null || in.trim().isEmpty()) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
254 |
return; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
255 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
256 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
257 |
final char NUL = (char)0; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
258 |
final int len = in.length(); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
259 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
260 |
int pos = 0; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
261 |
StringBuilder sb = new StringBuilder(); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
262 |
char quote = NUL; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
263 |
char ch; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
264 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
265 |
loop: |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
266 |
while (pos < len) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
267 |
ch = in.charAt(pos); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
268 |
switch (ch) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
269 |
case '\"': case '\'': |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
270 |
if (quote == NUL) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
271 |
quote = ch; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
272 |
} else if (quote == ch) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
273 |
quote = NUL; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
274 |
} else { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
275 |
sb.append(ch); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
276 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
277 |
pos++; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
278 |
break; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
279 |
case '\f': case '\n': case '\r': case '\t': case ' ': |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
280 |
if (quote == NUL) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
281 |
newArgs.add(sb.toString()); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
282 |
sb.setLength(0); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
283 |
while (ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ') { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
284 |
pos++; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
285 |
if (pos >= len) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
286 |
break loop; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
287 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
288 |
ch = in.charAt(pos); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
289 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
290 |
break; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
291 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
292 |
// fall through |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
293 |
default: |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
294 |
sb.append(ch); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
295 |
pos++; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
296 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
297 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
298 |
if (sb.length() != 0) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
299 |
newArgs.add(sb.toString()); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
300 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
301 |
if (quote != NUL) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
302 |
throw new UnmatchedQuote(envVariable); |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
303 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
304 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
305 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
306 |
public static class UnmatchedQuote extends Exception { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
307 |
private static final long serialVersionUID = 0; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
308 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
309 |
public final String variableName; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
310 |
|
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
311 |
UnmatchedQuote(String variable) { |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
312 |
this.variableName = variable; |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
313 |
} |
d49715456f51
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents:
41438
diff
changeset
|
314 |
} |
10 | 315 |
} |