Arguments.java revision 2362
1163N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
1163N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1163N/A *
1163N/A * This code is free software; you can redistribute it and/or modify it
1163N/A * under the terms of the GNU General Public License version 2 only, as
1163N/A * published by the Free Software Foundation. Oracle designates this
1163N/A * particular file as subject to the "Classpath" exception as provided
1163N/A * by Oracle in the LICENSE file that accompanied this code.
1163N/A *
1163N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1163N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1163N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1163N/A * version 2 for more details (a copy is included in the LICENSE file that
1163N/A * accompanied this code).
1163N/A *
1163N/A * You should have received a copy of the GNU General Public License version
1163N/A * 2 along with this work; if not, write to the Free Software Foundation,
2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1163N/A * or visit www.oracle.com if you need additional information or have any
1163N/A * questions.
1163N/A */
1163N/A
1163N/Apackage sun.tools.jps;
1163N/A
1163N/Aimport java.io.*;
1163N/Aimport java.net.*;
1163N/Aimport sun.jvmstat.monitor.*;
1163N/A
1163N/A/**
1163N/A * Class for processing command line arguments and providing method
1163N/A * level access to the command line arguments.
1163N/A *
1163N/A * @author Brian Doherty
1163N/A * @since 1.5
1163N/A */
1163N/Apublic class Arguments {
1163N/A
1163N/A private static final boolean debug = Boolean.getBoolean("jps.debug");
1163N/A private static final boolean printStackTrace = Boolean.getBoolean(
1163N/A "jps.printStackTrace");
1163N/A
1163N/A private boolean help;
3946N/A private boolean quiet;
1163N/A private boolean longPaths;
1163N/A private boolean vmArgs;
1163N/A private boolean vmFlags;
1163N/A private boolean mainArgs;
1163N/A private String hostname;
1163N/A private HostIdentifier hostId;
1163N/A
1163N/A public static void printUsage(PrintStream ps) {
1163N/A ps.println("usage: jps [-help]");
1163N/A ps.println(" jps [-q] [-mlvV] [<hostid>]");
1163N/A ps.println();
1163N/A ps.println("Definitions:");
1163N/A ps.println(" <hostid>: <hostname>[:<port>]");
1163N/A }
1163N/A
1163N/A public Arguments(String[] args) throws IllegalArgumentException {
1163N/A int argc = 0;
1163N/A
1163N/A if (args.length == 1) {
1163N/A if ((args[0].compareTo("-?") == 0)
1163N/A || (args[0].compareTo("-help")== 0)) {
1163N/A help = true;
1163N/A return;
1163N/A }
1163N/A }
1163N/A
1163N/A for (argc = 0; (argc < args.length) && (args[argc].startsWith("-"));
1163N/A argc++) {
1163N/A String arg = args[argc];
1163N/A
1163N/A if (arg.compareTo("-q") == 0) {
1163N/A quiet = true;
1163N/A } else if (arg.startsWith("-")) {
1163N/A for (int j = 1; j < arg.length(); j++) {
1163N/A switch (arg.charAt(j)) {
1163N/A case 'm':
1163N/A mainArgs = true;
1163N/A break;
1163N/A case 'l':
1163N/A longPaths = true;
1163N/A break;
1163N/A case 'v':
1163N/A vmArgs = true;
1163N/A break;
1163N/A case 'V':
1163N/A vmFlags = true;
1163N/A break;
1163N/A default:
1163N/A throw new IllegalArgumentException("illegal argument: "
1163N/A + args[argc]);
1163N/A }
1163N/A }
1163N/A } else {
1163N/A throw new IllegalArgumentException("illegal argument: "
1163N/A + args[argc]);
1163N/A }
1163N/A }
1163N/A
switch (args.length - argc) {
case 0:
hostname = null;
break;
case 1:
hostname = args[args.length - 1];
break;
default:
throw new IllegalArgumentException("invalid argument count");
}
try {
hostId = new HostIdentifier(hostname);
} catch (URISyntaxException e) {
IllegalArgumentException iae =
new IllegalArgumentException("Malformed Host Identifier: "
+ hostname);
iae.initCause(e);
throw iae;
}
}
public boolean isDebug() {
return debug;
}
public boolean printStackTrace() {
return printStackTrace;
}
public boolean isHelp() {
return help;
}
public boolean isQuiet() {
return quiet;
}
public boolean showLongPaths() {
return longPaths;
}
public boolean showVmArgs() {
return vmArgs;
}
public boolean showVmFlags() {
return vmFlags;
}
public boolean showMainArgs() {
return mainArgs;
}
public String hostname() {
return hostname;
}
public HostIdentifier hostId() {
return hostId;
}
}