1 /*
2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
35 *
36 * @author Brian Doherty
37 * @since 1.5
38 */
39 public class Arguments {
40
41 private static final boolean debug = Boolean.getBoolean("jps.debug");
42 private static final boolean printStackTrace = Boolean.getBoolean(
43 "jps.printStackTrace");
44
45 private boolean help;
46 private boolean quiet;
47 private boolean longPaths;
48 private boolean vmArgs;
49 private boolean vmFlags;
50 private boolean mainArgs;
51 private String hostname;
52 private HostIdentifier hostId;
53
54 public static void printUsage(PrintStream ps) {
55 ps.println("usage: jps [-help]");
56 ps.println(" jps [-q] [-mlvV] [<hostid>]");
57 ps.println();
58 ps.println("Definitions:");
59 ps.println(" <hostid>: <hostname>[:<port>]");
60 }
61
62 public Arguments(String[] args) throws IllegalArgumentException {
63 int argc = 0;
64
65 if (args.length == 1) {
66 if ((args[0].compareTo("-?") == 0)
67 || (args[0].compareTo("-help")== 0)) {
68 help = true;
69 return;
70 }
71 }
72
73 for (argc = 0; (argc < args.length) && (args[argc].startsWith("-"));
74 argc++) {
75 String arg = args[argc];
76
77 if (arg.compareTo("-q") == 0) {
78 quiet = true;
79 } else if (arg.startsWith("-")) {
80 for (int j = 1; j < arg.length(); j++) {
81 switch (arg.charAt(j)) {
82 case 'm':
83 mainArgs = true;
84 break;
85 case 'l':
86 longPaths = true;
|
1 /*
2 * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
35 *
36 * @author Brian Doherty
37 * @since 1.5
38 */
39 public class Arguments {
40
41 private static final boolean debug = Boolean.getBoolean("jps.debug");
42 private static final boolean printStackTrace = Boolean.getBoolean(
43 "jps.printStackTrace");
44
45 private boolean help;
46 private boolean quiet;
47 private boolean longPaths;
48 private boolean vmArgs;
49 private boolean vmFlags;
50 private boolean mainArgs;
51 private String hostname;
52 private HostIdentifier hostId;
53
54 public static void printUsage(PrintStream ps) {
55 ps.println("usage: jps [--help]");
56 ps.println(" jps [-q] [-mlvV] [<hostid>]");
57 ps.println();
58 ps.println("Definitions:");
59 ps.println(" <hostid>: <hostname>[:<port>]");
60 ps.println(" -? -h --help -help: Print this help message and exit.");
61 }
62
63 public Arguments(String[] args) throws IllegalArgumentException {
64 int argc = 0;
65
66 if (args.length == 1) {
67 if ((args[0].compareTo("-?") == 0)
68 || (args[0].compareTo("-h")== 0)
69 || (args[0].compareTo("--help")== 0)
70 // -help: legacy.
71 || (args[0].compareTo("-help")== 0)) {
72 help = true;
73 return;
74 }
75 }
76
77 for (argc = 0; (argc < args.length) && (args[argc].startsWith("-"));
78 argc++) {
79 String arg = args[argc];
80
81 if (arg.compareTo("-q") == 0) {
82 quiet = true;
83 } else if (arg.startsWith("-")) {
84 for (int j = 1; j < arg.length(); j++) {
85 switch (arg.charAt(j)) {
86 case 'm':
87 mainArgs = true;
88 break;
89 case 'l':
90 longPaths = true;
|