262 || !(jarfile.toLowerCase().endsWith(".jar")
263 || jarfile.toLowerCase().endsWith(".zip")
264 || (jarfile.equals("-") && !doPack))) {
265 printUsage(doPack, false, System.err);
266 System.exit(2);
267 return;
268 }
269
270 if (doRepack)
271 doPack = doUnpack = true;
272 else if (doPack)
273 doUnpack = false;
274
275 Pack200.Packer jpack = Pack200.newPacker();
276 Pack200.Unpacker junpack = Pack200.newUnpacker();
277
278 jpack.properties().putAll(engProps);
279 junpack.properties().putAll(engProps);
280 if (doRepack && newfile.equals(jarfile)) {
281 String zipc = getZipComment(jarfile);
282 if (verbose && zipc.length() > 0)
283 System.out.println(MessageFormat.format(RESOURCE.getString(DriverResource.DETECTED_ZIP_COMMENT), zipc));
284 if (zipc.indexOf(Utils.PACK_ZIP_ARCHIVE_MARKER_COMMENT) >= 0) {
285 System.out.println(MessageFormat.format(RESOURCE.getString(DriverResource.SKIP_FOR_REPACKED), jarfile));
286 doPack = false;
287 doUnpack = false;
288 doRepack = false;
289 }
290 }
291
292 try {
293
294 if (doPack) {
295 // Mode = Pack.
296 JarFile in = new JarFile(new File(jarfile));
297 OutputStream out;
298 // Packfile must be -, *.gz, *.pack, or *.pac.
299 if (packfile.equals("-")) {
300 out = System.out;
301 // Send warnings, etc., to stderr instead of stdout.
302 System.setOut(System.err);
535 * <p>
536 * The options string is a newline-separated series of
537 * option processing specifiers.
538 */
539 private static
540 String parseCommandOptions(List<String> args,
541 String options,
542 Map<String,String> properties) {
543 //System.out.println(args+" // "+properties);
544
545 String resultString = null;
546
547 // Convert options string into optLines dictionary.
548 TreeMap<String,String[]> optmap = new TreeMap<>();
549 loadOptmap:
550 for (String optline : options.split("\n")) {
551 String[] words = optline.split("\\p{Space}+");
552 if (words.length == 0) continue loadOptmap;
553 String opt = words[0];
554 words[0] = ""; // initial word is not a spec
555 if (opt.length() == 0 && words.length >= 1) {
556 opt = words[1]; // initial "word" is empty due to leading ' '
557 words[1] = "";
558 }
559 if (opt.length() == 0) continue loadOptmap;
560 String[] prevWords = optmap.put(opt, words);
561 if (prevWords != null)
562 throw new RuntimeException(MessageFormat.format(RESOURCE.getString(DriverResource.DUPLICATE_OPTION), optline.trim()));
563 }
564
565 // State machine for parsing a command line.
566 ListIterator<String> argp = args.listIterator();
567 ListIterator<String> pbp = new ArrayList<String>().listIterator();
568 doArgs:
569 for (;;) {
570 // One trip through this loop per argument.
571 // Multiple trips per option only if several options per argument.
572 String arg;
573 if (pbp.hasPrevious()) {
574 arg = pbp.previous();
575 pbp.remove();
605
606 // Execute the option processing specs for this opt.
607 // If no actions are taken, then look for a shorter prefix.
608 boolean didAction = false;
609 boolean isError = false;
610
611 int pbpMark = pbp.nextIndex(); // in case of backtracking
612 String[] specs = optmap.get(opt);
613 eachSpec:
614 for (String spec : specs) {
615 if (spec.length() == 0) continue eachSpec;
616 if (spec.startsWith("#")) break eachSpec;
617 int sidx = 0;
618 char specop = spec.charAt(sidx++);
619
620 // Deal with '+'/'*' prefixes (spec conditions).
621 boolean ok;
622 switch (specop) {
623 case '+':
624 // + means we want an non-empty val suffix.
625 ok = (val.length() != 0);
626 specop = spec.charAt(sidx++);
627 break;
628 case '*':
629 // * means we accept empty or non-empty
630 ok = true;
631 specop = spec.charAt(sidx++);
632 break;
633 default:
634 // No condition prefix means we require an exact
635 // match, as indicated by an empty val suffix.
636 ok = (val.length() == 0);
637 break;
638 }
639 if (!ok) continue eachSpec;
640
641 String specarg = spec.substring(sidx);
642 switch (specop) {
643 case '.': // terminate the option sequence
644 resultString = (specarg.length() != 0)? specarg.intern(): opt;
645 break doArgs;
646 case '?': // abort the option sequence
647 resultString = (specarg.length() != 0)? specarg.intern(): arg;
648 isError = true;
649 break eachSpec;
650 case '@': // change the effective opt name
651 opt = specarg.intern();
652 break;
653 case '>': // shift remaining arg val to next arg
654 pbp.add(specarg + val); // push a new argument
655 val = "";
656 break;
657 case '!': // negation option
658 String negopt = (specarg.length() != 0)? specarg.intern(): opt;
659 properties.remove(negopt);
660 properties.put(negopt, null); // leave placeholder
661 didAction = true;
662 break;
663 case '$': // normal "boolean" option
664 String boolval;
665 if (specarg.length() != 0) {
666 // If there is a given spec token, store it.
667 boolval = specarg;
668 } else {
669 String old = properties.get(opt);
670 if (old == null || old.length() == 0) {
671 boolval = "1";
672 } else {
673 // Increment any previous value as a numeral.
674 boolval = ""+(1+Integer.parseInt(old));
675 }
676 }
677 properties.put(opt, boolval);
678 didAction = true;
679 break;
680 case '=': // "string" option
681 case '&': // "collection" option
682 // Read an option.
683 boolean append = (specop == '&');
684 String strval;
685 if (pbp.hasPrevious()) {
|
262 || !(jarfile.toLowerCase().endsWith(".jar")
263 || jarfile.toLowerCase().endsWith(".zip")
264 || (jarfile.equals("-") && !doPack))) {
265 printUsage(doPack, false, System.err);
266 System.exit(2);
267 return;
268 }
269
270 if (doRepack)
271 doPack = doUnpack = true;
272 else if (doPack)
273 doUnpack = false;
274
275 Pack200.Packer jpack = Pack200.newPacker();
276 Pack200.Unpacker junpack = Pack200.newUnpacker();
277
278 jpack.properties().putAll(engProps);
279 junpack.properties().putAll(engProps);
280 if (doRepack && newfile.equals(jarfile)) {
281 String zipc = getZipComment(jarfile);
282 if (verbose && !zipc.isEmpty())
283 System.out.println(MessageFormat.format(RESOURCE.getString(DriverResource.DETECTED_ZIP_COMMENT), zipc));
284 if (zipc.indexOf(Utils.PACK_ZIP_ARCHIVE_MARKER_COMMENT) >= 0) {
285 System.out.println(MessageFormat.format(RESOURCE.getString(DriverResource.SKIP_FOR_REPACKED), jarfile));
286 doPack = false;
287 doUnpack = false;
288 doRepack = false;
289 }
290 }
291
292 try {
293
294 if (doPack) {
295 // Mode = Pack.
296 JarFile in = new JarFile(new File(jarfile));
297 OutputStream out;
298 // Packfile must be -, *.gz, *.pack, or *.pac.
299 if (packfile.equals("-")) {
300 out = System.out;
301 // Send warnings, etc., to stderr instead of stdout.
302 System.setOut(System.err);
535 * <p>
536 * The options string is a newline-separated series of
537 * option processing specifiers.
538 */
539 private static
540 String parseCommandOptions(List<String> args,
541 String options,
542 Map<String,String> properties) {
543 //System.out.println(args+" // "+properties);
544
545 String resultString = null;
546
547 // Convert options string into optLines dictionary.
548 TreeMap<String,String[]> optmap = new TreeMap<>();
549 loadOptmap:
550 for (String optline : options.split("\n")) {
551 String[] words = optline.split("\\p{Space}+");
552 if (words.length == 0) continue loadOptmap;
553 String opt = words[0];
554 words[0] = ""; // initial word is not a spec
555 if (opt.isEmpty() && words.length >= 1) {
556 opt = words[1]; // initial "word" is empty due to leading ' '
557 words[1] = "";
558 }
559 if (opt.length() == 0) continue loadOptmap;
560 String[] prevWords = optmap.put(opt, words);
561 if (prevWords != null)
562 throw new RuntimeException(MessageFormat.format(RESOURCE.getString(DriverResource.DUPLICATE_OPTION), optline.trim()));
563 }
564
565 // State machine for parsing a command line.
566 ListIterator<String> argp = args.listIterator();
567 ListIterator<String> pbp = new ArrayList<String>().listIterator();
568 doArgs:
569 for (;;) {
570 // One trip through this loop per argument.
571 // Multiple trips per option only if several options per argument.
572 String arg;
573 if (pbp.hasPrevious()) {
574 arg = pbp.previous();
575 pbp.remove();
605
606 // Execute the option processing specs for this opt.
607 // If no actions are taken, then look for a shorter prefix.
608 boolean didAction = false;
609 boolean isError = false;
610
611 int pbpMark = pbp.nextIndex(); // in case of backtracking
612 String[] specs = optmap.get(opt);
613 eachSpec:
614 for (String spec : specs) {
615 if (spec.length() == 0) continue eachSpec;
616 if (spec.startsWith("#")) break eachSpec;
617 int sidx = 0;
618 char specop = spec.charAt(sidx++);
619
620 // Deal with '+'/'*' prefixes (spec conditions).
621 boolean ok;
622 switch (specop) {
623 case '+':
624 // + means we want an non-empty val suffix.
625 ok = !val.isEmpty();
626 specop = spec.charAt(sidx++);
627 break;
628 case '*':
629 // * means we accept empty or non-empty
630 ok = true;
631 specop = spec.charAt(sidx++);
632 break;
633 default:
634 // No condition prefix means we require an exact
635 // match, as indicated by an empty val suffix.
636 ok = (val.length() == 0);
637 break;
638 }
639 if (!ok) continue eachSpec;
640
641 String specarg = spec.substring(sidx);
642 switch (specop) {
643 case '.': // terminate the option sequence
644 resultString = specarg.isEmpty() ? opt : specarg.intern();
645 break doArgs;
646 case '?': // abort the option sequence
647 resultString = specarg.isEmpty() ? arg : specarg.intern();
648 isError = true;
649 break eachSpec;
650 case '@': // change the effective opt name
651 opt = specarg.intern();
652 break;
653 case '>': // shift remaining arg val to next arg
654 pbp.add(specarg + val); // push a new argument
655 val = "";
656 break;
657 case '!': // negation option
658 String negopt = specarg.isEmpty() ? opt : specarg.intern();
659 properties.remove(negopt);
660 properties.put(negopt, null); // leave placeholder
661 didAction = true;
662 break;
663 case '$': // normal "boolean" option
664 String boolval;
665 if (!specarg.isEmpty()) {
666 // If there is a given spec token, store it.
667 boolval = specarg;
668 } else {
669 String old = properties.get(opt);
670 if (old == null || old.length() == 0) {
671 boolval = "1";
672 } else {
673 // Increment any previous value as a numeral.
674 boolval = ""+(1+Integer.parseInt(old));
675 }
676 }
677 properties.put(opt, boolval);
678 didAction = true;
679 break;
680 case '=': // "string" option
681 case '&': // "collection" option
682 // Read an option.
683 boolean append = (specop == '&');
684 String strval;
685 if (pbp.hasPrevious()) {
|