562 throw new PackagerException("ERR_NoAddLauncherName"); 563 } 564 // same rules apply to additional launcher names as app name 565 DeployParams.validateName(slName, false); 566 for (String usedName : usedNames) { 567 if (slName.equals(usedName)) { 568 throw new PackagerException("ERR_NoUniqueName"); 569 } 570 } 571 usedNames.add(slName); 572 } 573 if (runtimeInstaller && bp.getName() == null) { 574 throw new PackagerException("ERR_NoJreInstallerName"); 575 } 576 577 return generateBundle(bp.getBundleParamsAsMap()); 578 } catch (Exception e) { 579 if (Log.isVerbose()) { 580 throw e; 581 } else { 582 Log.error(e.getMessage()); 583 if (e.getCause() != null && e.getCause() != e) { 584 Log.error(e.getCause().getMessage()); 585 } 586 return false; 587 } 588 } 589 } 590 591 private void validateArguments() throws PackagerException { 592 CLIOptions mode = allOptions.get(0); 593 boolean imageOnly = (mode == CLIOptions.CREATE_IMAGE); 594 boolean hasAppImage = allOptions.contains( 595 CLIOptions.PREDEFINED_APP_IMAGE); 596 boolean hasRuntime = allOptions.contains( 597 CLIOptions.PREDEFINED_RUNTIME_IMAGE); 598 boolean installerOnly = !imageOnly && hasAppImage; 599 boolean runtimeInstall = !imageOnly && hasRuntime && !hasAppImage && 600 !hasMainModule && !hasMainJar; 601 602 for (CLIOptions option : allOptions) { 603 if (!ValidOptions.checkIfSupported(option)) { 604 // includes option valid only on different platform 654 return platformBundlers; 655 } 656 657 private boolean generateBundle(Map<String,? super Object> params) 658 throws PackagerException { 659 660 boolean bundleCreated = false; 661 662 // the temp-root needs to be fetched from the params early, 663 // to prevent each copy of the params (such as may be used for 664 // additional launchers) from generating a separate temp-root when 665 // the default is used (the default is a new temp directory) 666 // The bundler.cleanup() below would not otherwise be able to 667 // clean these extra (and unneeded) temp directories. 668 StandardBundlerParam.TEMP_ROOT.fetchFrom(params); 669 List<jdk.jpackage.internal.Bundler> bundlers = getPlatformBundlers(); 670 if (bundlers.isEmpty()) { 671 throw new PackagerException("ERR_InvalidInstallerType", 672 deployParams.getTargetFormat()); 673 } 674 for (jdk.jpackage.internal.Bundler bundler : bundlers) { 675 Map<String, ? super Object> localParams = new HashMap<>(params); 676 try { 677 if (bundler.validate(localParams)) { 678 File result = 679 bundler.execute(localParams, deployParams.outdir); 680 if (!userProvidedBuildRoot) { 681 bundler.cleanup(localParams); 682 } 683 if (result == null) { 684 throw new PackagerException("MSG_BundlerFailed", 685 bundler.getID(), bundler.getName()); 686 } 687 bundleCreated = true; // at least one bundle was created 688 } 689 } catch (UnsupportedPlatformException e) { 690 throw new PackagerException(e, 691 "MSG_BundlerPlatformException", 692 bundler.getName()); 693 } catch (ConfigException e) { 694 Log.debug(e); 695 if (e.getAdvice() != null) { 696 throw new PackagerException(e, 697 "MSG_BundlerConfigException", 698 bundler.getName(), e.getMessage(), e.getAdvice()); 699 } else { 700 throw new PackagerException(e, 701 "MSG_BundlerConfigExceptionNoAdvice", 702 bundler.getName(), e.getMessage()); 703 } 704 } catch (RuntimeException re) { 705 Log.debug(re); 706 throw new PackagerException(re, "MSG_BundlerRuntimeException", 707 bundler.getName(), re.toString()); 708 } finally { 709 if (userProvidedBuildRoot) { 710 Log.verbose(MessageFormat.format( 711 I18N.getString("message.debug-working-directory"), 712 (new File(buildRoot)).getAbsolutePath())); 713 } 714 } 715 } 716 717 return bundleCreated; 718 } 719 720 private void addResources(DeployParams deployParams, 721 String inputdir, List<String> inputfiles) { 722 723 if (inputdir == null || inputdir.isEmpty()) { 724 return; 725 } 726 727 File baseDir = new File(inputdir); 728 729 if (!baseDir.isDirectory()) { 730 Log.error( 731 "Unable to add resources: \"--input\" is not a directory."); 732 return; 733 } 734 735 List<String> fileNames; 736 if (inputfiles != null) { | 562 throw new PackagerException("ERR_NoAddLauncherName"); 563 } 564 // same rules apply to additional launcher names as app name 565 DeployParams.validateName(slName, false); 566 for (String usedName : usedNames) { 567 if (slName.equals(usedName)) { 568 throw new PackagerException("ERR_NoUniqueName"); 569 } 570 } 571 usedNames.add(slName); 572 } 573 if (runtimeInstaller && bp.getName() == null) { 574 throw new PackagerException("ERR_NoJreInstallerName"); 575 } 576 577 return generateBundle(bp.getBundleParamsAsMap()); 578 } catch (Exception e) { 579 if (Log.isVerbose()) { 580 throw e; 581 } else { 582 String msg1 = e.getMessage(); 583 Log.error(msg1); 584 if (e.getCause() != null && e.getCause() != e) { 585 String msg2 = e.getCause().getMessage(); 586 if (!msg1.contains(msg2)) { 587 Log.error(msg2); 588 } 589 } 590 return false; 591 } 592 } 593 } 594 595 private void validateArguments() throws PackagerException { 596 CLIOptions mode = allOptions.get(0); 597 boolean imageOnly = (mode == CLIOptions.CREATE_IMAGE); 598 boolean hasAppImage = allOptions.contains( 599 CLIOptions.PREDEFINED_APP_IMAGE); 600 boolean hasRuntime = allOptions.contains( 601 CLIOptions.PREDEFINED_RUNTIME_IMAGE); 602 boolean installerOnly = !imageOnly && hasAppImage; 603 boolean runtimeInstall = !imageOnly && hasRuntime && !hasAppImage && 604 !hasMainModule && !hasMainJar; 605 606 for (CLIOptions option : allOptions) { 607 if (!ValidOptions.checkIfSupported(option)) { 608 // includes option valid only on different platform 658 return platformBundlers; 659 } 660 661 private boolean generateBundle(Map<String,? super Object> params) 662 throws PackagerException { 663 664 boolean bundleCreated = false; 665 666 // the temp-root needs to be fetched from the params early, 667 // to prevent each copy of the params (such as may be used for 668 // additional launchers) from generating a separate temp-root when 669 // the default is used (the default is a new temp directory) 670 // The bundler.cleanup() below would not otherwise be able to 671 // clean these extra (and unneeded) temp directories. 672 StandardBundlerParam.TEMP_ROOT.fetchFrom(params); 673 List<jdk.jpackage.internal.Bundler> bundlers = getPlatformBundlers(); 674 if (bundlers.isEmpty()) { 675 throw new PackagerException("ERR_InvalidInstallerType", 676 deployParams.getTargetFormat()); 677 } 678 PackagerException pe = null; 679 for (jdk.jpackage.internal.Bundler bundler : bundlers) { 680 Map<String, ? super Object> localParams = new HashMap<>(params); 681 try { 682 if (bundler.validate(localParams)) { 683 File result = 684 bundler.execute(localParams, deployParams.outdir); 685 if (!userProvidedBuildRoot) { 686 bundler.cleanup(localParams); 687 } 688 if (result == null) { 689 throw new PackagerException("MSG_BundlerFailed", 690 bundler.getID(), bundler.getName()); 691 } 692 bundleCreated = true; // at least one bundle was created 693 } 694 Log.verbose(MessageFormat.format( 695 I18N.getString("message.bundle-created"), 696 bundler.getName())); 697 } catch (UnsupportedPlatformException upe) { 698 Log.debug(upe); 699 if (pe == null) { 700 pe = new PackagerException(upe, 701 "MSG_BundlerPlatformException", bundler.getName()); 702 } 703 } catch (ConfigException e) { 704 Log.debug(e); 705 if (pe == null) { 706 pe = (e.getAdvice() != null) ? 707 new PackagerException(e, 708 "MSG_BundlerConfigException", 709 bundler.getName(), e.getMessage(), e.getAdvice()) : 710 new PackagerException(e, 711 "MSG_BundlerConfigExceptionNoAdvice", 712 bundler.getName(), e.getMessage()); 713 } 714 } catch (RuntimeException re) { 715 Log.debug(re); 716 if (pe == null) { 717 pe = new PackagerException(re, 718 "MSG_BundlerRuntimeException", 719 bundler.getName(), re.toString()); 720 } 721 } finally { 722 if (userProvidedBuildRoot) { 723 Log.verbose(MessageFormat.format( 724 I18N.getString("message.debug-working-directory"), 725 (new File(buildRoot)).getAbsolutePath())); 726 } 727 } 728 } 729 if (pe != null) { 730 // throw packager exception only after trying all bundlers 731 throw pe; 732 } 733 return bundleCreated; 734 } 735 736 private void addResources(DeployParams deployParams, 737 String inputdir, List<String> inputfiles) { 738 739 if (inputdir == null || inputdir.isEmpty()) { 740 return; 741 } 742 743 File baseDir = new File(inputdir); 744 745 if (!baseDir.isDirectory()) { 746 Log.error( 747 "Unable to add resources: \"--input\" is not a directory."); 748 return; 749 } 750 751 List<String> fileNames; 752 if (inputfiles != null) { |