Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/jps/Arguments.java
38918 views
/*1* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jps;2627import java.io.*;28import java.net.*;29import sun.jvmstat.monitor.*;3031/**32* Class for processing command line arguments and providing method33* level access to the command line arguments.34*35* @author Brian Doherty36* @since 1.537*/38public class Arguments {3940private static final boolean debug = Boolean.getBoolean("jps.debug");41private static final boolean printStackTrace = Boolean.getBoolean(42"jps.printStackTrace");4344private boolean help;45private boolean quiet;46private boolean longPaths;47private boolean vmArgs;48private boolean vmFlags;49private boolean mainArgs;50private String hostname;51private HostIdentifier hostId;5253public static void printUsage(PrintStream ps) {54ps.println("usage: jps [-help]");55ps.println(" jps [-q] [-mlvV] [<hostid>]");56ps.println();57ps.println("Definitions:");58ps.println(" <hostid>: <hostname>[:<port>]");59}6061public Arguments(String[] args) throws IllegalArgumentException {62int argc = 0;6364if (args.length == 1) {65if ((args[0].compareTo("-?") == 0)66|| (args[0].compareTo("-help")== 0)) {67help = true;68return;69}70}7172for (argc = 0; (argc < args.length) && (args[argc].startsWith("-"));73argc++) {74String arg = args[argc];7576if (arg.compareTo("-q") == 0) {77quiet = true;78} else if (arg.startsWith("-")) {79for (int j = 1; j < arg.length(); j++) {80switch (arg.charAt(j)) {81case 'm':82mainArgs = true;83break;84case 'l':85longPaths = true;86break;87case 'v':88vmArgs = true;89break;90case 'V':91vmFlags = true;92break;93default:94throw new IllegalArgumentException("illegal argument: "95+ args[argc]);96}97}98} else {99throw new IllegalArgumentException("illegal argument: "100+ args[argc]);101}102}103104switch (args.length - argc) {105case 0:106hostname = null;107break;108case 1:109hostname = args[args.length - 1];110break;111default:112throw new IllegalArgumentException("invalid argument count");113}114115try {116hostId = new HostIdentifier(hostname);117} catch (URISyntaxException e) {118IllegalArgumentException iae =119new IllegalArgumentException("Malformed Host Identifier: "120+ hostname);121iae.initCause(e);122throw iae;123}124}125126public boolean isDebug() {127return debug;128}129130public boolean printStackTrace() {131return printStackTrace;132}133134public boolean isHelp() {135return help;136}137138public boolean isQuiet() {139return quiet;140}141142public boolean showLongPaths() {143return longPaths;144}145146public boolean showVmArgs() {147return vmArgs;148}149150public boolean showVmFlags() {151return vmFlags;152}153154public boolean showMainArgs() {155return mainArgs;156}157158public String hostname() {159return hostname;160}161162public HostIdentifier hostId() {163return hostId;164}165}166167168