jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java
changeset 41766 b5eab76a23a9
parent 41561 0c6942d13f2e
child 41817 b90ad1de93ea
equal deleted inserted replaced
41765:e830711d95ac 41766:b5eab76a23a9
   464                 }
   464                 }
   465             }
   465             }
   466             return pp;
   466             return pp;
   467         }
   467         }
   468 
   468 
       
   469         // used by jimage. Return unhandled arguments like "create", "describe".
   469         public List<String> handleOptions(T task, String[] args) throws BadArgs {
   470         public List<String> handleOptions(T task, String[] args) throws BadArgs {
       
   471             return handleOptions(task, args, true);
       
   472         }
       
   473 
       
   474         // used by jlink. No unhandled arguments like "create", "describe".
       
   475         void handleOptionsNoUnhandled(T task, String[] args) throws BadArgs {
       
   476             handleOptions(task, args, false);
       
   477         }
       
   478 
       
   479         // shared code that handles options for both jlink and jimage. jimage uses arguments like
       
   480         // "create", "describe" etc. as "task names". Those arguments are unhandled here and returned
       
   481         // as "unhandled arguments list". jlink does not want such arguments. "collectUnhandled" flag
       
   482         // tells whether to allow for unhandled arguments or not.
       
   483         private List<String> handleOptions(T task, String[] args, boolean collectUnhandled) throws BadArgs {
   470             // findbugs warning, copy instead of keeping a reference.
   484             // findbugs warning, copy instead of keeping a reference.
   471             command = Arrays.copyOf(args, args.length);
   485             command = Arrays.copyOf(args, args.length);
   472 
   486 
   473             // Must extract it prior to do any option analysis.
   487             // Must extract it prior to do any option analysis.
   474             // Required to interpret custom plugin options.
   488             // Required to interpret custom plugin options.
   497                 }
   511                 }
   498             }
   512             }
   499             String[] arr = new String[filteredArgs.size()];
   513             String[] arr = new String[filteredArgs.size()];
   500             args = filteredArgs.toArray(arr);
   514             args = filteredArgs.toArray(arr);
   501 
   515 
   502             List<String> rest = new ArrayList<>();
   516             List<String> rest = collectUnhandled? new ArrayList<>() : null;
   503             // process options
   517             // process options
   504             for (int i = 0; i < args.length; i++) {
   518             for (int i = 0; i < args.length; i++) {
   505                 if (!args[i].isEmpty() && args[i].charAt(0) == '-') {
   519                 if (args[i].charAt(0) == '-') {
   506                     String name = args[i];
   520                     String name = args[i];
   507                     PlugOption pluginOption = null;
   521                     PlugOption pluginOption = null;
   508                     Option<T> option = getOption(name);
   522                     Option<T> option = getOption(name);
   509                     if (option == null) {
   523                     if (option == null) {
   510                         pluginOption = pluginOptions.getOption(name);
   524                         pluginOption = pluginOptions.getOption(name);
   537                     }
   551                     }
   538                     if (opt.ignoreRest()) {
   552                     if (opt.ignoreRest()) {
   539                         i = args.length;
   553                         i = args.length;
   540                     }
   554                     }
   541                 } else {
   555                 } else {
   542                     rest.add(args[i]);
   556                     if (collectUnhandled) {
       
   557                         rest.add(args[i]);
       
   558                     } else {
       
   559                         throw new BadArgs("err.orphan.argument", args[i]).
       
   560                             showUsage(true);
       
   561                     }
   543                 }
   562                 }
   544             }
   563             }
   545             return rest;
   564             return rest;
   546         }
   565         }
   547 
   566