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