< prev index next >
src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -33,12 +33,16 @@
import java.nio.file.PathMatcher;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.MissingResourceException;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
import jdk.internal.jimage.BasicImageReader;
import jdk.internal.jimage.ImageHeader;
import jdk.internal.jimage.ImageLocation;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.tree.ClassNode;
@@ -97,11 +101,11 @@
log = out;
TASK_HELPER.setLog(log);
}
static class OptionsValues {
- Task task = Task.LIST;
+ Task task = null;
String directory = ".";
String include = "";
boolean fullVersion;
boolean help;
boolean verbose;
@@ -170,28 +174,35 @@
log.println(TASK_HELPER.getMessage("main.usage.summary", PROGNAME));
return EXIT_ABNORMAL;
}
try {
- List<String> unhandled = OPTION_HELPER.handleOptions(this, args);
-
- if(!unhandled.isEmpty()) {
+ String command;
+ String[] remaining = args;
try {
- options.task = Enum.valueOf(Task.class, unhandled.get(0).toUpperCase());
+ command = args[0];
+ options.task = Enum.valueOf(Task.class, args[0].toUpperCase(Locale.ENGLISH));
+ remaining = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length)
+ : new String[0];
} catch (IllegalArgumentException ex) {
- throw TASK_HELPER.newBadArgs("err.not.a.task", unhandled.get(0));
+ command = null;
+ options.task = null;
}
- for(int i = 1; i < unhandled.size(); i++) {
- options.jimages.add(new File(unhandled.get(i)));
+ // process arguments
+ List<String> unhandled = OPTION_HELPER.handleOptions(this, remaining);
+ for (String f : unhandled) {
+ options.jimages.add(new File(f));
}
- } else if (!options.help && !options.version && !options.fullVersion) {
- throw TASK_HELPER.newBadArgs("err.invalid.task", "<unspecified>");
+
+ if (options.task == null && !options.help && !options.version && !options.fullVersion) {
+ throw TASK_HELPER.newBadArgs("err.not.a.task",
+ command != null ? command : "<unspecified>");
}
if (options.help) {
- if (unhandled.isEmpty()) {
+ if (options.task == null) {
log.println(TASK_HELPER.getMessage("main.usage", PROGNAME));
Arrays.asList(RECOGNIZED_OPTIONS).stream()
.filter(option -> !option.isHidden())
.sorted()
.forEach(option -> {
@@ -201,19 +212,23 @@
} else {
try {
log.println(TASK_HELPER.getMessage("main.usage." +
options.task.toString().toLowerCase()));
} catch (MissingResourceException ex) {
- throw TASK_HELPER.newBadArgs("err.not.a.task", unhandled.get(0));
+ throw TASK_HELPER.newBadArgs("err.not.a.task", command);
}
}
return EXIT_OK;
}
if (options.version || options.fullVersion) {
- TASK_HELPER.showVersion(options.fullVersion);
+ if (options.task == null && !unhandled.isEmpty()) {
+ throw TASK_HELPER.newBadArgs("err.not.a.task",
+ Stream.of(args).collect(Collectors.joining(" ")));
+ }
+ TASK_HELPER.showVersion(options.fullVersion);
if (unhandled.isEmpty()) {
return EXIT_OK;
}
}
@@ -433,11 +448,11 @@
break;
case VERIFY:
iterate(this::listTitle, null, this::verify);
break;
default:
- throw TASK_HELPER.newBadArgs("err.invalid.task",
+ throw TASK_HELPER.newBadArgs("err.not.a.task",
options.task.name()).showUsage(true);
}
return true;
}
}
< prev index next >