< prev index next >

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

Print this page
rev 48495 : 8189102: All tools should support -?, -h and --help
Reviewed-by: kvn, jjg, weijun, alanb, rfield, ksrini
   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, 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


  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("-?") ||
  67                 arg.equals("-h") ||
  68                 arg.equals("--help") ||
  69                 // -help: legacy.
  70                 arg.equals("-help")) {
  71                 usage(0);
  72             }
  73 
  74             if (arg.equals("-flag")) {
  75                 doFlag = true;
  76                 // Consume the flag
  77                 if (optionCount < args.length) {
  78                     flag = optionCount++;
  79                     break;
  80                 }
  81                 usage(1);
  82             }
  83 
  84             if (arg.equals("-flags")) {
  85                 doFlags = true;
  86                 break;
  87             }
  88 
  89             if (arg.equals("-sysprops")) {
  90                 doSysprops = true;


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