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 sun.tools.jar;
27
28 import java.io.File;
29 import java.io.PrintStream;
30 import java.lang.module.ModuleFinder;
31 import java.lang.module.ModuleDescriptor.Version;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.util.regex.Pattern;
35 import java.util.regex.PatternSyntaxException;
36
37 /**
38 * Parser for GNU Style Options.
39 */
40 class GNUStyleOptions {
41
42 static class BadArgs extends Exception {
43 static final long serialVersionUID = 0L;
44
45 boolean showUsage;
46
47 BadArgs(String key, String arg) { super(Main.formatMsg(key, arg)); }
48 BadArgs(String key) { super(Main.getMsg(key)); }
49
272 if (!option.argIsOptional &&
273 (param == null || param.isEmpty() || param.charAt(0) == '-')) {
274 throw new BadArgs("error.missing.arg", name).showUsage(true);
275 }
276 }
277 option.process(jartool, name, param);
278 }
279
280 return count;
281 }
282
283 private static Option getOption(String name) throws BadArgs {
284 for (Option o : recognizedOptions) {
285 if (o.matches(name)) {
286 return o;
287 }
288 }
289 throw new BadArgs("error.unrecognized.option", name).showUsage(true);
290 }
291
292 static void printHelp(PrintStream out) {
293 out.format("%s%n", Main.getMsg("main.help.preopt"));
294 for (OptionType type : OptionType.values()) {
295 boolean typeHeadingWritten = false;
296
297 for (Option o : recognizedOptions) {
298 if (!o.type.equals(type))
299 continue;
300 String name = o.aliases[0].substring(1); // there must always be at least one name
301 name = name.charAt(0) == '-' ? name.substring(1) : name;
302 if (o.isHidden() || name.equals("h")) {
303 continue;
304 }
305 if (!typeHeadingWritten) {
306 out.format("%n%s%n", Main.getMsg("main.help.opt." + type.name));
307 typeHeadingWritten = true;
308 }
309 out.format("%s%n", Main.getMsg("main.help.opt." + type.name + "." + name));
310 }
311 }
312 out.format("%n%s%n%n", Main.getMsg("main.help.postopt"));
313 }
314
315 static void printCompatHelp(PrintStream out) {
316 out.format("%s%n", Main.getMsg("usage.compat"));
317 }
318
319 static void printUsageSummary(PrintStream out) {
320 out.format("%s%n", Main.getMsg("main.usage.summary"));
321 out.format("%s%n", Main.getMsg("main.usage.summary.try"));
322 }
323
324 static void printVersion(PrintStream out) {
325 out.format("%s %s%n", "jar", System.getProperty("java.version"));
326 }
327 }
|
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 sun.tools.jar;
27
28 import java.io.File;
29 import java.io.PrintStream;
30 import java.io.PrintWriter;
31 import java.lang.module.ModuleFinder;
32 import java.lang.module.ModuleDescriptor.Version;
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.regex.Pattern;
36 import java.util.regex.PatternSyntaxException;
37
38 /**
39 * Parser for GNU Style Options.
40 */
41 class GNUStyleOptions {
42
43 static class BadArgs extends Exception {
44 static final long serialVersionUID = 0L;
45
46 boolean showUsage;
47
48 BadArgs(String key, String arg) { super(Main.formatMsg(key, arg)); }
49 BadArgs(String key) { super(Main.getMsg(key)); }
50
273 if (!option.argIsOptional &&
274 (param == null || param.isEmpty() || param.charAt(0) == '-')) {
275 throw new BadArgs("error.missing.arg", name).showUsage(true);
276 }
277 }
278 option.process(jartool, name, param);
279 }
280
281 return count;
282 }
283
284 private static Option getOption(String name) throws BadArgs {
285 for (Option o : recognizedOptions) {
286 if (o.matches(name)) {
287 return o;
288 }
289 }
290 throw new BadArgs("error.unrecognized.option", name).showUsage(true);
291 }
292
293 static void printHelp(PrintWriter out) {
294 out.format("%s%n", Main.getMsg("main.help.preopt"));
295 for (OptionType type : OptionType.values()) {
296 boolean typeHeadingWritten = false;
297
298 for (Option o : recognizedOptions) {
299 if (!o.type.equals(type))
300 continue;
301 String name = o.aliases[0].substring(1); // there must always be at least one name
302 name = name.charAt(0) == '-' ? name.substring(1) : name;
303 if (o.isHidden() || name.equals("h")) {
304 continue;
305 }
306 if (!typeHeadingWritten) {
307 out.format("%n%s%n", Main.getMsg("main.help.opt." + type.name));
308 typeHeadingWritten = true;
309 }
310 out.format("%s%n", Main.getMsg("main.help.opt." + type.name + "." + name));
311 }
312 }
313 out.format("%n%s%n%n", Main.getMsg("main.help.postopt"));
314 }
315
316 static void printCompatHelp(PrintWriter out) {
317 out.format("%s%n", Main.getMsg("usage.compat"));
318 }
319
320 static void printUsageSummary(PrintWriter out) {
321 out.format("%s%n", Main.getMsg("main.usage.summary"));
322 out.format("%s%n", Main.getMsg("main.usage.summary.try"));
323 }
324
325 static void printVersion(PrintWriter out) {
326 out.format("%s %s%n", "jar", System.getProperty("java.version"));
327 }
328 }
|