8229779: Shortcut creation policy JDK-8200758-branch
authorherrick
Thu, 12 Sep 2019 10:46:10 -0400
branchJDK-8200758-branch
changeset 58116 93b8c1305de2
parent 58115 4a27283b542d
child 58117 69465ef51b0c
8229779: Shortcut creation policy Reviewed-by: asemenyuk, almatvee
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/ValidOptions.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources.properties
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_ja.properties
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_zh_CN.properties
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_ja.properties
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_zh_CN.properties
test/jdk/tools/jpackage/share/SimplePackageTest.java
test/jdk/tools/jpackage/windows/WinMenuTest.java
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java	Thu Sep 12 10:46:10 2019 -0400
@@ -221,6 +221,15 @@
                 (s, p) -> s
         );
 
+    public static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
+        new StandardBundlerParam<>(
+                Arguments.CLIOptions.LINUX_SHORTCUT_HINT.getId(),
+                Boolean.class,
+                params -> false,
+                (s, p) -> (s == null || "null".equalsIgnoreCase(s))
+                        ? false : Boolean.valueOf(s)
+        );
+
     private final static String DEFAULT_ICON = "java32.png";
     private final static String DEFAULT_CONTROL_TEMPLATE = "template.control";
     private final static String DEFAULT_PRERM_TEMPLATE = "template.prerm";
@@ -507,10 +516,11 @@
 
             if (!StandardBundlerParam.isRuntimeInstaller(params)) {
                 // prepare desktop shortcut
-                try (Writer w = Files.newBufferedWriter(
+                if (SHORTCUT_HINT.fetchFrom(params)) {
+                    try (Writer w = Files.newBufferedWriter(
                         getConfig_DesktopShortcutFile(
                                 binDir, addLauncher).toPath())) {
-                    String content = preprocessTextResource(
+                        String content = preprocessTextResource(
                             getConfig_DesktopShortcutFile(binDir,
                             addLauncher).getName(),
                             I18N.getString("resource.menu-shortcut-descriptor"),
@@ -518,7 +528,8 @@
                             addLauncherData,
                             VERBOSE.fetchFrom(params),
                             RESOURCE_DIR.fetchFrom(params));
-                    w.write(content);
+                        w.write(content);
+                    }
                 }
             }
 
@@ -707,10 +718,11 @@
         }
 
         if (!StandardBundlerParam.isRuntimeInstaller(params)) {
-            //prepare desktop shortcut
-            try (Writer w = Files.newBufferedWriter(
+            // prepare desktop shortcut
+            if (SHORTCUT_HINT.fetchFrom(params)) {
+                try (Writer w = Files.newBufferedWriter(
                     getConfig_DesktopShortcutFile(binDir, params).toPath())) {
-                String content = preprocessTextResource(
+                    String content = preprocessTextResource(
                         getConfig_DesktopShortcutFile(
                         binDir, params).getName(),
                         I18N.getString("resource.menu-shortcut-descriptor"),
@@ -718,7 +730,8 @@
                         data,
                         VERBOSE.fetchFrom(params),
                         RESOURCE_DIR.fetchFrom(params));
-                w.write(content);
+                    w.write(content);
+                }
             }
         }
         // prepare control file
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java	Thu Sep 12 10:46:10 2019 -0400
@@ -154,6 +154,15 @@
             },
             (s, p) -> s);
 
+    public static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
+        new StandardBundlerParam<>(
+                Arguments.CLIOptions.LINUX_SHORTCUT_HINT.getId(),
+                Boolean.class,
+                params -> false,
+                (s, p) -> (s == null || "null".equalsIgnoreCase(s))
+                        ? false : Boolean.valueOf(s)
+        );
+
     private final static String DEFAULT_ICON = "java32.png";
     private final static String DEFAULT_SPEC_TEMPLATE = "template.spec";
     private final static String DEFAULT_DESKTOP_FILE_TEMPLATE =
@@ -324,17 +333,19 @@
             addLauncherData.put("DESKTOP_MIMES", "");
 
             // prepare desktop shortcut
-            try (Writer w = Files.newBufferedWriter(
+            if (SHORTCUT_HINT.fetchFrom(params)) {
+                try (Writer w = Files.newBufferedWriter(
                     getConfig_DesktopShortcutFile(binDir,
                             addLauncher).toPath())) {
-                String content = preprocessTextResource(
+                    String content = preprocessTextResource(
                         getConfig_DesktopShortcutFile(binDir,
                         addLauncher).getName(),
                         I18N.getString("resource.menu-shortcut-descriptor"),
                         DEFAULT_DESKTOP_FILE_TEMPLATE, addLauncherData,
                         VERBOSE.fetchFrom(params),
                         RESOURCE_DIR.fetchFrom(params));
-                w.write(content);
+                    w.write(content);
+                }
             }
 
             // prepare installer icon
@@ -525,17 +536,19 @@
         }
 
         if (!StandardBundlerParam.isRuntimeInstaller(params)) {
-            //prepare desktop shortcut
-            try (Writer w = Files.newBufferedWriter(
+            // prepare desktop shortcut
+            if (SHORTCUT_HINT.fetchFrom(params)) {
+                try (Writer w = Files.newBufferedWriter(
                     getConfig_DesktopShortcutFile(binDir, params).toPath())) {
-                String content = preprocessTextResource(
+                    String content = preprocessTextResource(
                         getConfig_DesktopShortcutFile(binDir,
-                                                      params).getName(),
-                        I18N.getString("resource.menu-shortcut-descriptor"),
+                                                          params).getName(),
+                    I18N.getString("resource.menu-shortcut-descriptor"),
                         DEFAULT_DESKTOP_FILE_TEMPLATE, data,
                         VERBOSE.fetchFrom(params),
                         RESOURCE_DIR.fetchFrom(params));
-                w.write(content);
+                    w.write(content);
+                }
             }
         }
 
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java	Thu Sep 12 10:46:10 2019 -0400
@@ -331,6 +331,11 @@
         LINUX_PACKAGE_DEPENDENCIES ("linux-package-deps",
                 OptionCategories.PLATFORM_LINUX),
 
+        LINUX_SHORTCUT_HINT ("linux-shortcut",
+                OptionCategories.PLATFORM_LINUX, () -> {
+            setOptionValue("linux-shortcut", true);
+        }),
+
         LINUX_MENU_GROUP ("linux-menu-group", OptionCategories.PLATFORM_LINUX);
 
         private final String id;
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ValidOptions.java	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ValidOptions.java	Thu Sep 12 10:46:10 2019 -0400
@@ -129,6 +129,7 @@
                     USE.INSTALL);
             options.put(CLIOptions.LINUX_MENU_GROUP.getId(), USE.INSTALL);
             options.put(CLIOptions.RELEASE.getId(), USE.INSTALL);
+            options.put(CLIOptions.LINUX_SHORTCUT_HINT.getId(), USE.INSTALL);
         }
     }
 
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources.properties	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources.properties	Thu Sep 12 10:46:10 2019 -0400
@@ -260,6 +260,8 @@
 \  --linux-app-category <category value>\n\
 \          Group value of the RPM <name>.spec file or \n\
 \          Section value of DEB control file.\n\
+\  --linux-shortcut\n\
+\          Creates a shortcut for the application\n\
 
 MSG_Help_mac_linux_install_dir=\
 \Absolute path of the installation directory of the application\n\
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_ja.properties	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_ja.properties	Thu Sep 12 10:46:10 2019 -0400
@@ -260,6 +260,8 @@
 \  --linux-app-category <category value>\n\
 \          Group value of the RPM <name>.spec file or \n\
 \          Section value of DEB control file.\n\
+\  --linux-shortcut\n\
+\          Creates a shortcut for the application\n\
 
 MSG_Help_mac_linux_install_dir=\
 \Absolute path of the installation directory of the application\n\
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_zh_CN.properties	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_zh_CN.properties	Thu Sep 12 10:46:10 2019 -0400
@@ -260,6 +260,8 @@
 \  --linux-app-category <category value>\n\
 \          Group value of the RPM <name>.spec file or \n\
 \          Section value of DEB control file.\n\
+\  --linux-shortcut\n\
+\          Creates a shortcut for the application\n\
 
 MSG_Help_mac_linux_install_dir=\
 \Absolute path of the installation directory of the application\n\
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java	Thu Sep 12 10:46:10 2019 -0400
@@ -492,14 +492,6 @@
         try {
             imageDir.mkdirs();
 
-            boolean menuShortcut = MENU_HINT.fetchFrom(params);
-            boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(params);
-            if (!menuShortcut && !desktopShortcut) {
-                // both can not be false - user will not find the app
-                Log.verbose(I18N.getString("message.one-shortcut-required"));
-                params.put(MENU_HINT.getID(), true);
-            }
-
             prepareBasicProjectConfig(params);
             if (prepareProto(params)) {
                 wixVars = prepareWiXConfig(params);
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties	Thu Sep 12 10:46:10 2019 -0400
@@ -62,7 +62,6 @@
 message.outputting-to-location=Generating EXE for installer to: {0}.
 message.output-location=Installer (.exe) saved to: {0}
 message.tool-version=Detected [{0}] version [{1}].
-message.one-shortcut-required=At least one type of shortcut is required. Enabling menu shortcut.
 message.running-wsh-script=Running WSH script on application image [{0}].
 message.creating-association-with-null-extension=Creating association with null extension.
 message.wrong-tool-version=Detected [{0}] version {1} but version {2} is required.
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_ja.properties	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_ja.properties	Thu Sep 12 10:46:10 2019 -0400
@@ -62,7 +62,6 @@
 message.outputting-to-location=Generating EXE for installer to: {0}.
 message.output-location=Installer (.exe) saved to: {0}
 message.tool-version=Detected [{0}] version [{1}].
-message.one-shortcut-required=At least one type of shortcut is required. Enabling menu shortcut.
 message.running-wsh-script=Running WSH script on application image [{0}].
 message.creating-association-with-null-extension=Creating association with null extension.
 message.wrong-tool-version=Detected [{0}] version {1} but version {2} is required.
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_zh_CN.properties	Wed Sep 11 13:26:36 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_zh_CN.properties	Thu Sep 12 10:46:10 2019 -0400
@@ -62,7 +62,6 @@
 message.outputting-to-location=Generating EXE for installer to: {0}.
 message.output-location=Installer (.exe) saved to: {0}
 message.tool-version=Detected [{0}] version [{1}].
-message.one-shortcut-required=At least one type of shortcut is required. Enabling menu shortcut.
 message.running-wsh-script=Running WSH script on application image [{0}].
 message.creating-association-with-null-extension=Creating association with null extension.
 message.wrong-tool-version=Detected [{0}] version {1} but version {2} is required.
--- a/test/jdk/tools/jpackage/share/SimplePackageTest.java	Wed Sep 11 13:26:36 2019 -0400
+++ b/test/jdk/tools/jpackage/share/SimplePackageTest.java	Thu Sep 12 10:46:10 2019 -0400
@@ -33,7 +33,7 @@
  * to change the default installation directory.
  * Test application should be installed in %ProgramFiles%\SimplePackageTest directory.
  * Installer should install test app for all users (machine wide).
- * Installer should create a shortcut for application launcher in Windows Menu.
+ * Installer should not create any shortcuts.
  */
 
 /*
--- a/test/jdk/tools/jpackage/windows/WinMenuTest.java	Wed Sep 11 13:26:36 2019 -0400
+++ b/test/jdk/tools/jpackage/windows/WinMenuTest.java	Thu Sep 12 10:46:10 2019 -0400
@@ -28,7 +28,7 @@
  * Test --win-menu parameter. Output of the test should be WinMenuTest-1.0.exe
  * installer. The output installer should provide the same functionality as the
  * default installer (see description of the default installer in
- * SimplePackageTest.java).
+ * SimplePackageTest.java), except it should create a menu shortcut.
  */
 
 /*