This commit is contained in:
Max Ockner 2016-04-11 22:14:14 +02:00
commit 46e3ccd80c
3 changed files with 57 additions and 27 deletions

View File

@ -55,11 +55,11 @@ public class SAGetopt {
private void extractOptarg(String opt) {
// Argument expected
if (_optind > _argv.length) {
throw new RuntimeException("Not enough arguments for '" + opt + "'");
throw new SAGetoptException("Not enough arguments for '" + opt + "'");
}
if (! _argv[_optind].isEmpty() && _argv[_optind].charAt(0) == '-') {
throw new RuntimeException("Argument is expected for '" + opt + "'");
throw new SAGetoptException("Argument is expected for '" + opt + "'");
}
_optarg = _argv[_optind];
@ -72,7 +72,7 @@ public class SAGetopt {
if (los.contains(ca[0])) {
if (ca.length > 1) {
throw new RuntimeException("Argument is not expected for '" + ca[0] + "'");
throw new SAGetoptException("Argument is not expected for '" + ca[0] + "'");
}
return carg;
}
@ -87,14 +87,14 @@ public class SAGetopt {
try {
extractOptarg(ca[0]);
} catch (ArrayIndexOutOfBoundsException e) {
throw new RuntimeException("Argument is expected for '" + ca[0] + "'");
throw new SAGetoptException("Argument is expected for '" + ca[0] + "'");
}
}
return ca[0];
}
throw new RuntimeException("Invalid option '" + ca[0] + "'");
throw new SAGetoptException("Invalid option '" + ca[0] + "'");
}
public String next(String optStr, String[] longOptStr) {
@ -148,7 +148,7 @@ public class SAGetopt {
int chIndex = optStr.indexOf(ch);
if (chIndex == -1) {
throw new RuntimeException("Invalid option '" + ch + "'");
throw new SAGetoptException("Invalid option '" + ch + "'");
}
if (_optopt >= carg.length()) {

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2016, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
package sun.jvm.hotspot;
public class SAGetoptException extends IllegalArgumentException {
public SAGetoptException(String message) {
super(message);
}
}

View File

@ -111,34 +111,31 @@ public class SALauncher {
return launcherHelp();
}
private static void buildAttachArgs(ArrayList<String> newArgs,
String pid, String exe, String core) {
if ((pid == null) && (exe == null)) {
throw new IllegalArgumentException(
"You have to set --pid or --exe.");
private static void buildAttachArgs(ArrayList<String> newArgs, String pid,
String exe, String core, boolean allowEmpty) {
if (!allowEmpty && (pid == null) && (exe == null)) {
throw new SAGetoptException("You have to set --pid or --exe.");
}
if (pid != null) { // Attach to live process
if (exe != null) {
throw new IllegalArgumentException(
"Unnecessary argument: --exe");
throw new SAGetoptException("Unnecessary argument: --exe");
} else if (core != null) {
throw new IllegalArgumentException(
"Unnecessary argument: --core");
throw new SAGetoptException("Unnecessary argument: --core");
} else if (!pid.matches("^\\d+$")) {
throw new IllegalArgumentException("Invalid pid: " + pid);
throw new SAGetoptException("Invalid pid: " + pid);
}
newArgs.add(pid);
} else {
} else if (exe != null) {
if (exe.length() == 0) {
throw new IllegalArgumentException("You have to set --exe.");
throw new SAGetoptException("You have to set --exe.");
}
newArgs.add(exe);
if ((core == null) || (core.length() == 0)) {
throw new IllegalArgumentException("You have to set --core.");
throw new SAGetoptException("You have to set --core.");
}
newArgs.add(core);
@ -170,7 +167,7 @@ public class SALauncher {
}
}
buildAttachArgs(newArgs, pid, exe, core);
buildAttachArgs(newArgs, pid, exe, core, true);
CLHSDB.main(newArgs.toArray(new String[newArgs.size()]));
}
@ -199,7 +196,7 @@ public class SALauncher {
}
}
buildAttachArgs(newArgs, pid, exe, core);
buildAttachArgs(newArgs, pid, exe, core, true);
HSDB.main(newArgs.toArray(new String[newArgs.size()]));
}
@ -237,7 +234,7 @@ public class SALauncher {
}
}
buildAttachArgs(newArgs, pid, exe, core);
buildAttachArgs(newArgs, pid, exe, core, false);
JStack.main(newArgs.toArray(new String[newArgs.size()]));
}
@ -287,7 +284,7 @@ public class SALauncher {
}
}
buildAttachArgs(newArgs, pid, exe, core);
buildAttachArgs(newArgs, pid, exe, core, false);
JMap.main(newArgs.toArray(new String[newArgs.size()]));
}
@ -325,7 +322,7 @@ public class SALauncher {
}
}
buildAttachArgs(newArgs, pid, exe, core);
buildAttachArgs(newArgs, pid, exe, core, false);
JInfo.main(newArgs.toArray(new String[newArgs.size()]));
}
@ -358,7 +355,7 @@ public class SALauncher {
}
}
buildAttachArgs(newArgs, pid, exe, core);
buildAttachArgs(newArgs, pid, exe, core, false);
JSnap.main(newArgs.toArray(new String[newArgs.size()]));
}
@ -416,8 +413,8 @@ public class SALauncher {
return;
}
throw new IllegalArgumentException("Unknown tool: " + args[0]);
} catch (Exception e) {
throw new SAGetoptException("Unknown tool: " + args[0]);
} catch (SAGetoptException e) {
System.err.println(e.getMessage());
toolHelp(args[0]);
}