src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
branchJDK-8200758-branch
changeset 57060 5103d6d2e796
parent 57059 9bb2a4dc3af7
child 57062 044e7a644ee3
equal deleted inserted replaced
57059:9bb2a4dc3af7 57060:5103d6d2e796
   510         PLATFORM_WIN,
   510         PLATFORM_WIN,
   511         PLATFORM_LINUX;
   511         PLATFORM_LINUX;
   512     }
   512     }
   513 
   513 
   514     private void initArgumentList(String[] args) {
   514     private void initArgumentList(String[] args) {
   515         argList = new ArrayList<>(Arrays.asList(args));
   515         argList = new ArrayList<String>(args.length);
       
   516         for (String arg : args) {
       
   517             if (arg.startsWith("@")) {
       
   518                 if (arg.length() > 1) {
       
   519                     String filename = arg.substring(1);
       
   520                     argList.addAll(extractArgList(filename));
       
   521                 } else {
       
   522                     Log.error("Illegal argument ["+arg+"]");
       
   523                 }
       
   524             } else {
       
   525                 argList.add(arg);
       
   526             }
       
   527         }
       
   528         Log.debug ("\nJPackage argument list: \n" + argList + "\n");
   516         pos = 0;
   529         pos = 0;
   517 
   530 
   518         deployParams = new DeployParams();
   531         deployParams = new DeployParams();
   519         bundleType = BundlerType.NONE;
   532         bundleType = BundlerType.NONE;
   520 
   533 
   521         allOptions = new ArrayList<>();
   534         allOptions = new ArrayList<>();
   522 
   535 
   523         secondaryLaunchers = new ArrayList<>();
   536         secondaryLaunchers = new ArrayList<>();
   524     }
   537     }
       
   538 
       
   539     private List<String> extractArgList(String filename) {
       
   540         List<String> args = new ArrayList<String>();
       
   541         try {
       
   542             File f = new File(filename);
       
   543             if (f.exists()) {
       
   544                 List<String> lines = Files.readAllLines(f.toPath());
       
   545                 for (String line : lines) {
       
   546                     String [] qsplit;
       
   547                     String quote = "\"";
       
   548                     if (line.contains("\"")) {
       
   549                         qsplit = line.split("\"");
       
   550                     } else {
       
   551                         qsplit = line.split("\'");
       
   552                         quote = "\'";
       
   553                     }
       
   554                     for (int i=0; i<qsplit.length; i++) {
       
   555                         // every other qsplit of line is a quoted string
       
   556                         if ((i & 1) == 0) {
       
   557                             // non-quoted string - split by whitespace
       
   558                             String [] newargs = qsplit[i].split("\\s");
       
   559                             for (String newarg : newargs) {
       
   560                                 args.add(newarg);
       
   561                             }
       
   562                         } else {
       
   563                             // quoted string - don't split by whitespace
       
   564                             args.add(qsplit[i]);
       
   565                         }
       
   566                     }
       
   567                 } 
       
   568             } else {
       
   569                Log.error("Can not find argument file: " + f);
       
   570             }
       
   571         } catch (IOException ioe) {
       
   572             Log.verbose(ioe.getMessage());
       
   573             Log.verbose(ioe);
       
   574         }
       
   575         return args;
       
   576     }
       
   577 
   525 
   578 
   526     public boolean processArguments() throws Exception {
   579     public boolean processArguments() throws Exception {
   527         try {
   580         try {
   528 
   581 
   529             // init context of arguments
   582             // init context of arguments
   532             // parse cmd line
   585             // parse cmd line
   533             String arg;
   586             String arg;
   534             CLIOptions option;
   587             CLIOptions option;
   535             for (; CLIOptions.hasNextArg(); CLIOptions.nextArg()) {
   588             for (; CLIOptions.hasNextArg(); CLIOptions.nextArg()) {
   536                 arg = CLIOptions.getArg();
   589                 arg = CLIOptions.getArg();
   537                 // check if it's a CLI option
       
   538                 if ((option = toCLIOption(arg)) != null) {
   590                 if ((option = toCLIOption(arg)) != null) {
       
   591                     // found a CLI option
   539                     allOptions.add(option);
   592                     allOptions.add(option);
   540                     option.execute();
   593                     option.execute();
   541                 } else {
   594                 } else {
   542                     Log.error("Illegal argument ["+arg+"]");
   595                     Log.error("Illegal argument ["+arg+"]");
   543                 }
   596                 }