< prev index next >

src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java

Print this page
rev 47855 : 8189102: All tools should support -?, -h and --help
   1 /*
   2  * Copyright (c) 2006, 2014, 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


  46         if (args.length == 0) {
  47             usage(1); // no arguments
  48         }
  49         checkForUnsupportedOptions(args);
  50 
  51         boolean doFlag = false;
  52         boolean doFlags = false;
  53         boolean doSysprops = false;
  54         int flag = -1;
  55 
  56         // Parse the options (arguments starting with "-" )
  57         int optionCount = 0;
  58         while (optionCount < args.length) {
  59             String arg = args[optionCount];
  60             if (!arg.startsWith("-")) {
  61                 break;
  62             }
  63 
  64             optionCount++;
  65 
  66             if (arg.equals("-help") || arg.equals("-h")) {

  67                 usage(0);
  68             }
  69 
  70             if (arg.equals("-flag")) {
  71                 doFlag = true;
  72                 // Consume the flag
  73                 if (optionCount < args.length) {
  74                     flag = optionCount++;
  75                     break;
  76                 }
  77                 usage(1);
  78             }
  79 
  80             if (arg.equals("-flags")) {
  81                 doFlags = true;
  82                 break;
  83             }
  84 
  85             if (arg.equals("-sysprops")) {
  86                 doSysprops = true;


 238 
 239     private static void SAOptionError(String msg) {
 240         System.err.println("Error: " + msg);
 241         System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jinfo instead");
 242         System.exit(1);
 243     }
 244 
 245      // print usage message
 246     private static void usage(int exit) {
 247         System.err.println("Usage:");
 248         System.err.println("    jinfo <option> <pid>");
 249         System.err.println("       (to connect to a running process)");
 250         System.err.println("");
 251         System.err.println("where <option> is one of:");
 252         System.err.println("    -flag <name>         to print the value of the named VM flag");
 253         System.err.println("    -flag [+|-]<name>    to enable or disable the named VM flag");
 254         System.err.println("    -flag <name>=<value> to set the named VM flag to the given value");
 255         System.err.println("    -flags               to print VM flags");
 256         System.err.println("    -sysprops            to print Java system properties");
 257         System.err.println("    <no option>          to print both VM flags and system properties");
 258         System.err.println("    -h | -help           to print this help message");
 259         System.exit(exit);
 260     }
 261 }
   1 /*
   2  * Copyright (c) 2006, 2017, 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


  46         if (args.length == 0) {
  47             usage(1); // no arguments
  48         }
  49         checkForUnsupportedOptions(args);
  50 
  51         boolean doFlag = false;
  52         boolean doFlags = false;
  53         boolean doSysprops = false;
  54         int flag = -1;
  55 
  56         // Parse the options (arguments starting with "-" )
  57         int optionCount = 0;
  58         while (optionCount < args.length) {
  59             String arg = args[optionCount];
  60             if (!arg.startsWith("-")) {
  61                 break;
  62             }
  63 
  64             optionCount++;
  65 
  66             // -help: legacy. Undocumented.
  67             if (arg.equals("-?") || arg.equals("-h") || arg.equals("--help") || arg.equals("-help")) {
  68                 usage(0);
  69             }
  70 
  71             if (arg.equals("-flag")) {
  72                 doFlag = true;
  73                 // Consume the flag
  74                 if (optionCount < args.length) {
  75                     flag = optionCount++;
  76                     break;
  77                 }
  78                 usage(1);
  79             }
  80 
  81             if (arg.equals("-flags")) {
  82                 doFlags = true;
  83                 break;
  84             }
  85 
  86             if (arg.equals("-sysprops")) {
  87                 doSysprops = true;


 239 
 240     private static void SAOptionError(String msg) {
 241         System.err.println("Error: " + msg);
 242         System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jinfo instead");
 243         System.exit(1);
 244     }
 245 
 246      // print usage message
 247     private static void usage(int exit) {
 248         System.err.println("Usage:");
 249         System.err.println("    jinfo <option> <pid>");
 250         System.err.println("       (to connect to a running process)");
 251         System.err.println("");
 252         System.err.println("where <option> is one of:");
 253         System.err.println("    -flag <name>         to print the value of the named VM flag");
 254         System.err.println("    -flag [+|-]<name>    to enable or disable the named VM flag");
 255         System.err.println("    -flag <name>=<value> to set the named VM flag to the given value");
 256         System.err.println("    -flags               to print VM flags");
 257         System.err.println("    -sysprops            to print Java system properties");
 258         System.err.println("    <no option>          to print both VM flags and system properties");
 259         System.err.println("    -? | -h | --help     to print this help message");
 260         System.exit(exit);
 261     }
 262 }
< prev index next >