src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java
branchJDK-8200758-branch
changeset 57256 d7c27451f759
parent 57255 f686bda3b831
child 57283 0b0be19f79e4
equal deleted inserted replaced
57255:f686bda3b831 57256:d7c27451f759
    40     private static final ResourceBundle I18N = ResourceBundle.getBundle(
    40     private static final ResourceBundle I18N = ResourceBundle.getBundle(
    41             "jdk.jpackage.internal.resources.WinResources");
    41             "jdk.jpackage.internal.resources.WinResources");
    42 
    42 
    43     public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER =
    43     public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER =
    44             new WindowsBundlerParam<>(
    44             new WindowsBundlerParam<>(
    45             getString("param.exe-bundler.name"),
       
    46             getString("param.exe-bundler.description"),
       
    47             "win.app.bundler",
    45             "win.app.bundler",
    48             WinAppBundler.class,
    46             WinAppBundler.class,
    49             params -> new WinAppBundler(),
    47             params -> new WinAppBundler(),
    50             null);
    48             null);
    51 
    49 
    52     public static final BundlerParamInfo<File> EXE_IMAGE_DIR =
    50     public static final BundlerParamInfo<File> EXE_IMAGE_DIR =
    53             new WindowsBundlerParam<>(
    51             new WindowsBundlerParam<>(
    54             getString("param.image-dir.name"),
       
    55             getString("param.image-dir.description"),
       
    56             "win.exe.imageDir",
    52             "win.exe.imageDir",
    57             File.class,
    53             File.class,
    58             params -> {
    54             params -> {
    59                 File imagesRoot = IMAGES_ROOT.fetchFrom(params);
    55                 File imagesRoot = IMAGES_ROOT.fetchFrom(params);
    60                 if (!imagesRoot.exists()) imagesRoot.mkdirs();
    56                 if (!imagesRoot.exists()) imagesRoot.mkdirs();
    62             },
    58             },
    63             (s, p) -> null);
    59             (s, p) -> null);
    64 
    60 
    65     public static final BundlerParamInfo<File> WIN_APP_IMAGE =
    61     public static final BundlerParamInfo<File> WIN_APP_IMAGE =
    66             new WindowsBundlerParam<>(
    62             new WindowsBundlerParam<>(
    67             getString("param.app-dir.name"),
       
    68             getString("param.app-dir.description"),
       
    69             "win.app.image",
    63             "win.app.image",
    70             File.class,
    64             File.class,
    71             null,
    65             null,
    72             (s, p) -> null);
    66             (s, p) -> null);
    73 
    67 
    74     public static final BundlerParamInfo<UUID> UPGRADE_UUID =
    68     public static final BundlerParamInfo<UUID> UPGRADE_UUID =
    75             new WindowsBundlerParam<>(
    69             new WindowsBundlerParam<>(
    76             I18N.getString("param.upgrade-uuid.name"),
       
    77             I18N.getString("param.upgrade-uuid.description"),
       
    78             Arguments.CLIOptions.WIN_UPGRADE_UUID.getId(),
    70             Arguments.CLIOptions.WIN_UPGRADE_UUID.getId(),
    79             UUID.class,
    71             UUID.class,
    80             params -> UUID.randomUUID(),
    72             params -> UUID.randomUUID(),
    81             (s, p) -> UUID.fromString(s));
    73             (s, p) -> UUID.fromString(s));
    82 
    74 
    83     public static final StandardBundlerParam<Boolean> EXE_SYSTEM_WIDE  =
    75     public static final StandardBundlerParam<Boolean> EXE_SYSTEM_WIDE  =
    84             new StandardBundlerParam<>(
    76             new StandardBundlerParam<>(
    85             getString("param.system-wide.name"),
       
    86             getString("param.system-wide.description"),
       
    87             Arguments.CLIOptions.WIN_PER_USER_INSTALLATION.getId(),
    77             Arguments.CLIOptions.WIN_PER_USER_INSTALLATION.getId(),
    88             Boolean.class,
    78             Boolean.class,
    89             params -> true, // default to system wide
    79             params -> true, // default to system wide
    90             (s, p) -> (s == null || "null".equalsIgnoreCase(s))? null
    80             (s, p) -> (s == null || "null".equalsIgnoreCase(s))? null
    91                     : Boolean.valueOf(s)
    81                     : Boolean.valueOf(s)
    92             );
    82             );
    93     public static final StandardBundlerParam<String> PRODUCT_VERSION =
    83     public static final StandardBundlerParam<String> PRODUCT_VERSION =
    94             new StandardBundlerParam<>(
    84             new StandardBundlerParam<>(
    95                     getString("param.product-version.name"),
       
    96                     getString("param.product-version.description"),
       
    97                     "win.msi.productVersion",
    85                     "win.msi.productVersion",
    98                     String.class,
    86                     String.class,
    99                     VERSION::fetchFrom,
    87                     VERSION::fetchFrom,
   100                     (s, p) -> s
    88                     (s, p) -> s
   101             );
    89             );
   102 
    90 
   103     public static final StandardBundlerParam<Boolean> MENU_HINT =
    91     public static final StandardBundlerParam<Boolean> MENU_HINT =
   104         new WindowsBundlerParam<>(
    92         new WindowsBundlerParam<>(
   105                 getString("param.menu-shortcut-hint.name"),
       
   106                 getString("param.menu-shortcut-hint.description"),
       
   107                 Arguments.CLIOptions.WIN_MENU_HINT.getId(),
    93                 Arguments.CLIOptions.WIN_MENU_HINT.getId(),
   108                 Boolean.class,
    94                 Boolean.class,
   109                 params -> false,
    95                 params -> false,
   110                 (s, p) -> (s == null ||
    96                 (s, p) -> (s == null ||
   111                         "null".equalsIgnoreCase(s))? true : Boolean.valueOf(s)
    97                         "null".equalsIgnoreCase(s))? true : Boolean.valueOf(s)
   112         );
    98         );
   113 
    99 
   114     public static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
   100     public static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
   115         new WindowsBundlerParam<>(
   101         new WindowsBundlerParam<>(
   116                 getString("param.desktop-shortcut-hint.name"),
       
   117                 getString("param.desktop-shortcut-hint.description"),
       
   118                 Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(),
   102                 Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(),
   119                 Boolean.class,
   103                 Boolean.class,
   120                 params -> false,
   104                 params -> false,
   121                 (s, p) -> (s == null ||
   105                 (s, p) -> (s == null ||
   122                        "null".equalsIgnoreCase(s))? false : Boolean.valueOf(s)
   106                        "null".equalsIgnoreCase(s))? false : Boolean.valueOf(s)
   126     private final static String DEFAULT_JRE_EXE_TEMPLATE = "template.jre.iss";
   110     private final static String DEFAULT_JRE_EXE_TEMPLATE = "template.jre.iss";
   127     private static final String TOOL_INNO_SETUP_COMPILER = "iscc.exe";
   111     private static final String TOOL_INNO_SETUP_COMPILER = "iscc.exe";
   128 
   112 
   129     public static final BundlerParamInfo<String>
   113     public static final BundlerParamInfo<String>
   130             TOOL_INNO_SETUP_COMPILER_EXECUTABLE = new WindowsBundlerParam<>(
   114             TOOL_INNO_SETUP_COMPILER_EXECUTABLE = new WindowsBundlerParam<>(
   131             getString("param.iscc-path.name"),
       
   132             getString("param.iscc-path.description"),
       
   133             "win.exe.iscc.exe",
   115             "win.exe.iscc.exe",
   134             String.class,
   116             String.class,
   135             params -> {
   117             params -> {
   136                 for (String dirString : (System.getenv("PATH")
   118                 for (String dirString : (System.getenv("PATH")
   137                         + ";C:\\Program Files (x86)\\Inno Setup 5;"
   119                         + ";C:\\Program Files (x86)\\Inno Setup 5;"
   370                     outdir.getAbsolutePath());
   352                     outdir.getAbsolutePath());
   371         }
   353         }
   372 
   354 
   373         String tempDirectory = WindowsDefender.getUserTempDirectory();
   355         String tempDirectory = WindowsDefender.getUserTempDirectory();
   374         if (Arguments.CLIOptions.context().userProvidedBuildRoot) {
   356         if (Arguments.CLIOptions.context().userProvidedBuildRoot) {
   375             tempDirectory = BUILD_ROOT.fetchFrom(p).getAbsolutePath();
   357             tempDirectory = TEMP_ROOT.fetchFrom(p).getAbsolutePath();
   376         }
   358         }
   377         if (WindowsDefender.isThereAPotentialWindowsDefenderIssue(
   359         if (WindowsDefender.isThereAPotentialWindowsDefenderIssue(
   378                 tempDirectory)) {
   360                 tempDirectory)) {
   379             Log.error(MessageFormat.format(
   361             Log.error(MessageFormat.format(
   380                     getString("message.potential.windows.defender.issue"),
   362                     getString("message.potential.windows.defender.issue"),
   534                 WIN_APP_IMAGE.fetchFrom(p).toPath().toAbsolutePath().toString();
   516                 WIN_APP_IMAGE.fetchFrom(p).toPath().toAbsolutePath().toString();
   535         data.put("APPLICATION_IMAGE", innosetupEscape(imagePathString));
   517         data.put("APPLICATION_IMAGE", innosetupEscape(imagePathString));
   536         Log.verbose("setting APPLICATION_IMAGE to " +
   518         Log.verbose("setting APPLICATION_IMAGE to " +
   537                 innosetupEscape(imagePathString) + " for InnoSetup");
   519                 innosetupEscape(imagePathString) + " for InnoSetup");
   538 
   520 
   539         StringBuilder secondaryLaunchersCfg = new StringBuilder();
   521         StringBuilder addLaunchersCfg = new StringBuilder();
   540         for (Map<String, ? super Object>
   522         for (Map<String, ? super Object>
   541                 launcher : SECONDARY_LAUNCHERS.fetchFrom(p)) {
   523                 launcher : ADD_LAUNCHERS.fetchFrom(p)) {
   542             String application_name = APP_NAME.fetchFrom(launcher);
   524             String application_name = APP_NAME.fetchFrom(launcher);
   543             if (MENU_HINT.fetchFrom(launcher)) {
   525             if (MENU_HINT.fetchFrom(launcher)) {
   544                 // Name: "{group}\APPLICATION_NAME";
   526                 // Name: "{group}\APPLICATION_NAME";
   545                 // Filename: "{app}\APPLICATION_NAME.exe";
   527                 // Filename: "{app}\APPLICATION_NAME.exe";
   546                 // IconFilename: "{app}\APPLICATION_NAME.ico"
   528                 // IconFilename: "{app}\APPLICATION_NAME.ico"
   547                 secondaryLaunchersCfg.append("Name: \"{group}\\");
   529                 addLaunchersCfg.append("Name: \"{group}\\");
   548                 secondaryLaunchersCfg.append(application_name);
   530                 addLaunchersCfg.append(application_name);
   549                 secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
   531                 addLaunchersCfg.append("\"; Filename: \"{app}\\");
   550                 secondaryLaunchersCfg.append(application_name);
   532                 addLaunchersCfg.append(application_name);
   551                 secondaryLaunchersCfg.append(".exe\"; IconFilename: \"{app}\\");
   533                 addLaunchersCfg.append(".exe\"; IconFilename: \"{app}\\");
   552                 secondaryLaunchersCfg.append(application_name);
   534                 addLaunchersCfg.append(application_name);
   553                 secondaryLaunchersCfg.append(".ico\"\r\n");
   535                 addLaunchersCfg.append(".ico\"\r\n");
   554             }
   536             }
   555             if (SHORTCUT_HINT.fetchFrom(launcher)) {
   537             if (SHORTCUT_HINT.fetchFrom(launcher)) {
   556                 // Name: "{commondesktop}\APPLICATION_NAME";
   538                 // Name: "{commondesktop}\APPLICATION_NAME";
   557                 // Filename: "{app}\APPLICATION_NAME.exe";
   539                 // Filename: "{app}\APPLICATION_NAME.exe";
   558                 // IconFilename: "{app}\APPLICATION_NAME.ico"
   540                 // IconFilename: "{app}\APPLICATION_NAME.ico"
   559                 secondaryLaunchersCfg.append("Name: \"{commondesktop}\\");
   541                 addLaunchersCfg.append("Name: \"{commondesktop}\\");
   560                 secondaryLaunchersCfg.append(application_name);
   542                 addLaunchersCfg.append(application_name);
   561                 secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
   543                 addLaunchersCfg.append("\"; Filename: \"{app}\\");
   562                 secondaryLaunchersCfg.append(application_name);
   544                 addLaunchersCfg.append(application_name);
   563                 secondaryLaunchersCfg.append(".exe\";  IconFilename: \"{app}\\");
   545                 addLaunchersCfg.append(".exe\";  IconFilename: \"{app}\\");
   564                 secondaryLaunchersCfg.append(application_name);
   546                 addLaunchersCfg.append(application_name);
   565                 secondaryLaunchersCfg.append(".ico\"\r\n");
   547                 addLaunchersCfg.append(".ico\"\r\n");
   566             }
   548             }
   567         }
   549         }
   568         data.put("SECONDARY_LAUNCHERS", secondaryLaunchersCfg.toString());
   550         data.put("ADD_LAUNCHERS", addLaunchersCfg.toString());
   569 
   551 
   570         StringBuilder registryEntries = new StringBuilder();
   552         StringBuilder registryEntries = new StringBuilder();
   571         String regName = APP_REGISTRY_NAME.fetchFrom(p);
   553         String regName = APP_REGISTRY_NAME.fetchFrom(p);
   572         List<Map<String, ? super Object>> fetchFrom =
   554         List<Map<String, ? super Object>> fetchFrom =
   573                 FILE_ASSOCIATIONS.fetchFrom(p);
   555                 FILE_ASSOCIATIONS.fetchFrom(p);
   718                     registryEntries.toString());
   700                     registryEntries.toString());
   719         } else {
   701         } else {
   720             data.put("FILE_ASSOCIATIONS", "");
   702             data.put("FILE_ASSOCIATIONS", "");
   721         }
   703         }
   722 
   704 
   723         // TODO - alternate template for JRE installer
   705         String iss = StandardBundlerParam.isRuntimeInstaller(p) ?
   724         String iss = RUNTIME_INSTALLER.fetchFrom(p) ?
       
   725                 DEFAULT_JRE_EXE_TEMPLATE : DEFAULT_EXE_PROJECT_TEMPLATE;
   706                 DEFAULT_JRE_EXE_TEMPLATE : DEFAULT_EXE_PROJECT_TEMPLATE;
   726 
   707 
   727         Writer w = new BufferedWriter(new FileWriter(
   708         Writer w = new BufferedWriter(new FileWriter(
   728                 getConfig_ExeProjectFile(p)));
   709                 getConfig_ExeProjectFile(p)));
   729 
   710