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