< prev index next >

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

Print this page




  47 import java.util.stream.Stream;
  48 import java.util.regex.Matcher;
  49 import java.util.regex.Pattern;
  50 
  51 /**
  52  * Arguments
  53  *
  54  * This class encapsulates and processes the command line arguments,
  55  * in effect, implementing all the work of jpackage tool.
  56  *
  57  * The primary entry point, processArguments():
  58  * Processes and validates command line arguments, constructing DeployParams.
  59  * Validates the DeployParams, and generate the BundleParams.
  60  * Generates List of Bundlers from BundleParams valid for this platform.
  61  * Executes each Bundler in the list.
  62  */
  63 public class Arguments {
  64     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  65             "jdk.jpackage.internal.resources.MainResources");
  66 
  67     private static final String IMAGE_MODE = "image";
  68     private static final String INSTALLER_MODE = "installer";
  69 
  70     private static final String FA_EXTENSIONS = "extension";
  71     private static final String FA_CONTENT_TYPE = "mime-type";
  72     private static final String FA_DESCRIPTION = "description";
  73     private static final String FA_ICON = "icon";
  74 
  75     public static final BundlerParamInfo<Boolean> CREATE_IMAGE =
  76             new StandardBundlerParam<>(
  77                     IMAGE_MODE,
  78                     Boolean.class,
  79                     p -> Boolean.FALSE,
  80                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
  81                             true : Boolean.valueOf(s));
  82 
  83     public static final BundlerParamInfo<Boolean> CREATE_INSTALLER =
  84             new StandardBundlerParam<>(
  85                     INSTALLER_MODE,
  86                     Boolean.class,
  87                     p -> Boolean.FALSE,
  88                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
  89                             true : Boolean.valueOf(s));
  90 
  91     // regexp for parsing args (for example, for additional launchers)
  92     private static Pattern pattern = Pattern.compile(
  93           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
  94 
  95     private DeployParams deployParams = null;
  96     private BundlerType bundleType = null;
  97 
  98     private int pos = 0;
  99     private List<String> argList = null;
 100 
 101     private List<CLIOptions> allOptions = null;
 102 
 103     private ArrayList<String> files = null;
 104 
 105     private String input = null;
 106     private String output = null;
 107 
 108     private boolean hasMainJar = false;
 109     private boolean hasMainClass = false;
 110     private boolean hasMainModule = false;
 111     private boolean hasTargetFormat = false;
 112     private boolean hasAppImage = false;
 113     public boolean userProvidedBuildRoot = false;
 114 
 115     private String buildRoot = null;
 116     private String mainJarPath = null;
 117 
 118     private static boolean runtimeInstaller = false;
 119 
 120     private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
 121 
 122     private List<AddLauncherArguments> addLaunchers = null;
 123 
 124     private static Map<String, CLIOptions> argIds = new HashMap<>();


 135     }
 136 
 137     public Arguments(String[] args) throws PackagerException {
 138         argList = new ArrayList<String>(args.length);
 139         for (String arg : args) {
 140             argList.add(arg);
 141         }
 142         Log.debug ("\njpackage argument list: \n" + argList + "\n");
 143         pos = 0;
 144 
 145         deployParams = new DeployParams();
 146         bundleType = BundlerType.NONE;
 147 
 148         allOptions = new ArrayList<>();
 149 
 150         addLaunchers = new ArrayList<>();
 151     }
 152 
 153     // CLIOptions is public for DeployParamsTest
 154     public enum CLIOptions {
 155         CREATE_IMAGE(IMAGE_MODE, OptionCategories.MODE, () -> {
 156             context().bundleType = BundlerType.IMAGE;
 157             context().deployParams.setTargetFormat("image");
 158             setOptionValue(IMAGE_MODE, true);
 159         }),
 160 
 161         CREATE_INSTALLER(INSTALLER_MODE, OptionCategories.MODE, () -> {
 162             setOptionValue(INSTALLER_MODE, true);
 163             context().bundleType = BundlerType.INSTALLER;
 164             String format = "installer";
 165             context().deployParams.setTargetFormat(format);
 166         }),
 167 
 168         INSTALLER_TYPE("installer-type", OptionCategories.PROPERTY, () -> {
 169             String type = popArg();
 170             if (BundlerType.INSTALLER.equals(context().bundleType)) {
 171                 context().deployParams.setTargetFormat(type);
 172                 context().hasTargetFormat = true;
 173             }
 174             setOptionValue("installer-type", type);
 175         }),
 176 
 177         INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
 178             context().input = popArg();


 191         APPCLASS ("main-class", OptionCategories.PROPERTY, () -> {
 192             context().hasMainClass = true;
 193             setOptionValue("main-class", popArg());
 194         }),
 195 
 196         NAME ("name", "n", OptionCategories.PROPERTY),
 197 
 198         IDENTIFIER ("identifier", OptionCategories.PROPERTY),
 199 
 200         VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
 201             setOptionValue("verbose", true);
 202             Log.setVerbose(true);
 203         }),
 204 
 205         RESOURCE_DIR("resource-dir",
 206                 OptionCategories.PROPERTY, () -> {
 207             String resourceDir = popArg();
 208             setOptionValue("resource-dir", resourceDir);
 209         }),
 210 
 211         FILES ("files", "f", OptionCategories.PROPERTY, () -> {
 212               context().files = new ArrayList<>();
 213               String files = popArg();
 214               context().files.addAll(
 215                       Arrays.asList(files.split(File.pathSeparator)));
 216         }),
 217 
 218         ARGUMENTS ("arguments", OptionCategories.PROPERTY, () -> {
 219             List<String> arguments = getArgumentList(popArg());
 220             setOptionValue("arguments", arguments);
 221         }),
 222 
 223         ICON ("icon", OptionCategories.PROPERTY),
 224 
 225         COPYRIGHT ("copyright", OptionCategories.PROPERTY),
 226 
 227         LICENSE_FILE ("license-file", OptionCategories.PROPERTY),
 228 
 229         VERSION ("app-version", OptionCategories.PROPERTY),
 230 
 231         JAVA_OPTIONS ("java-options", OptionCategories.PROPERTY, () -> {
 232             List<String> args = getArgumentList(popArg());
 233             args.forEach(a -> setOptionValue("java-options", a));
 234         }),
 235 
 236         FILE_ASSOCIATIONS ("file-associations",
 237                 OptionCategories.PROPERTY, () -> {


 255                 args.put(StandardBundlerParam.FA_DESCRIPTION.getID(), desc);
 256             }
 257 
 258             String icon = initialMap.get(FA_ICON);
 259             if (icon != null) {
 260                 args.put(StandardBundlerParam.FA_ICON.getID(), icon);
 261             }
 262 
 263             ArrayList<Map<String, ? super Object>> associationList =
 264                 new ArrayList<Map<String, ? super Object>>();
 265 
 266             associationList.add(args);
 267 
 268             // check that we really add _another_ value to the list
 269             setOptionValue("file-associations", associationList);
 270 
 271         }),
 272 
 273         ADD_LAUNCHER ("add-launcher",
 274                     OptionCategories.PROPERTY, () -> {








 275             context().addLaunchers.add(
 276                 new AddLauncherArguments(popArg()));
 277         }),
 278 
 279         TEMP_ROOT ("temp-root", OptionCategories.PROPERTY, () -> {
 280             context().buildRoot = popArg();
 281             context().userProvidedBuildRoot = true;
 282             setOptionValue("temp-root", context().buildRoot);
 283         }),
 284 
 285         INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
 286 
 287         PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY, ()-> {
 288             setOptionValue("app-image", popArg());
 289             context().hasAppImage = true;
 290         }),
 291 
 292         PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
 293 
 294         MAIN_JAR ("main-jar",  OptionCategories.PROPERTY, () -> {
 295             context().mainJarPath = popArg();
 296             context().hasMainJar = true;


 402             this.category = category;
 403         }
 404 
 405         static void setContext(Arguments context) {
 406             argContext = context;
 407         }
 408 
 409         public static Arguments context() {
 410             if (argContext != null) {
 411                 return argContext;
 412             } else {
 413                 throw new RuntimeException("Argument context is not set.");
 414             }
 415         }
 416 
 417         public String getId() {
 418             return this.id;
 419         }
 420 
 421         String getIdWithPrefix() {
 422             String prefix = isMode() ? "create-" : "--";
 423             return prefix + this.id;
 424         }
 425 
 426         String getShortIdWithPrefix() {
 427             return this.shortId == null ? null : "-" + this.shortId;
 428         }
 429 
 430         void execute() {
 431             if (action != null) {
 432                 action.execute();
 433             } else {
 434                 defaultAction();
 435             }
 436         }
 437 
 438         boolean isMode() {
 439             return category == OptionCategories.MODE;
 440         }
 441 
 442         OptionCategories getCategory() {


 506 
 507             if (allOptions.isEmpty() || !allOptions.get(0).isMode()) {
 508                 // first argument should always be a mode.
 509                 throw new PackagerException("ERR_MissingMode");
 510             }
 511 
 512             if (hasMainJar && !hasMainClass) {
 513                 // try to get main-class from manifest
 514                 String mainClass = getMainClassFromManifest();
 515                 if (mainClass != null) {
 516                     CLIOptions.setOptionValue(
 517                             CLIOptions.APPCLASS.getId(), mainClass);
 518                 }
 519             }
 520 
 521             // display warning for arguments that are not supported
 522             // for current configuration.
 523 
 524             validateArguments();
 525 
 526             addResources(deployParams, input, files);
 527 
 528             deployParams.setBundleType(bundleType);
 529 
 530             List<Map<String, ? super Object>> launchersAsMap =
 531                     new ArrayList<>();
 532 
 533             for (AddLauncherArguments sl : addLaunchers) {
 534                 launchersAsMap.add(sl.getLauncherMap());
 535             }
 536 
 537             deployParams.addBundleArgument(
 538                     StandardBundlerParam.ADD_LAUNCHERS.getID(),
 539                     launchersAsMap);
 540 
 541             // at this point deployParams should be already configured
 542 
 543             deployParams.validate();
 544 
 545             BundleParams bp = deployParams.getBundleParams();
 546 


 571             return generateBundle(bp.getBundleParamsAsMap());
 572         } catch (Exception e) {
 573             if (Log.isVerbose()) {
 574                 throw e;
 575             } else {
 576                 String msg1 = e.getMessage();
 577                 Log.error(msg1);
 578                 if (e.getCause() != null && e.getCause() != e) {
 579                     String msg2 = e.getCause().getMessage();
 580                     if (!msg1.contains(msg2)) {
 581                         Log.error(msg2);
 582                     }
 583                 }
 584                 return false;
 585             }
 586         }
 587     }
 588 
 589     private void validateArguments() throws PackagerException {
 590         CLIOptions mode = allOptions.get(0);
 591         boolean imageOnly = (mode == CLIOptions.CREATE_IMAGE);
 592         boolean hasAppImage = allOptions.contains(
 593                 CLIOptions.PREDEFINED_APP_IMAGE);
 594         boolean hasRuntime = allOptions.contains(
 595                 CLIOptions.PREDEFINED_RUNTIME_IMAGE);
 596         boolean installerOnly = !imageOnly && hasAppImage;
 597         boolean runtimeInstall = !imageOnly && hasRuntime && !hasAppImage &&
 598                 !hasMainModule && !hasMainJar;
 599 
 600         for (CLIOptions option : allOptions) {
 601             if (!ValidOptions.checkIfSupported(option)) {
 602                 // includes option valid only on different platform
 603                 throw new PackagerException("ERR_UnsupportedOption",
 604                         option.getIdWithPrefix());
 605             }
 606             if (imageOnly) {
 607                 if (!ValidOptions.checkIfImageSupported(option)) {
 608                     throw new PackagerException("ERR_NotImageOption",
 609                         option.getIdWithPrefix());
 610                 }
 611             } else if (installerOnly || runtimeInstall) {


 711                     pe = new PackagerException(re,
 712                             "MSG_BundlerRuntimeException",
 713                             bundler.getName(), re.toString());
 714                 }
 715             } finally {
 716                 if (userProvidedBuildRoot) {
 717                     Log.verbose(MessageFormat.format(
 718                             I18N.getString("message.debug-working-directory"),
 719                             (new File(buildRoot)).getAbsolutePath()));
 720                 }
 721             }
 722         }
 723         if (pe != null) {
 724             // throw packager exception only after trying all bundlers
 725             throw pe;
 726         }
 727         return bundleCreated;
 728     }
 729 
 730     private void addResources(DeployParams deployParams,
 731             String inputdir, List<String> inputfiles) {
 732 
 733         if (inputdir == null || inputdir.isEmpty()) {
 734             return;
 735         }
 736 
 737         File baseDir = new File(inputdir);
 738 
 739         if (!baseDir.isDirectory()) {
 740             Log.error(
 741                     "Unable to add resources: \"--input\" is not a directory.");
 742             return;

 743         }
 744 
 745         List<String> fileNames;
 746         if (inputfiles != null) {
 747             fileNames = inputfiles;
 748         } else {
 749             // "-files" is omitted, all files in input cdir (which
 750             // is a mandatory argument in this case) will be packaged.
 751             fileNames = new ArrayList<>();
 752             try (Stream<Path> files = Files.list(baseDir.toPath())) {
 753                 files.forEach(file -> fileNames.add(
 754                         file.getFileName().toString()));
 755             } catch (IOException e) {
 756                 Log.error("Unable to add resources: " + e.getMessage());
 757             }
 758         }
 759         fileNames.forEach(file -> deployParams.addResource(baseDir, file));
 760 
 761         deployParams.setClasspath();
 762     }
 763 
 764     static boolean isCLIOption(String arg) {
 765         return toCLIOption(arg) != null;
 766     }
 767 
 768     static CLIOptions toCLIOption(String arg) {
 769         CLIOptions option;
 770         if ((option = argIds.get(arg)) == null) {
 771             option = argShortIds.get(arg);
 772         }
 773         return option;
 774     }
 775 
 776     static Map<String, String> getArgumentMap(String inputString) {
 777         Map<String, String> map = new HashMap<>();




  47 import java.util.stream.Stream;
  48 import java.util.regex.Matcher;
  49 import java.util.regex.Pattern;
  50 
  51 /**
  52  * Arguments
  53  *
  54  * This class encapsulates and processes the command line arguments,
  55  * in effect, implementing all the work of jpackage tool.
  56  *
  57  * The primary entry point, processArguments():
  58  * Processes and validates command line arguments, constructing DeployParams.
  59  * Validates the DeployParams, and generate the BundleParams.
  60  * Generates List of Bundlers from BundleParams valid for this platform.
  61  * Executes each Bundler in the list.
  62  */
  63 public class Arguments {
  64     private static final ResourceBundle I18N = ResourceBundle.getBundle(
  65             "jdk.jpackage.internal.resources.MainResources");
  66 
  67     private static final String APPIMAGE_MODE = "create-app-image";
  68     private static final String INSTALLER_MODE = "create-installer";
  69 
  70     private static final String FA_EXTENSIONS = "extension";
  71     private static final String FA_CONTENT_TYPE = "mime-type";
  72     private static final String FA_DESCRIPTION = "description";
  73     private static final String FA_ICON = "icon";
  74 
  75     public static final BundlerParamInfo<Boolean> CREATE_APP_IMAGE =
  76             new StandardBundlerParam<>(
  77                     APPIMAGE_MODE,
  78                     Boolean.class,
  79                     p -> Boolean.FALSE,
  80                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
  81                             true : Boolean.valueOf(s));
  82 
  83     public static final BundlerParamInfo<Boolean> CREATE_INSTALLER =
  84             new StandardBundlerParam<>(
  85                     INSTALLER_MODE,
  86                     Boolean.class,
  87                     p -> Boolean.FALSE,
  88                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
  89                             true : Boolean.valueOf(s));
  90 
  91     // regexp for parsing args (for example, for additional launchers)
  92     private static Pattern pattern = Pattern.compile(
  93           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
  94 
  95     private DeployParams deployParams = null;
  96     private BundlerType bundleType = null;
  97 
  98     private int pos = 0;
  99     private List<String> argList = null;
 100 
 101     private List<CLIOptions> allOptions = null;
 102 


 103     private String input = null;
 104     private String output = null;
 105 
 106     private boolean hasMainJar = false;
 107     private boolean hasMainClass = false;
 108     private boolean hasMainModule = false;
 109     private boolean hasTargetFormat = false;
 110     private boolean hasAppImage = false;
 111     public boolean userProvidedBuildRoot = false;
 112 
 113     private String buildRoot = null;
 114     private String mainJarPath = null;
 115 
 116     private static boolean runtimeInstaller = false;
 117 
 118     private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
 119 
 120     private List<AddLauncherArguments> addLaunchers = null;
 121 
 122     private static Map<String, CLIOptions> argIds = new HashMap<>();


 133     }
 134 
 135     public Arguments(String[] args) throws PackagerException {
 136         argList = new ArrayList<String>(args.length);
 137         for (String arg : args) {
 138             argList.add(arg);
 139         }
 140         Log.debug ("\njpackage argument list: \n" + argList + "\n");
 141         pos = 0;
 142 
 143         deployParams = new DeployParams();
 144         bundleType = BundlerType.NONE;
 145 
 146         allOptions = new ArrayList<>();
 147 
 148         addLaunchers = new ArrayList<>();
 149     }
 150 
 151     // CLIOptions is public for DeployParamsTest
 152     public enum CLIOptions {
 153         CREATE_APP_IMAGE(APPIMAGE_MODE, OptionCategories.MODE, () -> {
 154             context().bundleType = BundlerType.IMAGE;
 155             context().deployParams.setTargetFormat("image");
 156             setOptionValue(APPIMAGE_MODE, true);
 157         }),
 158 
 159         CREATE_INSTALLER(INSTALLER_MODE, OptionCategories.MODE, () -> {
 160             setOptionValue(INSTALLER_MODE, true);
 161             context().bundleType = BundlerType.INSTALLER;
 162             String format = "installer";
 163             context().deployParams.setTargetFormat(format);
 164         }),
 165 
 166         INSTALLER_TYPE("installer-type", OptionCategories.PROPERTY, () -> {
 167             String type = popArg();
 168             if (BundlerType.INSTALLER.equals(context().bundleType)) {
 169                 context().deployParams.setTargetFormat(type);
 170                 context().hasTargetFormat = true;
 171             }
 172             setOptionValue("installer-type", type);
 173         }),
 174 
 175         INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
 176             context().input = popArg();


 189         APPCLASS ("main-class", OptionCategories.PROPERTY, () -> {
 190             context().hasMainClass = true;
 191             setOptionValue("main-class", popArg());
 192         }),
 193 
 194         NAME ("name", "n", OptionCategories.PROPERTY),
 195 
 196         IDENTIFIER ("identifier", OptionCategories.PROPERTY),
 197 
 198         VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
 199             setOptionValue("verbose", true);
 200             Log.setVerbose(true);
 201         }),
 202 
 203         RESOURCE_DIR("resource-dir",
 204                 OptionCategories.PROPERTY, () -> {
 205             String resourceDir = popArg();
 206             setOptionValue("resource-dir", resourceDir);
 207         }),
 208 







 209         ARGUMENTS ("arguments", OptionCategories.PROPERTY, () -> {
 210             List<String> arguments = getArgumentList(popArg());
 211             setOptionValue("arguments", arguments);
 212         }),
 213 
 214         ICON ("icon", OptionCategories.PROPERTY),
 215 
 216         COPYRIGHT ("copyright", OptionCategories.PROPERTY),
 217 
 218         LICENSE_FILE ("license-file", OptionCategories.PROPERTY),
 219 
 220         VERSION ("app-version", OptionCategories.PROPERTY),
 221 
 222         JAVA_OPTIONS ("java-options", OptionCategories.PROPERTY, () -> {
 223             List<String> args = getArgumentList(popArg());
 224             args.forEach(a -> setOptionValue("java-options", a));
 225         }),
 226 
 227         FILE_ASSOCIATIONS ("file-associations",
 228                 OptionCategories.PROPERTY, () -> {


 246                 args.put(StandardBundlerParam.FA_DESCRIPTION.getID(), desc);
 247             }
 248 
 249             String icon = initialMap.get(FA_ICON);
 250             if (icon != null) {
 251                 args.put(StandardBundlerParam.FA_ICON.getID(), icon);
 252             }
 253 
 254             ArrayList<Map<String, ? super Object>> associationList =
 255                 new ArrayList<Map<String, ? super Object>>();
 256 
 257             associationList.add(args);
 258 
 259             // check that we really add _another_ value to the list
 260             setOptionValue("file-associations", associationList);
 261 
 262         }),
 263 
 264         ADD_LAUNCHER ("add-launcher",
 265                     OptionCategories.PROPERTY, () -> {
 266             String spec = popArg();
 267             String name = null;
 268             String filename = spec;
 269             if (spec.contains("=")) {
 270                 String[] values = spec.split("=", 2);
 271                 name = values[0];
 272                 filename = values[1];
 273             }
 274             context().addLaunchers.add(
 275                 new AddLauncherArguments(name, filename));
 276         }),
 277 
 278         TEMP_ROOT ("temp-root", OptionCategories.PROPERTY, () -> {
 279             context().buildRoot = popArg();
 280             context().userProvidedBuildRoot = true;
 281             setOptionValue("temp-root", context().buildRoot);
 282         }),
 283 
 284         INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
 285 
 286         PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY, ()-> {
 287             setOptionValue("app-image", popArg());
 288             context().hasAppImage = true;
 289         }),
 290 
 291         PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
 292 
 293         MAIN_JAR ("main-jar",  OptionCategories.PROPERTY, () -> {
 294             context().mainJarPath = popArg();
 295             context().hasMainJar = true;


 401             this.category = category;
 402         }
 403 
 404         static void setContext(Arguments context) {
 405             argContext = context;
 406         }
 407 
 408         public static Arguments context() {
 409             if (argContext != null) {
 410                 return argContext;
 411             } else {
 412                 throw new RuntimeException("Argument context is not set.");
 413             }
 414         }
 415 
 416         public String getId() {
 417             return this.id;
 418         }
 419 
 420         String getIdWithPrefix() {
 421             String prefix = isMode() ? "" : "--";
 422             return prefix + this.id;
 423         }
 424 
 425         String getShortIdWithPrefix() {
 426             return this.shortId == null ? null : "-" + this.shortId;
 427         }
 428 
 429         void execute() {
 430             if (action != null) {
 431                 action.execute();
 432             } else {
 433                 defaultAction();
 434             }
 435         }
 436 
 437         boolean isMode() {
 438             return category == OptionCategories.MODE;
 439         }
 440 
 441         OptionCategories getCategory() {


 505 
 506             if (allOptions.isEmpty() || !allOptions.get(0).isMode()) {
 507                 // first argument should always be a mode.
 508                 throw new PackagerException("ERR_MissingMode");
 509             }
 510 
 511             if (hasMainJar && !hasMainClass) {
 512                 // try to get main-class from manifest
 513                 String mainClass = getMainClassFromManifest();
 514                 if (mainClass != null) {
 515                     CLIOptions.setOptionValue(
 516                             CLIOptions.APPCLASS.getId(), mainClass);
 517                 }
 518             }
 519 
 520             // display warning for arguments that are not supported
 521             // for current configuration.
 522 
 523             validateArguments();
 524 
 525             addResources(deployParams, input);
 526 
 527             deployParams.setBundleType(bundleType);
 528 
 529             List<Map<String, ? super Object>> launchersAsMap =
 530                     new ArrayList<>();
 531 
 532             for (AddLauncherArguments sl : addLaunchers) {
 533                 launchersAsMap.add(sl.getLauncherMap());
 534             }
 535 
 536             deployParams.addBundleArgument(
 537                     StandardBundlerParam.ADD_LAUNCHERS.getID(),
 538                     launchersAsMap);
 539 
 540             // at this point deployParams should be already configured
 541 
 542             deployParams.validate();
 543 
 544             BundleParams bp = deployParams.getBundleParams();
 545 


 570             return generateBundle(bp.getBundleParamsAsMap());
 571         } catch (Exception e) {
 572             if (Log.isVerbose()) {
 573                 throw e;
 574             } else {
 575                 String msg1 = e.getMessage();
 576                 Log.error(msg1);
 577                 if (e.getCause() != null && e.getCause() != e) {
 578                     String msg2 = e.getCause().getMessage();
 579                     if (!msg1.contains(msg2)) {
 580                         Log.error(msg2);
 581                     }
 582                 }
 583                 return false;
 584             }
 585         }
 586     }
 587 
 588     private void validateArguments() throws PackagerException {
 589         CLIOptions mode = allOptions.get(0);
 590         boolean imageOnly = (mode == CLIOptions.CREATE_APP_IMAGE);
 591         boolean hasAppImage = allOptions.contains(
 592                 CLIOptions.PREDEFINED_APP_IMAGE);
 593         boolean hasRuntime = allOptions.contains(
 594                 CLIOptions.PREDEFINED_RUNTIME_IMAGE);
 595         boolean installerOnly = !imageOnly && hasAppImage;
 596         boolean runtimeInstall = !imageOnly && hasRuntime && !hasAppImage &&
 597                 !hasMainModule && !hasMainJar;
 598 
 599         for (CLIOptions option : allOptions) {
 600             if (!ValidOptions.checkIfSupported(option)) {
 601                 // includes option valid only on different platform
 602                 throw new PackagerException("ERR_UnsupportedOption",
 603                         option.getIdWithPrefix());
 604             }
 605             if (imageOnly) {
 606                 if (!ValidOptions.checkIfImageSupported(option)) {
 607                     throw new PackagerException("ERR_NotImageOption",
 608                         option.getIdWithPrefix());
 609                 }
 610             } else if (installerOnly || runtimeInstall) {


 710                     pe = new PackagerException(re,
 711                             "MSG_BundlerRuntimeException",
 712                             bundler.getName(), re.toString());
 713                 }
 714             } finally {
 715                 if (userProvidedBuildRoot) {
 716                     Log.verbose(MessageFormat.format(
 717                             I18N.getString("message.debug-working-directory"),
 718                             (new File(buildRoot)).getAbsolutePath()));
 719                 }
 720             }
 721         }
 722         if (pe != null) {
 723             // throw packager exception only after trying all bundlers
 724             throw pe;
 725         }
 726         return bundleCreated;
 727     }
 728 
 729     private void addResources(DeployParams deployParams,
 730             String inputdir) throws PackagerException {
 731 
 732         if (inputdir == null || inputdir.isEmpty()) {
 733             return;
 734         }
 735 
 736         File baseDir = new File(inputdir);
 737 
 738         if (!baseDir.isDirectory()) {
 739             throw new PackagerException("ERR_InputNotDirectory", inputdir);
 740         }
 741         if (!baseDir.canRead()) {
 742             throw new PackagerException("ERR_CannotReadInputDir", inputdir);
 743         }
 744 
 745         List<String> fileNames;





 746         fileNames = new ArrayList<>();
 747         try (Stream<Path> files = Files.list(baseDir.toPath())) {
 748             files.forEach(file -> fileNames.add(
 749                     file.getFileName().toString()));
 750         } catch (IOException e) {
 751             Log.error("Unable to add resources: " + e.getMessage());

 752         }
 753         fileNames.forEach(file -> deployParams.addResource(baseDir, file));
 754 
 755         deployParams.setClasspath();
 756     }
 757 
 758     static boolean isCLIOption(String arg) {
 759         return toCLIOption(arg) != null;
 760     }
 761 
 762     static CLIOptions toCLIOption(String arg) {
 763         CLIOptions option;
 764         if ((option = argIds.get(arg)) == null) {
 765             option = argShortIds.get(arg);
 766         }
 767         return option;
 768     }
 769 
 770     static Map<String, String> getArgumentMap(String inputString) {
 771         Map<String, String> map = new HashMap<>();


< prev index next >