< prev index next >

modules/jdk.packager/src/main/java/com/sun/javafx/tools/packager/Main.java

Print this page




  35 import java.io.FileInputStream;
  36 import java.io.IOException;
  37 import java.text.MessageFormat;
  38 import java.util.*;
  39 import java.util.stream.Stream;
  40 import java.nio.file.Files;
  41 import java.nio.file.Path;
  42 
  43 import jdk.packager.internal.JLinkBundlerHelper;
  44 
  45 
  46 public class Main {
  47 
  48     private static final ResourceBundle bundle =
  49             ResourceBundle.getBundle("com/sun/javafx/tools/packager/Bundle");
  50 
  51     private static final String version = bundle.getString("MSG_Version")
  52             + " " + PackagerLib.JAVAFX_VERSION + "\n";
  53     private static final String help = bundle.getString("MSG_Help_1")
  54                                         + bundle.getString("MSG_Help_2")
  55                                         + bundle.getString("MSG_Help_3")
  56                                         + bundle.getString("MSG_Help_4")
  57                                         + bundle.getString("MSG_Help_5")
  58                                         + bundle.getString("MSG_Help_6")
  59                                         + bundle.getString("MSG_Help_7");
  60 
  61     private static String nextArg(String args[], int i) {
  62         return (i == args.length - 1) ? "" : args[i + 1];
  63     }
  64 
  65     private static boolean verbose = false;
  66     private static boolean packageAsJar = false;
  67     private static boolean genJNLP = false;
  68     private static boolean genPackages = false;
  69     private static boolean css2Bin = false;
  70     private static boolean signJar = false;
  71     private static boolean makeAll = false;
  72 
  73     private static void addResources(CommonParams commonParams,
  74                                      String srcdir, String srcfiles) {
  75         if (srcdir == null || "".equals(srcdir)) {
  76             return;
  77         }
  78 
  79         File baseDir = new File(srcdir);
  80 
  81         if (!baseDir.isDirectory()) {
  82             Log.info("Unable to add resources: \"-srcdir\" is not a directory.");
  83             return;
  84         }
  85 
  86         List<String> fileNames;
  87         if (srcfiles != null) {
  88             fileNames = Arrays.asList(srcfiles.split(File.pathSeparator));
  89         } else {
  90             // "-srcfiles" is omitted, all files in srcdir (which
  91             // is a mandatory argument in this case) will be packaged.


 391                     addResources(deployParams, srcdir, srcfiles);
 392                 } else if (args[0].equalsIgnoreCase("-createbss")) {
 393                     for (int i = 1; i < args.length; i++) {
 394                         String arg = args[i];
 395                         if (arg.equalsIgnoreCase("-verbose") || arg.equalsIgnoreCase("-v")) {
 396                             createBssParams.setVerbose(true);
 397                             verbose = true;
 398                         } else if (arg.equalsIgnoreCase("-outdir")) {
 399                             createBssParams.setOutdir(new File(nextArg(args, i++)));
 400                         } else if (arg.equalsIgnoreCase("-srcdir")) {
 401                             srcdir = nextArg(args, i++);
 402                         } else if (arg.equalsIgnoreCase("-srcfiles")) {
 403                             srcfiles = nextArg(args, i++);
 404                         } else {
 405                             throw new PackagerException("ERR_UnknownArgument", arg);
 406                         }
 407                     }
 408 
 409                     addResources(createBssParams, srcdir, srcfiles);
 410                     css2Bin = true;
 411                 } else if (args[0].equalsIgnoreCase("-signJar")) {
 412                     Log.info("Warning: -signJar has been deprecated and will be removed in a future release.");
 413                     for (int i = 1; i < args.length; i++) {
 414                         String arg = args[i];
 415                         if (arg.equalsIgnoreCase("-keyStore")) {
 416                             signJarParams.setKeyStore(new File(nextArg(args, i++)));
 417                         } else if(arg.equalsIgnoreCase("-alias")) {
 418                             signJarParams.setAlias(nextArg(args, i++));
 419                         } else if(arg.equalsIgnoreCase("-storePass")) {
 420                             signJarParams.setStorePass(nextArg(args, i++));
 421                         } else if(arg.equalsIgnoreCase("-keyPass")) {
 422                             signJarParams.setKeyPass(nextArg(args, i++));
 423                         } else if(arg.equalsIgnoreCase("-storeType")) {
 424                             signJarParams.setStoreType(nextArg(args, i++));
 425                         } else if(arg.equalsIgnoreCase("-verbose") || arg.equalsIgnoreCase("-v")) {
 426                             signJarParams.setVerbose(true);
 427                             verbose = true;
 428                         } else if (arg.equalsIgnoreCase("-outdir")) {
 429                             signJarParams.setOutdir(new File(nextArg(args, i++)));
 430                         } else if (arg.equalsIgnoreCase("-srcdir")) {
 431                             srcdir = nextArg(args, i++);
 432                         } else if (arg.equalsIgnoreCase("-srcfiles")) {
 433                             srcfiles = nextArg(args, i++);
 434                         } else {
 435                             throw new PackagerException("ERR_UnknownArgument", arg);
 436                         }
 437                     }
 438 
 439                     addResources(signJarParams, srcdir, srcfiles);
 440                     signJar = true;
 441                 } else if (args[0].equalsIgnoreCase("-makeall")) {
 442                     System.err.println("-makeall is deprecated");
 443                     for (int i = 1; i < args.length; i++) {
 444                         String arg = args[i];
 445                         if (arg.equalsIgnoreCase("-appclass")) {
 446                             makeAllParams.setAppClass(nextArg(args, i++));
 447                         } else if (arg.equalsIgnoreCase("-preloader")) {
 448                             makeAllParams.setPreloader(nextArg(args, i++));
 449                         } else if (arg.equalsIgnoreCase("-classpath")) {
 450                             makeAllParams.setClasspath(nextArg(args, i++));
 451                         } else if (arg.equalsIgnoreCase("-name")) {
 452                             makeAllParams.setAppName(nextArg(args, i++));
 453                         } else if(arg.equalsIgnoreCase("-width")) {
 454                             makeAllParams.setWidth(Integer.parseInt(nextArg(args, i++)));
 455                         } else if(arg.equalsIgnoreCase("-height")) {
 456                             makeAllParams.setHeight(Integer.parseInt(nextArg(args, i++)));
 457                         } else if(arg.equalsIgnoreCase("-v")) {
 458                             makeAllParams.setVerbose(true);
 459                         } else {
 460                             throw new PackagerException("ERR_UnknownArgument", arg);
 461                         }
 462                     }
 463                     makeAll = true;
 464                 } else if (args[0].equalsIgnoreCase("-help")) {
 465                     showBundlerHelp(args[1], args.length > 2 && "-verbose".equals(args[2]));
 466                 } else {
 467                     System.err.println(MessageFormat.format(
 468                                         bundle.getString("ERR_UnknownCommand"),
 469                                         args[0]));
 470                     System.exit(-1);
 471                 }
 472 
 473                 //set default logger
 474                 if (verbose) {
 475                     com.oracle.tools.packager.Log.setLogger(new com.oracle.tools.packager.Log.Logger(true));
 476                 } else {
 477                     com.oracle.tools.packager.Log.setLogger(new com.oracle.tools.packager.Log.Logger(false));
 478                 }
 479 
 480                 if (css2Bin) {
 481                     createBssParams.validate();
 482                     packager.generateBSS(createBssParams);
 483                 }
 484                 if (packageAsJar) {
 485                     createJarParams.validate();
 486                     packager.packageAsJar(createJarParams);
 487                 }
 488                 if (genJNLP) {
 489                     deployParams.setBundleType(BundleType.JNLP);
 490                     deployParams.validate();
 491                     packager.generateDeploymentPackages(deployParams);
 492                 }
 493                 if (genPackages) {
 494                     deployParams.setBundleType(bundleType);
 495                     deployParams.validate();
 496                     packager.generateDeploymentPackages(deployParams);
 497                 }
 498                 if (signJar) {
 499                     signJarParams.validate();
 500                     if (signJarParams.storePass == null) {
 501                         char[] passwd = System.console().readPassword(bundle.getString("MSG_EnterKeystorePassword"));
 502                         if (passwd == null) {
 503                             signJarParams.storePass = "";
 504                         } else {
 505                             signJarParams.storePass = new String(passwd);
 506                         }
 507                     }
 508                     if (signJarParams.keyPass == null) {
 509                         char[] passwd = System.console().readPassword(bundle.getString("MSG_EnterKeyPassword"), signJarParams.alias);
 510                         if (passwd == null) {
 511                             signJarParams.keyPass = "";
 512                         } else {
 513                             signJarParams.keyPass = new String(passwd);
 514                         }
 515                     }
 516                     packager.signJar(signJarParams);
 517                 }
 518                 if (makeAll) {
 519                     makeAllParams.validate();
 520                     packager.makeAll(makeAllParams);
 521                 }
 522 
 523             } catch (Exception e) {
 524                 if (verbose) {
 525                     throw e;
 526                 } else {
 527                     System.err.println(e.getMessage());
 528                     if (e.getCause() != null && e.getCause() != e) {
 529                         System.err.println(e.getCause().getMessage());
 530                     }
 531                     System.exit(-1);
 532                 }
 533             }
 534         }
 535     }
 536 
 537     private static final String MODULE = "--" + StandardBundlerParam.MODULE.getID();
 538     private static final String M = "-m";
 539     private static final String MODULE_PATH = "--" + StandardBundlerParam.MODULE_PATH.getID();
 540     private static final String P = "-p";
 541     private static final String ADD_MODULES = "--" + StandardBundlerParam.ADD_MODULES.getID();
 542     private static final String LIMIT_MODULES = "--" + StandardBundlerParam.LIMIT_MODULES.getID();




  35 import java.io.FileInputStream;
  36 import java.io.IOException;
  37 import java.text.MessageFormat;
  38 import java.util.*;
  39 import java.util.stream.Stream;
  40 import java.nio.file.Files;
  41 import java.nio.file.Path;
  42 
  43 import jdk.packager.internal.JLinkBundlerHelper;
  44 
  45 
  46 public class Main {
  47 
  48     private static final ResourceBundle bundle =
  49             ResourceBundle.getBundle("com/sun/javafx/tools/packager/Bundle");
  50 
  51     private static final String version = bundle.getString("MSG_Version")
  52             + " " + PackagerLib.JAVAFX_VERSION + "\n";
  53     private static final String help = bundle.getString("MSG_Help_1")
  54                                         + bundle.getString("MSG_Help_2")
  55                                         + MessageFormat.format(bundle.getString("MSG_Help_3"), File.pathSeparator)
  56                                         + bundle.getString("MSG_Help_4")
  57                                         + bundle.getString("MSG_Help_5")
  58                                         + bundle.getString("MSG_Help_6")
  59                                         + bundle.getString("MSG_Help_7");
  60 
  61     private static String nextArg(String args[], int i) {
  62         return (i == args.length - 1) ? "" : args[i + 1];
  63     }
  64 
  65     private static boolean verbose = false;
  66     private static boolean packageAsJar = false;
  67     private static boolean genJNLP = false;
  68     private static boolean genPackages = false;
  69     private static boolean css2Bin = false;


  70 
  71     private static void addResources(CommonParams commonParams,
  72                                      String srcdir, String srcfiles) {
  73         if (srcdir == null || "".equals(srcdir)) {
  74             return;
  75         }
  76 
  77         File baseDir = new File(srcdir);
  78 
  79         if (!baseDir.isDirectory()) {
  80             Log.info("Unable to add resources: \"-srcdir\" is not a directory.");
  81             return;
  82         }
  83 
  84         List<String> fileNames;
  85         if (srcfiles != null) {
  86             fileNames = Arrays.asList(srcfiles.split(File.pathSeparator));
  87         } else {
  88             // "-srcfiles" is omitted, all files in srcdir (which
  89             // is a mandatory argument in this case) will be packaged.


 389                     addResources(deployParams, srcdir, srcfiles);
 390                 } else if (args[0].equalsIgnoreCase("-createbss")) {
 391                     for (int i = 1; i < args.length; i++) {
 392                         String arg = args[i];
 393                         if (arg.equalsIgnoreCase("-verbose") || arg.equalsIgnoreCase("-v")) {
 394                             createBssParams.setVerbose(true);
 395                             verbose = true;
 396                         } else if (arg.equalsIgnoreCase("-outdir")) {
 397                             createBssParams.setOutdir(new File(nextArg(args, i++)));
 398                         } else if (arg.equalsIgnoreCase("-srcdir")) {
 399                             srcdir = nextArg(args, i++);
 400                         } else if (arg.equalsIgnoreCase("-srcfiles")) {
 401                             srcfiles = nextArg(args, i++);
 402                         } else {
 403                             throw new PackagerException("ERR_UnknownArgument", arg);
 404                         }
 405                     }
 406 
 407                     addResources(createBssParams, srcdir, srcfiles);
 408                     css2Bin = true;





















































 409                 } else if (args[0].equalsIgnoreCase("-help")) {
 410                     showBundlerHelp(args[1], args.length > 2 && "-verbose".equals(args[2]));
 411                 } else {
 412                     System.err.println(MessageFormat.format(
 413                                         bundle.getString("ERR_UnknownCommand"),
 414                                         args[0]));
 415                     System.exit(-1);
 416                 }
 417 
 418                 //set default logger
 419                 if (verbose) {
 420                     com.oracle.tools.packager.Log.setLogger(new com.oracle.tools.packager.Log.Logger(true));
 421                 } else {
 422                     com.oracle.tools.packager.Log.setLogger(new com.oracle.tools.packager.Log.Logger(false));
 423                 }
 424 
 425                 if (css2Bin) {
 426                     createBssParams.validate();
 427                     packager.generateBSS(createBssParams);
 428                 }
 429                 if (packageAsJar) {
 430                     createJarParams.validate();
 431                     packager.packageAsJar(createJarParams);
 432                 }
 433                 if (genJNLP) {
 434                     deployParams.setBundleType(BundleType.JNLP);
 435                     deployParams.validate();
 436                     packager.generateDeploymentPackages(deployParams);
 437                 }
 438                 if (genPackages) {
 439                     deployParams.setBundleType(bundleType);
 440                     deployParams.validate();
 441                     packager.generateDeploymentPackages(deployParams);
 442                 }

























 443             } catch (Exception e) {
 444                 if (verbose) {
 445                     throw e;
 446                 } else {
 447                     System.err.println(e.getMessage());
 448                     if (e.getCause() != null && e.getCause() != e) {
 449                         System.err.println(e.getCause().getMessage());
 450                     }
 451                     System.exit(-1);
 452                 }
 453             }
 454         }
 455     }
 456 
 457     private static final String MODULE = "--" + StandardBundlerParam.MODULE.getID();
 458     private static final String M = "-m";
 459     private static final String MODULE_PATH = "--" + StandardBundlerParam.MODULE_PATH.getID();
 460     private static final String P = "-p";
 461     private static final String ADD_MODULES = "--" + StandardBundlerParam.ADD_MODULES.getID();
 462     private static final String LIMIT_MODULES = "--" + StandardBundlerParam.LIMIT_MODULES.getID();


< prev index next >