< prev index next >

src/jdk.jartool/share/classes/sun/tools/jar/GNUStyleOptions.java

Print this page
rev 50498 : 8199871: Deprecate pack200 and unpack200 tools
Reviewed-by:


   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
  23  * questions.
  24  */
  25 
  26 package sun.tools.jar;
  27 
  28 import java.io.File;
  29 import java.io.PrintStream;
  30 import java.io.PrintWriter;
  31 import java.lang.module.ModuleFinder;
  32 import java.lang.module.ModuleDescriptor.Version;
  33 import java.nio.file.Path;
  34 import java.nio.file.Paths;
  35 import java.util.regex.Pattern;
  36 import java.util.regex.PatternSyntaxException;
  37 
  38 import jdk.internal.module.ModulePath;
  39 import jdk.internal.module.ModuleResolution;
  40 
  41 /**
  42  * Parser for GNU Style Options.
  43  */
  44 class GNUStyleOptions {
  45 
  46     static class BadArgs extends Exception {
  47         static final long serialVersionUID = 0L;
  48 
  49         boolean showUsage;
  50 
  51         BadArgs(String key, String arg) { super(Main.formatMsg(key, arg)); }
  52         BadArgs(String key) { super(Main.getMsg(key)); }
  53 
  54         BadArgs showUsage(boolean b) {
  55             showUsage = b;
  56             return this;
  57         }


 275             return false;
 276         }
 277 
 278         abstract void process(Main jartool, String opt, String arg) throws BadArgs;
 279     }
 280 
 281     static int parseOptions(Main jartool, String[] args) throws BadArgs {
 282         int count = 0;
 283         if (args.length == 0) {
 284             jartool.info = GNUStyleOptions::printUsageTryHelp;  //  never be here
 285             return 0;
 286         }
 287 
 288         // process options
 289         for (; count < args.length; count++) {
 290             if (args[count].charAt(0) != '-' || args[count].equals("-C") ||
 291                 args[count].equals("--release"))
 292                 break;
 293 
 294             String name = args[count];




 295             Option option = getOption(name);
 296             String param = null;
 297             if (option.hasArg) {
 298                 if (name.startsWith("--help")) {  // "special" optional separator
 299                     if (name.indexOf(':') > 0) {
 300                         param = name.substring(name.indexOf(':') + 1, name.length());
 301                     }
 302                 } else if (name.startsWith("--") && name.indexOf('=') > 0) {
 303                     param = name.substring(name.indexOf('=') + 1, name.length());
 304                 } else if (count + 1 < args.length) {
 305                     param = args[++count];
 306                 }
 307                 if (!option.argIsOptional &&
 308                     (param == null || param.isEmpty() || param.charAt(0) == '-')) {
 309                     throw new BadArgs("error.missing.arg", name).showUsage(true);
 310                 }
 311             }
 312             option.process(jartool, name, param);
 313         }
 314 




   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
  23  * questions.
  24  */
  25 
  26 package sun.tools.jar;
  27 
  28 import java.io.File;

  29 import java.io.PrintWriter;

  30 import java.lang.module.ModuleDescriptor.Version;
  31 import java.nio.file.Path;
  32 import java.nio.file.Paths;
  33 import java.util.regex.Pattern;
  34 import java.util.regex.PatternSyntaxException;

  35 import jdk.internal.module.ModulePath;
  36 import jdk.internal.module.ModuleResolution;
  37 
  38 /**
  39  * Parser for GNU Style Options.
  40  */
  41 class GNUStyleOptions {
  42 
  43     static class BadArgs extends Exception {
  44         static final long serialVersionUID = 0L;
  45 
  46         boolean showUsage;
  47 
  48         BadArgs(String key, String arg) { super(Main.formatMsg(key, arg)); }
  49         BadArgs(String key) { super(Main.getMsg(key)); }
  50 
  51         BadArgs showUsage(boolean b) {
  52             showUsage = b;
  53             return this;
  54         }


 272             return false;
 273         }
 274 
 275         abstract void process(Main jartool, String opt, String arg) throws BadArgs;
 276     }
 277 
 278     static int parseOptions(Main jartool, String[] args) throws BadArgs {
 279         int count = 0;
 280         if (args.length == 0) {
 281             jartool.info = GNUStyleOptions::printUsageTryHelp;  //  never be here
 282             return 0;
 283         }
 284 
 285         // process options
 286         for (; count < args.length; count++) {
 287             if (args[count].charAt(0) != '-' || args[count].equals("-C") ||
 288                 args[count].equals("--release"))
 289                 break;
 290 
 291             String name = args[count];
 292             if (name.equals("-XDsuppress-tool-removal-message")) {
 293                 jartool.suppressDeprecateMsg = true;
 294                 continue;
 295             }
 296             Option option = getOption(name);
 297             String param = null;
 298             if (option.hasArg) {
 299                 if (name.startsWith("--help")) {  // "special" optional separator
 300                     if (name.indexOf(':') > 0) {
 301                         param = name.substring(name.indexOf(':') + 1, name.length());
 302                     }
 303                 } else if (name.startsWith("--") && name.indexOf('=') > 0) {
 304                     param = name.substring(name.indexOf('=') + 1, name.length());
 305                 } else if (count + 1 < args.length) {
 306                     param = args[++count];
 307                 }
 308                 if (!option.argIsOptional &&
 309                     (param == null || param.isEmpty() || param.charAt(0) == '-')) {
 310                     throw new BadArgs("error.missing.arg", name).showUsage(true);
 311                 }
 312             }
 313             option.process(jartool, name, param);
 314         }
 315 


< prev index next >