author | jjg |
Thu, 03 Nov 2016 13:59:15 -0700 | |
changeset 41938 | 8e66bf10fcec |
parent 41637 | 7b24b4c32ee6 |
child 41992 | 720257f5307d |
permissions | -rw-r--r-- |
11315 | 1 |
/* |
36153 | 2 |
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. |
11315 | 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.main; |
|
27 |
||
14960 | 28 |
import java.io.FileWriter; |
29 |
import java.io.PrintWriter; |
|
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
30 |
import java.nio.file.Files; |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
31 |
import java.nio.file.Path; |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
32 |
import java.nio.file.Paths; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
33 |
import java.text.Collator; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
34 |
import java.util.Arrays; |
11315 | 35 |
import java.util.Collections; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
36 |
import java.util.Comparator; |
14960 | 37 |
import java.util.EnumSet; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
38 |
import java.util.Iterator; |
14960 | 39 |
import java.util.LinkedHashMap; |
41637 | 40 |
import java.util.LinkedHashSet; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
41 |
import java.util.Locale; |
14960 | 42 |
import java.util.Map; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
43 |
import java.util.ServiceLoader; |
14960 | 44 |
import java.util.Set; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
45 |
import java.util.TreeSet; |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
46 |
import java.util.regex.Pattern; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
47 |
import java.util.stream.Collectors; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
48 |
import java.util.stream.StreamSupport; |
14960 | 49 |
|
50 |
import javax.lang.model.SourceVersion; |
|
51 |
||
52 |
import com.sun.tools.doclint.DocLint; |
|
11315 | 53 |
import com.sun.tools.javac.code.Lint; |
23114 | 54 |
import com.sun.tools.javac.code.Lint.LintCategory; |
11315 | 55 |
import com.sun.tools.javac.code.Source; |
56 |
import com.sun.tools.javac.code.Type; |
|
15724 | 57 |
import com.sun.tools.javac.jvm.Profile; |
11315 | 58 |
import com.sun.tools.javac.jvm.Target; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
59 |
import com.sun.tools.javac.platform.PlatformProvider; |
14960 | 60 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
61 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
62 |
import com.sun.tools.javac.util.Assert; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
63 |
import com.sun.tools.javac.util.JDK9Wrappers; |
14960 | 64 |
import com.sun.tools.javac.util.Log; |
65 |
import com.sun.tools.javac.util.Log.PrefixKind; |
|
66 |
import com.sun.tools.javac.util.Log.WriterKind; |
|
11315 | 67 |
import com.sun.tools.javac.util.Options; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19670
diff
changeset
|
68 |
import com.sun.tools.javac.util.StringUtils; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
69 |
|
11315 | 70 |
import static com.sun.tools.javac.main.Option.ChoiceKind.*; |
14960 | 71 |
import static com.sun.tools.javac.main.Option.OptionGroup.*; |
11315 | 72 |
import static com.sun.tools.javac.main.Option.OptionKind.*; |
73 |
||
74 |
/** |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
75 |
* Options for javac. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
76 |
* The specific Option to handle a command-line option can be found by calling |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
77 |
* {@link #lookup}, which search some or all of the members of this enum in order, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
78 |
* looking for the first {@link #matches match}. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
79 |
* The action for an Option is performed {@link #handleOption}, which determines |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
80 |
* whether an argument is needed and where to find it; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
81 |
* {@code handleOption} then calls {@link #process process} providing a suitable |
11315 | 82 |
* {@link OptionHelper} to provide access the compiler state. |
83 |
* |
|
84 |
* <p><b>This is NOT part of any supported API. |
|
85 |
* If you write code that depends on this, you do so at your own |
|
86 |
* risk. This code and its internal interfaces are subject to change |
|
87 |
* or deletion without notice.</b></p> |
|
88 |
*/ |
|
89 |
public enum Option { |
|
90 |
G("-g", "opt.g", STANDARD, BASIC), |
|
91 |
||
92 |
G_NONE("-g:none", "opt.g.none", STANDARD, BASIC) { |
|
93 |
@Override |
|
94 |
public boolean process(OptionHelper helper, String option) { |
|
95 |
helper.put("-g:", "none"); |
|
96 |
return false; |
|
97 |
} |
|
98 |
}, |
|
99 |
||
100 |
G_CUSTOM("-g:", "opt.g.lines.vars.source", |
|
101 |
STANDARD, BASIC, ANYOF, "lines", "vars", "source"), |
|
102 |
||
103 |
XLINT("-Xlint", "opt.Xlint", EXTENDED, BASIC), |
|
104 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
105 |
XLINT_CUSTOM("-Xlint:", "opt.arg.Xlint", "opt.Xlint.custom", EXTENDED, BASIC, ANYOF, getXLintChoices()) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
106 |
private final String LINT_KEY_FORMAT = LARGE_INDENT + " %-" + |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
107 |
(DEFAULT_SYNOPSIS_WIDTH + SMALL_INDENT.length() - LARGE_INDENT.length() - 2) + "s %s"; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
24298
diff
changeset
|
108 |
@Override |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
109 |
protected void help(Log log) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
110 |
super.help(log); |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
111 |
log.printRawLines(WriterKind.STDOUT, |
23114 | 112 |
String.format(LINT_KEY_FORMAT, |
113 |
"all", |
|
114 |
log.localize(PrefixKind.JAVAC, "opt.Xlint.all"))); |
|
115 |
for (LintCategory lc : LintCategory.values()) { |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
116 |
log.printRawLines(WriterKind.STDOUT, |
23114 | 117 |
String.format(LINT_KEY_FORMAT, |
118 |
lc.option, |
|
119 |
log.localize(PrefixKind.JAVAC, |
|
120 |
"opt.Xlint.desc." + lc.option))); |
|
121 |
} |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
122 |
log.printRawLines(WriterKind.STDOUT, |
23114 | 123 |
String.format(LINT_KEY_FORMAT, |
124 |
"none", |
|
125 |
log.localize(PrefixKind.JAVAC, "opt.Xlint.none"))); |
|
126 |
} |
|
127 |
}, |
|
11315 | 128 |
|
14960 | 129 |
XDOCLINT("-Xdoclint", "opt.Xdoclint", EXTENDED, BASIC), |
130 |
||
131 |
XDOCLINT_CUSTOM("-Xdoclint:", "opt.Xdoclint.subopts", "opt.Xdoclint.custom", EXTENDED, BASIC) { |
|
132 |
@Override |
|
133 |
public boolean matches(String option) { |
|
134 |
return DocLint.isValidOption( |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
135 |
option.replace(XDOCLINT_CUSTOM.primaryName, DocLint.XMSGS_CUSTOM_PREFIX)); |
14960 | 136 |
} |
137 |
||
138 |
@Override |
|
139 |
public boolean process(OptionHelper helper, String option) { |
|
140 |
String prev = helper.get(XDOCLINT_CUSTOM); |
|
141 |
String next = (prev == null) ? option : (prev + " " + option); |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
142 |
helper.put(XDOCLINT_CUSTOM.primaryName, next); |
14960 | 143 |
return false; |
144 |
} |
|
145 |
}, |
|
146 |
||
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
147 |
XDOCLINT_PACKAGE("-Xdoclint/package:", "opt.Xdoclint.package.args", "opt.Xdoclint.package.desc", EXTENDED, BASIC) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
148 |
@Override |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
149 |
public boolean matches(String option) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
150 |
return DocLint.isValidOption( |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
151 |
option.replace(XDOCLINT_PACKAGE.primaryName, DocLint.XCHECK_PACKAGE)); |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
152 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
153 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
154 |
@Override |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
155 |
public boolean process(OptionHelper helper, String option) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
156 |
String prev = helper.get(XDOCLINT_PACKAGE); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
157 |
String next = (prev == null) ? option : (prev + " " + option); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
158 |
helper.put(XDOCLINT_PACKAGE.primaryName, next); |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
159 |
return false; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
160 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
161 |
}, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26264
diff
changeset
|
162 |
|
11315 | 163 |
// -nowarn is retained for command-line backward compatibility |
164 |
NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) { |
|
165 |
@Override |
|
166 |
public boolean process(OptionHelper helper, String option) { |
|
167 |
helper.put("-Xlint:none", option); |
|
168 |
return false; |
|
169 |
} |
|
170 |
}, |
|
171 |
||
172 |
VERBOSE("-verbose", "opt.verbose", STANDARD, BASIC), |
|
173 |
||
174 |
// -deprecation is retained for command-line backward compatibility |
|
175 |
DEPRECATION("-deprecation", "opt.deprecation", STANDARD, BASIC) { |
|
176 |
@Override |
|
177 |
public boolean process(OptionHelper helper, String option) { |
|
178 |
helper.put("-Xlint:deprecation", option); |
|
179 |
return false; |
|
180 |
} |
|
181 |
}, |
|
182 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
183 |
CLASS_PATH("--class-path -classpath -cp", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
184 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
185 |
SOURCE_PATH("--source-path -sourcepath", "opt.arg.path", "opt.sourcepath", STANDARD, FILEMANAGER), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
186 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
187 |
MODULE_SOURCE_PATH("--module-source-path", "opt.arg.mspath", "opt.modulesourcepath", STANDARD, FILEMANAGER), |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
188 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
189 |
MODULE_PATH("--module-path -p", "opt.arg.path", "opt.modulepath", STANDARD, FILEMANAGER), |
11315 | 190 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
191 |
UPGRADE_MODULE_PATH("--upgrade-module-path", "opt.arg.path", "opt.upgrademodulepath", STANDARD, FILEMANAGER), |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
192 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
193 |
SYSTEM("--system", "opt.arg.jdk", "opt.system", STANDARD, FILEMANAGER), |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
194 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
195 |
PATCH_MODULE("--patch-module", "opt.arg.patch", "opt.patch", EXTENDED, FILEMANAGER) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
196 |
// The deferred filemanager diagnostics mechanism assumes a single value per option, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
197 |
// but --patch-module can be used multiple times, once per module. Therefore we compose |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
198 |
// a value for the option containing the last value specified for each module, and separate |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
199 |
// the the module=path pairs by an invalid path character, NULL. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
200 |
// The standard file manager code knows to split apart the NULL-separated components. |
11315 | 201 |
@Override |
202 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
203 |
if (!arg.contains("=")) { // could be more strict regeex, e.g. "(?i)[a-z0-9_.]+=.*" |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
204 |
helper.error(Errors.LocnInvalidArgForXpatch(arg)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
205 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
206 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
207 |
String previous = helper.get(this); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
208 |
if (previous == null) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
209 |
return super.process(helper, option, arg); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
210 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
211 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
212 |
Map<String,String> map = new LinkedHashMap<>(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
213 |
for (String s : previous.split("\0")) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
214 |
int sep = s.indexOf('='); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
215 |
map.put(s.substring(0, sep), s.substring(sep + 1)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
216 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
217 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
218 |
int sep = arg.indexOf('='); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
219 |
map.put(arg.substring(0, sep), arg.substring(sep + 1)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
220 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
221 |
StringBuilder sb = new StringBuilder(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
222 |
map.forEach((m, p) -> { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
223 |
if (sb.length() > 0) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
224 |
sb.append('\0'); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
225 |
sb.append(m).append('=').append(p); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
226 |
}); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
227 |
return super.process(helper, option, sb.toString()); |
11315 | 228 |
} |
229 |
}, |
|
230 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
231 |
BOOT_CLASS_PATH("--boot-class-path -bootclasspath", "opt.arg.path", "opt.bootclasspath", STANDARD, FILEMANAGER) { |
11315 | 232 |
@Override |
233 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
234 |
helper.remove("-Xbootclasspath/p:"); |
|
235 |
helper.remove("-Xbootclasspath/a:"); |
|
236 |
return super.process(helper, option, arg); |
|
237 |
} |
|
238 |
}, |
|
239 |
||
240 |
XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:", "opt.arg.path", "opt.Xbootclasspath.p", EXTENDED, FILEMANAGER), |
|
241 |
||
242 |
XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:", "opt.arg.path", "opt.Xbootclasspath.a", EXTENDED, FILEMANAGER), |
|
243 |
||
244 |
XBOOTCLASSPATH("-Xbootclasspath:", "opt.arg.path", "opt.bootclasspath", EXTENDED, FILEMANAGER) { |
|
245 |
@Override |
|
246 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
247 |
helper.remove("-Xbootclasspath/p:"); |
|
248 |
helper.remove("-Xbootclasspath/a:"); |
|
249 |
return super.process(helper, "-bootclasspath", arg); |
|
250 |
} |
|
251 |
}, |
|
252 |
||
253 |
EXTDIRS("-extdirs", "opt.arg.dirs", "opt.extdirs", STANDARD, FILEMANAGER), |
|
254 |
||
255 |
DJAVA_EXT_DIRS("-Djava.ext.dirs=", "opt.arg.dirs", "opt.extdirs", EXTENDED, FILEMANAGER) { |
|
256 |
@Override |
|
257 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
258 |
return EXTDIRS.process(helper, "-extdirs", arg); |
11315 | 259 |
} |
260 |
}, |
|
261 |
||
262 |
ENDORSEDDIRS("-endorseddirs", "opt.arg.dirs", "opt.endorseddirs", STANDARD, FILEMANAGER), |
|
263 |
||
264 |
DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs=", "opt.arg.dirs", "opt.endorseddirs", EXTENDED, FILEMANAGER) { |
|
265 |
@Override |
|
266 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
267 |
return ENDORSEDDIRS.process(helper, "-endorseddirs", arg); |
11315 | 268 |
} |
269 |
}, |
|
270 |
||
271 |
PROC("-proc:", "opt.proc.none.only", STANDARD, BASIC, ONEOF, "none", "only"), |
|
272 |
||
273 |
PROCESSOR("-processor", "opt.arg.class.list", "opt.processor", STANDARD, BASIC), |
|
274 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
275 |
PROCESSOR_PATH("--processor-path -processorpath", "opt.arg.path", "opt.processorpath", STANDARD, FILEMANAGER), |
11315 | 276 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
277 |
PROCESSOR_MODULE_PATH("--processor-module-path", "opt.arg.path", "opt.processormodulepath", STANDARD, FILEMANAGER), |
36526 | 278 |
|
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14960
diff
changeset
|
279 |
PARAMETERS("-parameters","opt.parameters", STANDARD, BASIC), |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14960
diff
changeset
|
280 |
|
11315 | 281 |
D("-d", "opt.arg.directory", "opt.d", STANDARD, FILEMANAGER), |
282 |
||
283 |
S("-s", "opt.arg.directory", "opt.sourceDest", STANDARD, FILEMANAGER), |
|
284 |
||
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11317
diff
changeset
|
285 |
H("-h", "opt.arg.directory", "opt.headerDest", STANDARD, FILEMANAGER), |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11317
diff
changeset
|
286 |
|
11315 | 287 |
IMPLICIT("-implicit:", "opt.implicit", STANDARD, BASIC, ONEOF, "none", "class"), |
288 |
||
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
36153
diff
changeset
|
289 |
ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER), |
11315 | 290 |
|
291 |
SOURCE("-source", "opt.arg.release", "opt.source", STANDARD, BASIC) { |
|
292 |
@Override |
|
293 |
public boolean process(OptionHelper helper, String option, String operand) { |
|
294 |
Source source = Source.lookup(operand); |
|
295 |
if (source == null) { |
|
296 |
helper.error("err.invalid.source", operand); |
|
297 |
return true; |
|
298 |
} |
|
299 |
return super.process(helper, option, operand); |
|
300 |
} |
|
301 |
}, |
|
302 |
||
303 |
TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) { |
|
304 |
@Override |
|
305 |
public boolean process(OptionHelper helper, String option, String operand) { |
|
306 |
Target target = Target.lookup(operand); |
|
307 |
if (target == null) { |
|
308 |
helper.error("err.invalid.target", operand); |
|
309 |
return true; |
|
310 |
} |
|
311 |
return super.process(helper, option, operand); |
|
312 |
} |
|
313 |
}, |
|
314 |
||
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
315 |
RELEASE("--release", "opt.arg.release", "opt.release", STANDARD, BASIC) { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
316 |
@Override |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
317 |
protected void help(Log log) { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
318 |
Iterable<PlatformProvider> providers = |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
319 |
ServiceLoader.load(PlatformProvider.class, Arguments.class.getClassLoader()); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
320 |
Set<String> platforms = StreamSupport.stream(providers.spliterator(), false) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
321 |
.flatMap(provider -> StreamSupport.stream(provider.getSupportedPlatformNames() |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
322 |
.spliterator(), |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
323 |
false)) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
324 |
.collect(Collectors.toCollection(TreeSet :: new)); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
325 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
326 |
StringBuilder targets = new StringBuilder(); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
327 |
String delim = ""; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
328 |
for (String platform : platforms) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
329 |
targets.append(delim); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
330 |
targets.append(platform); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
331 |
delim = ", "; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
332 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
333 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
334 |
super.help(log, log.localize(PrefixKind.JAVAC, descrKey, targets.toString())); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
335 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
336 |
}, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
29427
diff
changeset
|
337 |
|
15724 | 338 |
PROFILE("-profile", "opt.arg.profile", "opt.profile", STANDARD, BASIC) { |
339 |
@Override |
|
340 |
public boolean process(OptionHelper helper, String option, String operand) { |
|
341 |
Profile profile = Profile.lookup(operand); |
|
342 |
if (profile == null) { |
|
343 |
helper.error("err.invalid.profile", operand); |
|
344 |
return true; |
|
345 |
} |
|
346 |
return super.process(helper, option, operand); |
|
347 |
} |
|
348 |
}, |
|
349 |
||
11315 | 350 |
VERSION("-version", "opt.version", STANDARD, INFO) { |
351 |
@Override |
|
352 |
public boolean process(OptionHelper helper, String option) { |
|
353 |
Log log = helper.getLog(); |
|
354 |
String ownName = helper.getOwnName(); |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
355 |
log.printLines(WriterKind.STDOUT, PrefixKind.JAVAC, "version", ownName, JavaCompiler.version()); |
11315 | 356 |
return super.process(helper, option); |
357 |
} |
|
358 |
}, |
|
359 |
||
360 |
FULLVERSION("-fullversion", null, HIDDEN, INFO) { |
|
361 |
@Override |
|
362 |
public boolean process(OptionHelper helper, String option) { |
|
363 |
Log log = helper.getLog(); |
|
364 |
String ownName = helper.getOwnName(); |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
365 |
log.printLines(WriterKind.STDOUT, PrefixKind.JAVAC, "fullVersion", ownName, JavaCompiler.fullVersion()); |
11315 | 366 |
return super.process(helper, option); |
367 |
} |
|
368 |
}, |
|
369 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
370 |
// Note: -h is already taken for "native header output directory". |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
371 |
HELP("--help -help", "opt.help", STANDARD, INFO) { |
11315 | 372 |
@Override |
373 |
public boolean process(OptionHelper helper, String option) { |
|
374 |
Log log = helper.getLog(); |
|
375 |
String ownName = helper.getOwnName(); |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
376 |
log.printLines(WriterKind.STDOUT, PrefixKind.JAVAC, "msg.usage.header", ownName); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
377 |
showHelp(log, OptionKind.STANDARD); |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
378 |
log.printNewline(WriterKind.STDOUT); |
11315 | 379 |
return super.process(helper, option); |
380 |
} |
|
381 |
}, |
|
382 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
383 |
A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC, ArgKind.ADJACENT) { |
11315 | 384 |
@Override |
385 |
public boolean matches(String arg) { |
|
386 |
return arg.startsWith("-A"); |
|
387 |
} |
|
388 |
||
389 |
@Override |
|
390 |
public boolean hasArg() { |
|
391 |
return false; |
|
392 |
} |
|
393 |
// Mapping for processor options created in |
|
394 |
// JavacProcessingEnvironment |
|
395 |
@Override |
|
396 |
public boolean process(OptionHelper helper, String option) { |
|
397 |
int argLength = option.length(); |
|
398 |
if (argLength == 2) { |
|
399 |
helper.error("err.empty.A.argument"); |
|
400 |
return true; |
|
401 |
} |
|
402 |
int sepIndex = option.indexOf('='); |
|
403 |
String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) ); |
|
404 |
if (!JavacProcessingEnvironment.isValidOptionName(key)) { |
|
405 |
helper.error("err.invalid.A.key", option); |
|
406 |
return true; |
|
407 |
} |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
408 |
helper.put(option, option); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
409 |
return false; |
11315 | 410 |
} |
411 |
}, |
|
412 |
||
413 |
X("-X", "opt.X", STANDARD, INFO) { |
|
414 |
@Override |
|
415 |
public boolean process(OptionHelper helper, String option) { |
|
416 |
Log log = helper.getLog(); |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
417 |
showHelp(log, OptionKind.EXTENDED); |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
418 |
log.printNewline(WriterKind.STDOUT); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
39812
diff
changeset
|
419 |
log.printLines(WriterKind.STDOUT, PrefixKind.JAVAC, "msg.usage.nonstandard.footer"); |
11315 | 420 |
return super.process(helper, option); |
421 |
} |
|
422 |
}, |
|
423 |
||
424 |
// This option exists only for the purpose of documenting itself. |
|
425 |
// It's actually implemented by the launcher. |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
426 |
J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO, ArgKind.ADJACENT) { |
11315 | 427 |
@Override |
428 |
public boolean process(OptionHelper helper, String option) { |
|
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40835
diff
changeset
|
429 |
throw new AssertionError("the -J flag should be caught by the launcher."); |
11315 | 430 |
} |
431 |
}, |
|
432 |
||
433 |
MOREINFO("-moreinfo", null, HIDDEN, BASIC) { |
|
434 |
@Override |
|
435 |
public boolean process(OptionHelper helper, String option) { |
|
436 |
Type.moreInfo = true; |
|
437 |
return super.process(helper, option); |
|
438 |
} |
|
439 |
}, |
|
440 |
||
441 |
// treat warnings as errors |
|
442 |
WERROR("-Werror", "opt.Werror", STANDARD, BASIC), |
|
443 |
||
444 |
// prompt after each error |
|
445 |
// new Option("-prompt", "opt.prompt"), |
|
446 |
PROMPT("-prompt", null, HIDDEN, BASIC), |
|
447 |
||
448 |
// dump stack on error |
|
449 |
DOE("-doe", null, HIDDEN, BASIC), |
|
450 |
||
451 |
// output source after type erasure |
|
452 |
PRINTSOURCE("-printsource", null, HIDDEN, BASIC), |
|
453 |
||
454 |
// display warnings for generic unchecked operations |
|
455 |
WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) { |
|
456 |
@Override |
|
457 |
public boolean process(OptionHelper helper, String option) { |
|
458 |
helper.put("-Xlint:unchecked", option); |
|
459 |
return false; |
|
460 |
} |
|
461 |
}, |
|
462 |
||
463 |
XMAXERRS("-Xmaxerrs", "opt.arg.number", "opt.maxerrs", EXTENDED, BASIC), |
|
464 |
||
465 |
XMAXWARNS("-Xmaxwarns", "opt.arg.number", "opt.maxwarns", EXTENDED, BASIC), |
|
466 |
||
11316
4dcad625e72e
7111022: javac no long prints last round of processing
jjg
parents:
11315
diff
changeset
|
467 |
XSTDOUT("-Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) { |
11315 | 468 |
@Override |
469 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
470 |
try { |
|
471 |
Log log = helper.getLog(); |
|
472 |
log.setWriters(new PrintWriter(new FileWriter(arg), true)); |
|
473 |
} catch (java.io.IOException e) { |
|
474 |
helper.error("err.error.writing.file", arg, e); |
|
475 |
return true; |
|
476 |
} |
|
477 |
return super.process(helper, option, arg); |
|
478 |
} |
|
479 |
}, |
|
480 |
||
481 |
XPRINT("-Xprint", "opt.print", EXTENDED, BASIC), |
|
482 |
||
483 |
XPRINTROUNDS("-XprintRounds", "opt.printRounds", EXTENDED, BASIC), |
|
484 |
||
485 |
XPRINTPROCESSORINFO("-XprintProcessorInfo", "opt.printProcessorInfo", EXTENDED, BASIC), |
|
486 |
||
487 |
XPREFER("-Xprefer:", "opt.prefer", EXTENDED, BASIC, ONEOF, "source", "newer"), |
|
488 |
||
24298
cc4f0f71a505
8028196: Javac allows timestamps inside rt.jar to affect compilation when using -sourcepath.
alundblad
parents:
23792
diff
changeset
|
489 |
XXUSERPATHSFIRST("-XXuserPathsFirst", "opt.userpathsfirst", HIDDEN, BASIC), |
cc4f0f71a505
8028196: Javac allows timestamps inside rt.jar to affect compilation when using -sourcepath.
alundblad
parents:
23792
diff
changeset
|
490 |
|
19670
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
491 |
// see enum PkgInfo |
11315 | 492 |
XPKGINFO("-Xpkginfo:", "opt.pkginfo", EXTENDED, BASIC, ONEOF, "always", "legacy", "nonempty"), |
493 |
||
494 |
/* -O is a no-op, accepted for backward compatibility. */ |
|
495 |
O("-O", null, HIDDEN, BASIC), |
|
496 |
||
497 |
/* -Xjcov produces tables to support the code coverage tool jcov. */ |
|
498 |
XJCOV("-Xjcov", null, HIDDEN, BASIC), |
|
499 |
||
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
500 |
PLUGIN("-Xplugin:", "opt.arg.plugin", "opt.plugin", EXTENDED, BASIC) { |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
501 |
@Override |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
502 |
public boolean process(OptionHelper helper, String option) { |
36526 | 503 |
String p = option.substring(option.indexOf(':') + 1).trim(); |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
504 |
String prev = helper.get(PLUGIN); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
505 |
helper.put(PLUGIN.primaryName, (prev == null) ? p : prev + '\0' + p); |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
506 |
return false; |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
507 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
508 |
}, |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
509 |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
15724
diff
changeset
|
510 |
XDIAGS("-Xdiags:", "opt.diags", EXTENDED, BASIC, ONEOF, "compact", "verbose"), |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
15724
diff
changeset
|
511 |
|
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
512 |
DEBUG("--debug:", null, HIDDEN, BASIC) { |
39599 | 513 |
@Override |
514 |
public boolean process(OptionHelper helper, String option) { |
|
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
515 |
return HiddenGroup.DEBUG.process(helper, option); |
39599 | 516 |
} |
517 |
}, |
|
518 |
||
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
519 |
SHOULDSTOP("--should-stop:", null, HIDDEN, BASIC) { |
39601 | 520 |
@Override |
521 |
public boolean process(OptionHelper helper, String option) { |
|
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
522 |
return HiddenGroup.SHOULDSTOP.process(helper, option); |
39601 | 523 |
} |
524 |
}, |
|
525 |
||
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
526 |
DIAGS("--diags:", null, HIDDEN, BASIC) { |
39812 | 527 |
@Override |
528 |
public boolean process(OptionHelper helper, String option) { |
|
529 |
return HiddenGroup.DIAGS.process(helper, option); |
|
530 |
} |
|
531 |
}, |
|
532 |
||
533 |
/* This is a back door to the compiler's option table. |
|
534 |
* -XDx=y sets the option x to the value y. |
|
535 |
* -XDx sets the option x to the value x. |
|
536 |
*/ |
|
537 |
XD("-XD", null, HIDDEN, BASIC) { |
|
538 |
@Override |
|
539 |
public boolean matches(String s) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
540 |
return s.startsWith(primaryName); |
39812 | 541 |
} |
542 |
@Override |
|
543 |
public boolean process(OptionHelper helper, String option) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
544 |
return process(helper, option, option.substring(primaryName.length())); |
39812 | 545 |
} |
546 |
||
547 |
@Override |
|
548 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
549 |
int eq = arg.indexOf('='); |
|
550 |
String key = (eq < 0) ? arg : arg.substring(0, eq); |
|
551 |
String value = (eq < 0) ? arg : arg.substring(eq+1); |
|
552 |
helper.put(key, value); |
|
553 |
return false; |
|
554 |
} |
|
555 |
}, |
|
556 |
||
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
557 |
ADD_EXPORTS("--add-exports", "opt.arg.addExports", "opt.addExports", EXTENDED, BASIC) { |
36526 | 558 |
@Override |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
559 |
public boolean process(OptionHelper helper, String option, String arg) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
560 |
if (arg.isEmpty()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
561 |
helper.error("err.no.value.for.option", option); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
562 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
563 |
} else if (getPattern().matcher(arg).matches()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
564 |
String prev = helper.get(ADD_EXPORTS); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
565 |
helper.put(ADD_EXPORTS.primaryName, (prev == null) ? arg : prev + '\0' + arg); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
566 |
return false; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
567 |
} else { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
568 |
helper.error("err.bad.value.for.option", option, arg); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
569 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
570 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
571 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
572 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
573 |
@Override |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
574 |
public Pattern getPattern() { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
575 |
return Pattern.compile("([^/]+)/([^=]+)=(,*[^,].*)"); |
36526 | 576 |
} |
577 |
}, |
|
578 |
||
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
579 |
ADD_READS("--add-reads", "opt.arg.addReads", "opt.addReads", EXTENDED, BASIC) { |
36526 | 580 |
@Override |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
581 |
public boolean process(OptionHelper helper, String option, String arg) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
582 |
if (arg.isEmpty()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
583 |
helper.error("err.no.value.for.option", option); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
584 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
585 |
} else if (getPattern().matcher(arg).matches()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
586 |
String prev = helper.get(ADD_READS); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
587 |
helper.put(ADD_READS.primaryName, (prev == null) ? arg : prev + '\0' + arg); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
588 |
return false; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
589 |
} else { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
590 |
helper.error("err.bad.value.for.option", option, arg); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
591 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
592 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
593 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
594 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
595 |
@Override |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
596 |
public Pattern getPattern() { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
597 |
return Pattern.compile("([^=]+)=(,*[^,].*)"); |
36526 | 598 |
} |
599 |
}, |
|
600 |
||
601 |
XMODULE("-Xmodule:", "opt.arg.module", "opt.module", EXTENDED, BASIC) { |
|
602 |
@Override |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
603 |
public boolean process(OptionHelper helper, String option, String arg) { |
36526 | 604 |
String prev = helper.get(XMODULE); |
605 |
if (prev != null) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
606 |
helper.error("err.option.too.many", XMODULE.primaryName); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
607 |
return true; |
36526 | 608 |
} |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
609 |
helper.put(XMODULE.primaryName, arg); |
36526 | 610 |
return false; |
611 |
} |
|
612 |
}, |
|
613 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
614 |
MODULE("--module -m", "opt.arg.m", "opt.m", STANDARD, BASIC), |
36526 | 615 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
616 |
ADD_MODULES("--add-modules", "opt.arg.addmods", "opt.addmods", STANDARD, BASIC) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
617 |
@Override |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
618 |
public boolean process(OptionHelper helper, String option, String arg) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
619 |
if (arg.isEmpty()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
620 |
helper.error("err.no.value.for.option", option); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
621 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
622 |
} else if (getPattern().matcher(arg).matches()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
623 |
String prev = helper.get(ADD_MODULES); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
624 |
// since the individual values are simple names, we can simply join the |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
625 |
// values of multiple --add-modules options with ',' |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
626 |
helper.put(ADD_MODULES.primaryName, (prev == null) ? arg : prev + ',' + arg); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
627 |
return false; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
628 |
} else { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
629 |
helper.error("err.bad.value.for.option", option, arg); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
630 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
631 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
632 |
} |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
633 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
634 |
@Override |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
635 |
public Pattern getPattern() { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
636 |
return Pattern.compile(",*[^,].*"); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
637 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
638 |
}, |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
639 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
640 |
LIMIT_MODULES("--limit-modules", "opt.arg.limitmods", "opt.limitmods", STANDARD, BASIC) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
641 |
@Override |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
642 |
public boolean process(OptionHelper helper, String option, String arg) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
643 |
if (arg.isEmpty()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
644 |
helper.error("err.no.value.for.option", option); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
645 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
646 |
} else if (getPattern().matcher(arg).matches()) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
647 |
helper.put(LIMIT_MODULES.primaryName, arg); // last one wins |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
648 |
return false; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
649 |
} else { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
650 |
helper.error("err.bad.value.for.option", option, arg); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
651 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
652 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
653 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
654 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
655 |
@Override |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
656 |
public Pattern getPattern() { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
657 |
return Pattern.compile(",*[^,].*"); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
658 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
659 |
}, |
36526 | 660 |
|
11315 | 661 |
// This option exists only for the purpose of documenting itself. |
662 |
// It's actually implemented by the CommandLine class. |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
663 |
AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO, ArgKind.ADJACENT) { |
11315 | 664 |
@Override |
665 |
public boolean process(OptionHelper helper, String option) { |
|
666 |
throw new AssertionError("the @ flag should be caught by CommandLine."); |
|
667 |
} |
|
668 |
}, |
|
669 |
||
36526 | 670 |
// Standalone positional argument: source file or type name. |
11315 | 671 |
SOURCEFILE("sourcefile", null, HIDDEN, INFO) { |
672 |
@Override |
|
673 |
public boolean matches(String s) { |
|
36526 | 674 |
if (s.endsWith(".java")) // Java source file |
675 |
return true; |
|
676 |
int sep = s.indexOf('/'); |
|
677 |
if (sep != -1) { |
|
678 |
return SourceVersion.isName(s.substring(0, sep)) |
|
679 |
&& SourceVersion.isName(s.substring(sep + 1)); |
|
680 |
} else { |
|
681 |
return SourceVersion.isName(s); // Legal type name |
|
682 |
} |
|
11315 | 683 |
} |
684 |
@Override |
|
685 |
public boolean process(OptionHelper helper, String option) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
686 |
if (option.endsWith(".java") ) { |
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
687 |
Path p = Paths.get(option); |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
688 |
if (!Files.exists(p)) { |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
689 |
helper.error("err.file.not.found", p); |
11315 | 690 |
return true; |
691 |
} |
|
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
692 |
if (!Files.isRegularFile(p)) { |
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
693 |
helper.error("err.file.not.file", p); |
11315 | 694 |
return true; |
695 |
} |
|
36157
fdbf6c9be2ab
8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents:
36155
diff
changeset
|
696 |
helper.addFile(p); |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
697 |
} else { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
698 |
helper.addClassName(option); |
11315 | 699 |
} |
700 |
return false; |
|
701 |
} |
|
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
702 |
}, |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
703 |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40308
diff
changeset
|
704 |
MULTIRELEASE("--multi-release", "opt.arg.multi-release", "opt.multi-release", HIDDEN, FILEMANAGER), |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
705 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
706 |
INHERIT_RUNTIME_ENVIRONMENT("--inherit-runtime-environment", "opt.inherit_runtime_environment", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
707 |
EXTENDED, BASIC) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
708 |
@Override |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
709 |
public boolean process(OptionHelper helper, String option) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
710 |
try { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
711 |
Class.forName(JDK9Wrappers.VMHelper.VM_CLASSNAME); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
712 |
String[] runtimeArgs = JDK9Wrappers.VMHelper.getRuntimeArguments(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
713 |
for (String arg : runtimeArgs) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
714 |
// Handle any supported runtime options; ignore all others. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
715 |
// The runtime arguments always use the single token form, e.g. "--name=value". |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
716 |
for (Option o : getSupportedRuntimeOptions()) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
717 |
if (o.matches(arg)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
718 |
o.handleOption(helper, arg, Collections.emptyIterator()); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
719 |
break; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
720 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
721 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
722 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
723 |
} catch (ClassNotFoundException | SecurityException e) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
724 |
helper.error("err.cannot.access.runtime.env"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
725 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
726 |
return false; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
727 |
} |
11315 | 728 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
729 |
private Option[] getSupportedRuntimeOptions() { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
730 |
Option[] supportedRuntimeOptions = { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
731 |
ADD_EXPORTS, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
732 |
ADD_MODULES, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
733 |
LIMIT_MODULES, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
734 |
MODULE_PATH, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
735 |
UPGRADE_MODULE_PATH, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
736 |
PATCH_MODULE |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
737 |
}; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
738 |
return supportedRuntimeOptions; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
739 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
740 |
}; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
741 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
742 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
743 |
* The kind of argument, if any, accepted by this option. The kind is augmented |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
744 |
* by characters in the name of the option. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
745 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
746 |
public enum ArgKind { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
747 |
/** This option does not take any argument. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
748 |
NONE, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
749 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
750 |
// Not currently supported |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
751 |
// /** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
752 |
// * This option takes an optional argument, which may be provided directly after an '=' |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
753 |
// * separator, or in the following argument position if that word does not itself appear |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
754 |
// * to be the name of an option. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
755 |
// */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
756 |
// OPTIONAL, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
757 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
758 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
759 |
* This option takes an argument. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
760 |
* If the name of option ends with ':' or '=', the argument must be provided directly |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
761 |
* after that separator. |
41252
058d83c9b1c7
8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents:
40835
diff
changeset
|
762 |
* Otherwise, it may appear after an '=' or in the following argument position. |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
763 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
764 |
REQUIRED, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
765 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
766 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
767 |
* This option takes an argument immediately after the option name, with no separator |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
768 |
* character. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
769 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
770 |
ADJACENT |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
771 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
772 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
773 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
774 |
* The kind of an Option. This is used by the -help and -X options. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
775 |
*/ |
11315 | 776 |
public enum OptionKind { |
777 |
/** A standard option, documented by -help. */ |
|
778 |
STANDARD, |
|
779 |
/** An extended option, documented by -X. */ |
|
780 |
EXTENDED, |
|
781 |
/** A hidden option, not documented. */ |
|
782 |
HIDDEN, |
|
783 |
} |
|
784 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
785 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
786 |
* The group for an Option. This determines the situations in which the |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
787 |
* option is applicable. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
788 |
*/ |
11315 | 789 |
enum OptionGroup { |
790 |
/** A basic option, available for use on the command line or via the |
|
791 |
* Compiler API. */ |
|
792 |
BASIC, |
|
793 |
/** An option for javac's standard JavaFileManager. Other file managers |
|
794 |
* may or may not support these options. */ |
|
795 |
FILEMANAGER, |
|
796 |
/** A command-line option that requests information, such as -help. */ |
|
797 |
INFO, |
|
798 |
/** A command-line "option" representing a file or class name. */ |
|
799 |
OPERAND |
|
800 |
} |
|
801 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
802 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
803 |
* The kind of choice for "choice" options. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
804 |
*/ |
11315 | 805 |
enum ChoiceKind { |
806 |
/** The expected value is exactly one of the set of choices. */ |
|
807 |
ONEOF, |
|
808 |
/** The expected value is one of more of the set of choices. */ |
|
809 |
ANYOF |
|
810 |
} |
|
811 |
||
39812 | 812 |
enum HiddenGroup { |
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
813 |
DIAGS("diags"), |
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
814 |
DEBUG("debug"), |
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
815 |
SHOULDSTOP("should-stop"); |
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
816 |
|
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
817 |
static final Set<String> skipSet = new java.util.HashSet<>( |
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
818 |
Arrays.asList("--diags:", "--debug:", "--should-stop:")); |
39812 | 819 |
|
820 |
final String text; |
|
821 |
||
822 |
HiddenGroup(String text) { |
|
823 |
this.text = text; |
|
824 |
} |
|
825 |
||
826 |
public boolean process(OptionHelper helper, String option) { |
|
827 |
String p = option.substring(option.indexOf(':') + 1).trim(); |
|
828 |
String[] subOptions = p.split(";"); |
|
829 |
for (String subOption : subOptions) { |
|
830 |
subOption = text + "." + subOption.trim(); |
|
831 |
XD.process(helper, subOption, subOption); |
|
832 |
} |
|
833 |
return false; |
|
834 |
} |
|
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
835 |
|
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
836 |
static boolean skip(String name) { |
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
837 |
return skipSet.contains(name); |
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
838 |
} |
39812 | 839 |
} |
840 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
841 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
842 |
* The "primary name" for this option. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
843 |
* This is the name that is used to put values in the {@link Options} table. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
844 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
845 |
public final String primaryName; |
11315 | 846 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
847 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
848 |
* The set of names (primary name and aliases) for this option. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
849 |
* Note that some names may end in a separator, to indicate that an argument must immediately |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
850 |
* follow the separator (and cannot appear in the following argument position. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
851 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
852 |
public final String[] names; |
11315 | 853 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
854 |
/** Documentation key for arguments. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
855 |
protected final String argsNameKey; |
11315 | 856 |
|
857 |
/** Documentation key for description. |
|
858 |
*/ |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
859 |
protected final String descrKey; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
860 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
861 |
/** The kind of this option. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
862 |
private final OptionKind kind; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
863 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
864 |
/** The group for this option. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
865 |
private final OptionGroup group; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
866 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
867 |
/** The kind of argument for this option. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
868 |
private final ArgKind argKind; |
11315 | 869 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
870 |
/** The kind of choices for this option, if any. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
871 |
private final ChoiceKind choiceKind; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
872 |
|
41637 | 873 |
/** The choices for this option, if any. */ |
874 |
private final Set<String> choices; |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
875 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
876 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
877 |
* Looks up the first option matching the given argument in the full set of options. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
878 |
* @param arg the argument to be matches |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
879 |
* @return the first option that matches, or null if none. |
11315 | 880 |
*/ |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
881 |
public static Option lookup(String arg) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
882 |
return lookup(arg, EnumSet.allOf(Option.class)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
883 |
} |
11315 | 884 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
885 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
886 |
* Looks up the first option matching the given argument within a set of options. |
41637 | 887 |
* @param arg the argument to be matched |
888 |
* @param options the set of possible options |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
889 |
* @return the first option that matches, or null if none. |
11315 | 890 |
*/ |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
891 |
public static Option lookup(String arg, Set<Option> options) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
892 |
for (Option option: options) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
893 |
if (option.matches(arg)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
894 |
return option; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
895 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
896 |
return null; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
897 |
} |
11315 | 898 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
899 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
900 |
* Writes the "command line help" for given kind of option to the log. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
901 |
* @param log the log |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
902 |
* @param kind the kind of options to select |
11315 | 903 |
*/ |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
904 |
private static void showHelp(Log log, OptionKind kind) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
905 |
Comparator<Option> comp = new Comparator<Option>() { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
906 |
final Collator collator = Collator.getInstance(Locale.US); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
907 |
{ collator.setStrength(Collator.PRIMARY); } |
11315 | 908 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
909 |
@Override |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
910 |
public int compare(Option o1, Option o2) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
911 |
return collator.compare(o1.primaryName, o2.primaryName); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
912 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
913 |
}; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
914 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
915 |
getJavaCompilerOptions() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
916 |
.stream() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
917 |
.filter(o -> o.kind == kind) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
918 |
.sorted(comp) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
919 |
.forEach(o -> { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
920 |
o.help(log); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
921 |
}); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
922 |
} |
11315 | 923 |
|
924 |
Option(String text, String descrKey, |
|
925 |
OptionKind kind, OptionGroup group) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
926 |
this(text, null, descrKey, kind, group, null, null, ArgKind.NONE); |
39812 | 927 |
} |
928 |
||
11315 | 929 |
Option(String text, String argsNameKey, String descrKey, |
930 |
OptionKind kind, OptionGroup group) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
931 |
this(text, argsNameKey, descrKey, kind, group, null, null, ArgKind.REQUIRED); |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
932 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
933 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
934 |
Option(String text, String argsNameKey, String descrKey, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
935 |
OptionKind kind, OptionGroup group, ArgKind ak) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
936 |
this(text, argsNameKey, descrKey, kind, group, null, null, ak); |
11315 | 937 |
} |
938 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
939 |
Option(String text, String argsNameKey, String descrKey, OptionKind kind, OptionGroup group, |
41637 | 940 |
ChoiceKind choiceKind, Set<String> choices) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
941 |
this(text, argsNameKey, descrKey, kind, group, choiceKind, choices, ArgKind.REQUIRED); |
11315 | 942 |
} |
943 |
||
944 |
Option(String text, String descrKey, |
|
945 |
OptionKind kind, OptionGroup group, |
|
946 |
ChoiceKind choiceKind, String... choices) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
947 |
this(text, null, descrKey, kind, group, choiceKind, |
41637 | 948 |
new LinkedHashSet<>(Arrays.asList(choices)), ArgKind.REQUIRED); |
11315 | 949 |
} |
950 |
||
951 |
private Option(String text, String argsNameKey, String descrKey, |
|
952 |
OptionKind kind, OptionGroup group, |
|
41637 | 953 |
ChoiceKind choiceKind, Set<String> choices, |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
954 |
ArgKind argKind) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
955 |
this.names = text.trim().split("\\s+"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
956 |
Assert.check(names.length >= 1); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
957 |
this.primaryName = names[0]; |
11315 | 958 |
this.argsNameKey = argsNameKey; |
959 |
this.descrKey = descrKey; |
|
960 |
this.kind = kind; |
|
961 |
this.group = group; |
|
962 |
this.choiceKind = choiceKind; |
|
963 |
this.choices = choices; |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
964 |
this.argKind = argKind; |
11315 | 965 |
} |
966 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
967 |
public String getPrimaryName() { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
968 |
return primaryName; |
11315 | 969 |
} |
970 |
||
971 |
public OptionKind getKind() { |
|
972 |
return kind; |
|
973 |
} |
|
974 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
975 |
public ArgKind getArgKind() { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
976 |
return argKind; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
977 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
978 |
|
11315 | 979 |
public boolean hasArg() { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
980 |
return (argKind != ArgKind.NONE); |
11315 | 981 |
} |
982 |
||
983 |
public boolean matches(String option) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
984 |
for (String name: names) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
985 |
if (matches(option, name)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
986 |
return true; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
987 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
988 |
return false; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
989 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
990 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
991 |
private boolean matches(String option, String name) { |
40835
6ab9ed1abc46
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents:
40762
diff
changeset
|
992 |
if (name.startsWith("--") && !HiddenGroup.skip(name)) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
993 |
return option.equals(name) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
994 |
|| hasArg() && option.startsWith(name + "="); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
995 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
996 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
997 |
boolean hasSuffix = (argKind == ArgKind.ADJACENT) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
998 |
|| name.endsWith(":") || name.endsWith("="); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
999 |
|
11315 | 1000 |
if (!hasSuffix) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1001 |
return option.equals(name); |
11315 | 1002 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1003 |
if (!option.startsWith(name)) |
11315 | 1004 |
return false; |
1005 |
||
1006 |
if (choices != null) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1007 |
String arg = option.substring(name.length()); |
11315 | 1008 |
if (choiceKind == ChoiceKind.ONEOF) |
41637 | 1009 |
return choices.contains(arg); |
11315 | 1010 |
else { |
1011 |
for (String a: arg.split(",+")) { |
|
41637 | 1012 |
if (!choices.contains(a)) |
11315 | 1013 |
return false; |
1014 |
} |
|
1015 |
} |
|
1016 |
} |
|
1017 |
||
1018 |
return true; |
|
1019 |
} |
|
1020 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1021 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1022 |
* Handles an option. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1023 |
* If an argument for the option is required, depending on spec of the option, it will be found |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1024 |
* as part of the current arg (following ':' or '=') or in the following argument. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1025 |
* This is the recommended way to handle an option directly, instead of calling the underlying |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1026 |
* {@link #process process} methods. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1027 |
* @param helper a helper to provide access to the environment |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1028 |
* @param arg the arg string that identified this option |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1029 |
* @param rest the remaining strings to be analysed |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1030 |
* @return true if the operation was successful, and false otherwise |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1031 |
* @implNote The return value is the opposite of that used by {@link #process}. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1032 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1033 |
public boolean handleOption(OptionHelper helper, String arg, Iterator<String> rest) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1034 |
if (hasArg()) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1035 |
String option; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1036 |
String operand; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1037 |
int sep = findSeparator(arg); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1038 |
if (getArgKind() == Option.ArgKind.ADJACENT) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1039 |
option = primaryName; // aliases not supported |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1040 |
operand = arg.substring(primaryName.length()); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1041 |
} else if (sep > 0) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1042 |
option = arg.substring(0, sep); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1043 |
operand = arg.substring(sep + 1); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1044 |
} else { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1045 |
if (!rest.hasNext()) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1046 |
helper.error("err.req.arg", arg); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1047 |
return false; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1048 |
} |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1049 |
option = arg; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1050 |
operand = rest.next(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1051 |
} |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1052 |
return !process(helper, option, operand); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1053 |
} else { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1054 |
return !process(helper, arg); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1055 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1056 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1057 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1058 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1059 |
* Processes an option that either does not need an argument, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1060 |
* or which contains an argument within it, following a separator. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1061 |
* @param helper a helper to provide access to the environment |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1062 |
* @param option the option to be processed |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1063 |
* @return true if an error occurred |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1064 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1065 |
public boolean process(OptionHelper helper, String option) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1066 |
if (argKind == ArgKind.NONE) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1067 |
return process(helper, primaryName, option); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1068 |
} else { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1069 |
int sep = findSeparator(option); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1070 |
return process(helper, primaryName, option.substring(sep + 1)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1071 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1072 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1073 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1074 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1075 |
* Processes an option by updating the environment via a helper object. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1076 |
* @param helper a helper to provide access to the environment |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1077 |
* @param option the option to be processed |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1078 |
* @param arg the value to associate with the option, or a default value |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1079 |
* to be used if the option does not otherwise take an argument. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1080 |
* @return true if an error occurred |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1081 |
*/ |
11315 | 1082 |
public boolean process(OptionHelper helper, String option, String arg) { |
1083 |
if (choices != null) { |
|
1084 |
if (choiceKind == ChoiceKind.ONEOF) { |
|
1085 |
// some clients like to see just one of option+choice set |
|
41637 | 1086 |
for (String s : choices) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1087 |
helper.remove(primaryName + s); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1088 |
String opt = primaryName + arg; |
11315 | 1089 |
helper.put(opt, opt); |
1090 |
// some clients like to see option (without trailing ":") |
|
1091 |
// set to arg |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1092 |
String nm = primaryName.substring(0, primaryName.length() - 1); |
11315 | 1093 |
helper.put(nm, arg); |
1094 |
} else { |
|
1095 |
// set option+word for each word in arg |
|
1096 |
for (String a: arg.split(",+")) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1097 |
String opt = primaryName + a; |
11315 | 1098 |
helper.put(opt, opt); |
1099 |
} |
|
1100 |
} |
|
1101 |
} |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1102 |
helper.put(primaryName, arg); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
24298
diff
changeset
|
1103 |
if (group == OptionGroup.FILEMANAGER) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
24298
diff
changeset
|
1104 |
helper.handleFileManagerOption(this, arg); |
11315 | 1105 |
return false; |
1106 |
} |
|
1107 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1108 |
/** |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1109 |
* Returns a pattern to analyze the value for an option. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1110 |
* @return the pattern |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1111 |
* @throws UnsupportedOperationException if an option does not provide a pattern. |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1112 |
*/ |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1113 |
public Pattern getPattern() { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1114 |
throw new UnsupportedOperationException(); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1115 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1116 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41637
diff
changeset
|
1117 |
/** |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1118 |
* Scans a word to find the first separator character, either colon or equals. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1119 |
* @param word the word to be scanned |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1120 |
* @return the position of the first':' or '=' character in the word, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1121 |
* or -1 if none found |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1122 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1123 |
private static int findSeparator(String word) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1124 |
for (int i = 0; i < word.length(); i++) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1125 |
switch (word.charAt(i)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1126 |
case ':': case '=': |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1127 |
return i; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1128 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1129 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1130 |
return -1; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1131 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1132 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1133 |
/** The indent for the option synopsis. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1134 |
private static final String SMALL_INDENT = " "; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1135 |
/** The automatic indent for the description. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1136 |
private static final String LARGE_INDENT = " "; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1137 |
/** The space allowed for the synopsis, if the description is to be shown on the same line. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1138 |
private static final int DEFAULT_SYNOPSIS_WIDTH = 28; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1139 |
/** The nominal maximum line length, when seeing if text will fit on a line. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1140 |
private static final int DEFAULT_MAX_LINE_LENGTH = 80; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1141 |
/** The format for a single-line help entry. */ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1142 |
private static final String COMPACT_FORMAT = SMALL_INDENT + "%-" + DEFAULT_SYNOPSIS_WIDTH + "s %s"; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1143 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1144 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1145 |
* Writes help text for this option to the log. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1146 |
* @param log the log |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1147 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1148 |
protected void help(Log log) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1149 |
help(log, log.localize(PrefixKind.JAVAC, descrKey)); |
11315 | 1150 |
} |
1151 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1152 |
protected void help(Log log, String descr) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1153 |
String synopses = Arrays.stream(names) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1154 |
.map(s -> helpSynopsis(s, log)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1155 |
.collect(Collectors.joining(", ")); |
11315 | 1156 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1157 |
// If option synopses and description fit on a single line of reasonable length, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1158 |
// display using COMPACT_FORMAT |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1159 |
if (synopses.length() < DEFAULT_SYNOPSIS_WIDTH |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1160 |
&& !descr.contains("\n") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1161 |
&& (SMALL_INDENT.length() + DEFAULT_SYNOPSIS_WIDTH + 1 + descr.length() <= DEFAULT_MAX_LINE_LENGTH)) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1162 |
log.printRawLines(WriterKind.STDOUT, String.format(COMPACT_FORMAT, synopses, descr)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1163 |
return; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1164 |
} |
11315 | 1165 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1166 |
// If option synopses fit on a single line of reasonable length, show that; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1167 |
// otherwise, show 1 per line |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1168 |
if (synopses.length() <= DEFAULT_MAX_LINE_LENGTH) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1169 |
log.printRawLines(WriterKind.STDOUT, SMALL_INDENT + synopses); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1170 |
} else { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1171 |
for (String name: names) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1172 |
log.printRawLines(WriterKind.STDOUT, SMALL_INDENT + helpSynopsis(name, log)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1173 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1174 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1175 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1176 |
// Finally, show the description |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1177 |
log.printRawLines(WriterKind.STDOUT, LARGE_INDENT + descr.replace("\n", "\n" + LARGE_INDENT)); |
11315 | 1178 |
} |
1179 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1180 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1181 |
* Composes the initial synopsis of one of the forms for this option. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1182 |
* @param name the name of this form of the option |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1183 |
* @param log the log used to localize the description of the arguments |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1184 |
* @return the synopsis |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1185 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1186 |
private String helpSynopsis(String name, Log log) { |
11315 | 1187 |
StringBuilder sb = new StringBuilder(); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1188 |
sb.append(name); |
11315 | 1189 |
if (argsNameKey == null) { |
1190 |
if (choices != null) { |
|
1191 |
String sep = "{"; |
|
41637 | 1192 |
for (String choice : choices) { |
1193 |
sb.append(sep); |
|
1194 |
sb.append(choices); |
|
1195 |
sep = ","; |
|
11315 | 1196 |
} |
1197 |
sb.append("}"); |
|
1198 |
} |
|
1199 |
} else { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1200 |
if (!name.matches(".*[=:]$") && argKind != ArgKind.ADJACENT) |
11315 | 1201 |
sb.append(" "); |
1202 |
sb.append(log.localize(PrefixKind.JAVAC, argsNameKey)); |
|
1203 |
} |
|
1204 |
||
1205 |
return sb.toString(); |
|
1206 |
} |
|
1207 |
||
1208 |
// For -XpkgInfo:value |
|
1209 |
public enum PkgInfo { |
|
19670
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1210 |
/** |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1211 |
* Always generate package-info.class for every package-info.java file. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1212 |
* The file may be empty if there annotations with a RetentionPolicy |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1213 |
* of CLASS or RUNTIME. This option may be useful in conjunction with |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1214 |
* build systems (such as Ant) that expect javac to generate at least |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1215 |
* one .class file for every .java file. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1216 |
*/ |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1217 |
ALWAYS, |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1218 |
/** |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1219 |
* Generate a package-info.class file if package-info.java contains |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1220 |
* annotations. The file may be empty if all the annotations have |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1221 |
* a RetentionPolicy of SOURCE. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1222 |
* This value is just for backwards compatibility with earlier behavior. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1223 |
* Either of the other two values are to be preferred to using this one. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1224 |
*/ |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1225 |
LEGACY, |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1226 |
/** |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1227 |
* Generate a package-info.class file if and only if there are annotations |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1228 |
* in package-info.java to be written into it. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1229 |
*/ |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1230 |
NONEMPTY; |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
1231 |
|
11315 | 1232 |
public static PkgInfo get(Options options) { |
1233 |
String v = options.get(XPKGINFO); |
|
1234 |
return (v == null |
|
1235 |
? PkgInfo.LEGACY |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19670
diff
changeset
|
1236 |
: PkgInfo.valueOf(StringUtils.toUpperCase(v))); |
11315 | 1237 |
} |
1238 |
} |
|
1239 |
||
41637 | 1240 |
private static Set<String> getXLintChoices() { |
1241 |
Set<String> choices = new LinkedHashSet<>(); |
|
1242 |
choices.add("all"); |
|
1243 |
for (Lint.LintCategory c : Lint.LintCategory.values()) { |
|
1244 |
choices.add(c.option); |
|
1245 |
choices.add("-" + c.option); |
|
1246 |
} |
|
1247 |
choices.add("none"); |
|
11315 | 1248 |
return choices; |
1249 |
} |
|
1250 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1251 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1252 |
* Returns the set of options supported by the command line tool. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1253 |
* @return the set of options. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1254 |
*/ |
11315 | 1255 |
static Set<Option> getJavaCompilerOptions() { |
1256 |
return EnumSet.allOf(Option.class); |
|
1257 |
} |
|
1258 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1259 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1260 |
* Returns the set of options supported by the built-in file manager. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1261 |
* @return the set of options. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1262 |
*/ |
11315 | 1263 |
public static Set<Option> getJavacFileManagerOptions() { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1264 |
return getOptions(FILEMANAGER); |
11315 | 1265 |
} |
1266 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1267 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1268 |
* Returns the set of options supported by this implementation of |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1269 |
* the JavaCompiler API, via {@link JavaCompiler#getTask}. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1270 |
* @return the set of options. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1271 |
*/ |
11315 | 1272 |
public static Set<Option> getJavacToolOptions() { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1273 |
return getOptions(BASIC); |
11315 | 1274 |
} |
1275 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1276 |
private static Set<Option> getOptions(OptionGroup group) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1277 |
return Arrays.stream(Option.values()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1278 |
.filter(o -> o.group == group) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
1279 |
.collect(Collectors.toCollection(() -> EnumSet.noneOf(Option.class))); |
11315 | 1280 |
} |
1281 |
||
1282 |
} |