< prev index next >

src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java

Print this page




 108           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
 109 
 110     private DeployParams deployParams = null;
 111     private BundlerType bundleType = null;
 112 
 113     private int pos = 0;
 114     private List<String> argList = null;
 115 
 116     private List<CLIOptions> allOptions = null;
 117 
 118     private ArrayList<String> files = null;
 119 
 120     private String input = null;
 121     private String output = null;
 122 
 123     private boolean hasMainJar = false;
 124     private boolean hasMainClass = false;
 125     private boolean hasMainModule = false;
 126     private boolean hasTargetFormat = false;
 127     private boolean hasAppImage = false;
 128     private boolean retainBuildRoot = false;
 129 
 130     private String buildRoot = null;
 131     private String mainJarPath = null;
 132 
 133     private static boolean jreInstaller = false;
 134 
 135     private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
 136 
 137     private List<SecondaryLauncherArguments> secondaryLaunchers = null;
 138 
 139     private static Map<String, CLIOptions> argIds = new HashMap<>();
 140     private static Map<String, CLIOptions> argShortIds = new HashMap<>();
 141 
 142     {
 143         // init maps for parsing arguments
 144         EnumSet<CLIOptions> options = EnumSet.allOf(CLIOptions.class);
 145 
 146         options.forEach(option -> {
 147             argIds.put(option.getIdWithPrefix(), option);
 148             if (option.getShortIdWithPrefix() != null) {


 293             }
 294 
 295             ArrayList<Map<String, ? super Object>> associationList =
 296                 new ArrayList<Map<String, ? super Object>>();
 297 
 298             associationList.add(args);
 299 
 300             // check that we really add _another_ value to the list
 301             setOptionValue("file-associations", associationList);
 302 
 303         }),
 304 
 305         SECONDARY_LAUNCHER ("secondary-launcher",
 306                     OptionCategories.PROPERTY, () -> {
 307             context().secondaryLaunchers.add(
 308                 new SecondaryLauncherArguments(popArg()));
 309         }),
 310 
 311         BUILD_ROOT ("build-root", OptionCategories.PROPERTY, () -> {
 312             context().buildRoot = popArg();
 313             context().retainBuildRoot = true;
 314             setOptionValue("build-root", context().buildRoot);
 315         }),
 316 
 317         INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
 318 
 319         PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY, ()-> {
 320             setOptionValue("app-image", popArg());
 321             context().hasAppImage = true;
 322         }),
 323 
 324         PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
 325 
 326         MAIN_JAR ("main-jar", "j", OptionCategories.PROPERTY, () -> {
 327             context().mainJarPath = popArg();
 328             context().hasMainJar = true;
 329             setOptionValue("main-jar", context().mainJarPath);
 330         }),
 331 
 332         MODULE ("module", "m", OptionCategories.MODULAR, () -> {
 333             context().hasMainModule = true;


 421             this(id, shortId, category, null);
 422         }
 423 
 424         private CLIOptions(String id,
 425                 OptionCategories category, ArgAction action) {
 426             this(id, null, category, action);
 427         }
 428 
 429         private CLIOptions(String id, String shortId,
 430                            OptionCategories category, ArgAction action) {
 431             this.id = id;
 432             this.shortId = shortId;
 433             this.action = action;
 434             this.category = category;
 435         }
 436 
 437         static void setContext(Arguments context) {
 438             argContext = context;
 439         }
 440 
 441         private static Arguments context() {
 442             if (argContext != null) {
 443                 return argContext;
 444             } else {
 445                 throw new RuntimeException("Argument context is not set.");
 446             }
 447         }
 448 
 449         public String getId() {
 450             return this.id;
 451         }
 452 
 453         String getIdWithPrefix() {
 454             String prefix = isMode() ? "create-" : "--";
 455             return prefix + this.id;
 456         }
 457 
 458         String getShortIdWithPrefix() {
 459             return this.shortId == null ? null : "-" + this.shortId;
 460         }
 461 


 720 
 721     private boolean generateBundle(Map<String,? super Object> params)
 722             throws PackagerException {
 723 
 724         boolean bundleCreated = false;
 725 
 726         // the build-root needs to be fetched from the params early,
 727         // to prevent each copy of the params (such as may be used for
 728         // secondary launchers) from generating a separate build-root when
 729         // the default is used (the default is a new temp directory)
 730         // The bundler.cleanup() below would not otherwise be able to
 731         // clean these extra (and unneeded) temp directories.
 732         StandardBundlerParam.BUILD_ROOT.fetchFrom(params);
 733 
 734         for (jdk.jpackage.internal.Bundler bundler : getPlatformBundlers()) {
 735             Map<String, ? super Object> localParams = new HashMap<>(params);
 736             try {
 737                 if (bundler.validate(localParams)) {
 738                     File result =
 739                             bundler.execute(localParams, deployParams.outdir);
 740                     if (!retainBuildRoot) {
 741                         bundler.cleanup(localParams);
 742                     }
 743                     if (result == null) {
 744                         throw new PackagerException("MSG_BundlerFailed",
 745                                 bundler.getID(), bundler.getName());
 746                     }
 747                     bundleCreated = true; // at least one bundle was created
 748                 }
 749             } catch (UnsupportedPlatformException e) {
 750                 Log.debug(MessageFormat.format(
 751                         I18N.getString("MSG_BundlerPlatformException"),
 752                         bundler.getName()));
 753             } catch (ConfigException e) {
 754                 Log.debug(e);
 755                 if (e.getAdvice() != null) {
 756                     Log.error(MessageFormat.format(
 757                             I18N.getString("MSG_BundlerConfigException"),
 758                             bundler.getName(), e.getMessage(), e.getAdvice()));
 759                 } else {
 760                     Log.error(MessageFormat.format(I18N.getString(
 761                             "MSG_BundlerConfigExceptionNoAdvice"),
 762                             bundler.getName(), e.getMessage()));
 763                 }
 764             } catch (RuntimeException re) {
 765                 Log.error(MessageFormat.format(
 766                         I18N.getString("MSG_BundlerRuntimeException"),
 767                         bundler.getName(), re.toString()));
 768                 Log.debug(re);
 769             } finally {
 770                 if (retainBuildRoot) {
 771                     Log.verbose(MessageFormat.format(
 772                             I18N.getString("message.debug-working-directory"),
 773                             (new File(buildRoot)).getAbsolutePath()));
 774                 }
 775             }
 776         }
 777 
 778         return bundleCreated;
 779     }
 780 
 781     private void addResources(DeployParams deployParams,
 782             String inputdir, List<String> inputfiles) {
 783 
 784         if (inputdir == null || inputdir.isEmpty()) {
 785             return;
 786         }
 787 
 788         File baseDir = new File(inputdir);
 789 
 790         if (!baseDir.isDirectory()) {




 108           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
 109 
 110     private DeployParams deployParams = null;
 111     private BundlerType bundleType = null;
 112 
 113     private int pos = 0;
 114     private List<String> argList = null;
 115 
 116     private List<CLIOptions> allOptions = null;
 117 
 118     private ArrayList<String> files = null;
 119 
 120     private String input = null;
 121     private String output = null;
 122 
 123     private boolean hasMainJar = false;
 124     private boolean hasMainClass = false;
 125     private boolean hasMainModule = false;
 126     private boolean hasTargetFormat = false;
 127     private boolean hasAppImage = false;
 128     public boolean userProvidedBuildRoot = false;
 129 
 130     private String buildRoot = null;
 131     private String mainJarPath = null;
 132 
 133     private static boolean jreInstaller = false;
 134 
 135     private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
 136 
 137     private List<SecondaryLauncherArguments> secondaryLaunchers = null;
 138 
 139     private static Map<String, CLIOptions> argIds = new HashMap<>();
 140     private static Map<String, CLIOptions> argShortIds = new HashMap<>();
 141 
 142     {
 143         // init maps for parsing arguments
 144         EnumSet<CLIOptions> options = EnumSet.allOf(CLIOptions.class);
 145 
 146         options.forEach(option -> {
 147             argIds.put(option.getIdWithPrefix(), option);
 148             if (option.getShortIdWithPrefix() != null) {


 293             }
 294 
 295             ArrayList<Map<String, ? super Object>> associationList =
 296                 new ArrayList<Map<String, ? super Object>>();
 297 
 298             associationList.add(args);
 299 
 300             // check that we really add _another_ value to the list
 301             setOptionValue("file-associations", associationList);
 302 
 303         }),
 304 
 305         SECONDARY_LAUNCHER ("secondary-launcher",
 306                     OptionCategories.PROPERTY, () -> {
 307             context().secondaryLaunchers.add(
 308                 new SecondaryLauncherArguments(popArg()));
 309         }),
 310 
 311         BUILD_ROOT ("build-root", OptionCategories.PROPERTY, () -> {
 312             context().buildRoot = popArg();
 313             context().userProvidedBuildRoot = true;
 314             setOptionValue("build-root", context().buildRoot);
 315         }),
 316 
 317         INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
 318 
 319         PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY, ()-> {
 320             setOptionValue("app-image", popArg());
 321             context().hasAppImage = true;
 322         }),
 323 
 324         PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
 325 
 326         MAIN_JAR ("main-jar", "j", OptionCategories.PROPERTY, () -> {
 327             context().mainJarPath = popArg();
 328             context().hasMainJar = true;
 329             setOptionValue("main-jar", context().mainJarPath);
 330         }),
 331 
 332         MODULE ("module", "m", OptionCategories.MODULAR, () -> {
 333             context().hasMainModule = true;


 421             this(id, shortId, category, null);
 422         }
 423 
 424         private CLIOptions(String id,
 425                 OptionCategories category, ArgAction action) {
 426             this(id, null, category, action);
 427         }
 428 
 429         private CLIOptions(String id, String shortId,
 430                            OptionCategories category, ArgAction action) {
 431             this.id = id;
 432             this.shortId = shortId;
 433             this.action = action;
 434             this.category = category;
 435         }
 436 
 437         static void setContext(Arguments context) {
 438             argContext = context;
 439         }
 440 
 441         public static Arguments context() {
 442             if (argContext != null) {
 443                 return argContext;
 444             } else {
 445                 throw new RuntimeException("Argument context is not set.");
 446             }
 447         }
 448 
 449         public String getId() {
 450             return this.id;
 451         }
 452 
 453         String getIdWithPrefix() {
 454             String prefix = isMode() ? "create-" : "--";
 455             return prefix + this.id;
 456         }
 457 
 458         String getShortIdWithPrefix() {
 459             return this.shortId == null ? null : "-" + this.shortId;
 460         }
 461 


 720 
 721     private boolean generateBundle(Map<String,? super Object> params)
 722             throws PackagerException {
 723 
 724         boolean bundleCreated = false;
 725 
 726         // the build-root needs to be fetched from the params early,
 727         // to prevent each copy of the params (such as may be used for
 728         // secondary launchers) from generating a separate build-root when
 729         // the default is used (the default is a new temp directory)
 730         // The bundler.cleanup() below would not otherwise be able to
 731         // clean these extra (and unneeded) temp directories.
 732         StandardBundlerParam.BUILD_ROOT.fetchFrom(params);
 733 
 734         for (jdk.jpackage.internal.Bundler bundler : getPlatformBundlers()) {
 735             Map<String, ? super Object> localParams = new HashMap<>(params);
 736             try {
 737                 if (bundler.validate(localParams)) {
 738                     File result =
 739                             bundler.execute(localParams, deployParams.outdir);
 740                     if (!userProvidedBuildRoot) {
 741                         bundler.cleanup(localParams);
 742                     }
 743                     if (result == null) {
 744                         throw new PackagerException("MSG_BundlerFailed",
 745                                 bundler.getID(), bundler.getName());
 746                     }
 747                     bundleCreated = true; // at least one bundle was created
 748                 }
 749             } catch (UnsupportedPlatformException e) {
 750                 Log.debug(MessageFormat.format(
 751                         I18N.getString("MSG_BundlerPlatformException"),
 752                         bundler.getName()));
 753             } catch (ConfigException e) {
 754                 Log.debug(e);
 755                 if (e.getAdvice() != null) {
 756                     Log.error(MessageFormat.format(
 757                             I18N.getString("MSG_BundlerConfigException"),
 758                             bundler.getName(), e.getMessage(), e.getAdvice()));
 759                 } else {
 760                     Log.error(MessageFormat.format(I18N.getString(
 761                             "MSG_BundlerConfigExceptionNoAdvice"),
 762                             bundler.getName(), e.getMessage()));
 763                 }
 764             } catch (RuntimeException re) {
 765                 Log.error(MessageFormat.format(
 766                         I18N.getString("MSG_BundlerRuntimeException"),
 767                         bundler.getName(), re.toString()));
 768                 Log.debug(re);
 769             } finally {
 770                 if (userProvidedBuildRoot) {
 771                     Log.verbose(MessageFormat.format(
 772                             I18N.getString("message.debug-working-directory"),
 773                             (new File(buildRoot)).getAbsolutePath()));
 774                 }
 775             }
 776         }
 777 
 778         return bundleCreated;
 779     }
 780 
 781     private void addResources(DeployParams deployParams,
 782             String inputdir, List<String> inputfiles) {
 783 
 784         if (inputdir == null || inputdir.isEmpty()) {
 785             return;
 786         }
 787 
 788         File baseDir = new File(inputdir);
 789 
 790         if (!baseDir.isDirectory()) {


< prev index next >