changeset 8661:f88433e126cd 8u40-b21

RT-39763: Javapackager Windows installers should write to local-user registry keys by default Summary: Change the registry root we write to based on local/system wide install for EXE
author Danno Ferrin (shemnon) <danno.ferrin@oracle.com>
date Mon, 05 Jan 2015 22:18:00 -0700
parents 0e74290964bf
children 29f7ba34750c
files modules/fxpackager/src/main/java/com/oracle/tools/packager/windows/WinExeBundler.java modules/fxpackager/src/test/java/com/oracle/tools/packager/windows/WinExeBundlerTest.java
diffstat 2 files changed, 79 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/modules/fxpackager/src/main/java/com/oracle/tools/packager/windows/WinExeBundler.java	Fri Dec 26 11:15:06 2014 -0700
+++ b/modules/fxpackager/src/main/java/com/oracle/tools/packager/windows/WinExeBundler.java	Mon Jan 05 22:18:00 2015 -0700
@@ -457,7 +457,9 @@
 
         data.put("APPLICATION_LICENSE_FILE", innosetupEscape(getLicenseFile(params)));
 
-        if (EXE_SYSTEM_WIDE.fetchFrom(params)) {
+        Boolean isSystemWide = EXE_SYSTEM_WIDE.fetchFrom(params);
+        
+        if (isSystemWide) {
             data.put("APPLICATION_INSTALL_ROOT", "{pf}");
             data.put("APPLICATION_INSTALL_PRIVILEGE", "admin");
         } else {
@@ -527,12 +529,20 @@
                 Log.info(I18N.getString("message.creating-association-with-null-extension"));
             } else {
                 for (String ext : extensions) {
-                    // "Root: HKCR; Subkey: \".myp\"; ValueType: string; ValueName: \"\"; ValueData: \"MyProgramFile\"; Flags: uninsdeletevalue"
-                    registryEntries.append("Root: HKCR; Subkey: \".")
-                        .append(ext)
-                        .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
-                        .append(entryName)
-                        .append("\"; Flags: uninsdeletevalue\r\n");
+                    if (isSystemWide) {
+                        // "Root: HKCR; Subkey: \".myp\"; ValueType: string; ValueName: \"\"; ValueData: \"MyProgramFile\"; Flags: uninsdeletevalue"
+                        registryEntries.append("Root: HKCR; Subkey: \".")
+                                .append(ext)
+                                .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
+                                .append(entryName)
+                                .append("\"; Flags: uninsdeletevalue\r\n");
+                    } else {
+                        registryEntries.append("Root: HKCU; Subkey: \"Software\\Classes\\.")
+                                .append(ext)
+                                .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
+                                .append(entryName)
+                                .append("\"; Flags: uninsdeletevalue\r\n");
+                    }
                 }
             }
 
@@ -540,37 +550,70 @@
                 String ext = extensions.get(0);
                 List<String> mimeTypes = FA_CONTENT_TYPE.fetchFrom(fileAssociation);
                 for (String mime : mimeTypes) {
-                    // "Root: HKCR; Subkey: HKCR\\Mime\\Database\\Content Type\\application/chaos; ValueType: string; ValueName: Extension; ValueData: .chaos; Flags: uninsdeletevalue"
-                    registryEntries.append("Root: HKCR; Subkey: \"Mime\\Database\\Content Type\\")
-                        .append(mime)
-                        .append("\"; ValueType: string; ValueName: \"Extension\"; ValueData: \".")
-                        .append(ext)
-                        .append("\"; Flags: uninsdeletevalue\r\n");
+                    if (isSystemWide) {
+                        // "Root: HKCR; Subkey: HKCR\\Mime\\Database\\Content Type\\application/chaos; ValueType: string; ValueName: Extension; ValueData: .chaos; Flags: uninsdeletevalue"
+                        registryEntries.append("Root: HKCR; Subkey: \"Mime\\Database\\Content Type\\")
+                            .append(mime)
+                            .append("\"; ValueType: string; ValueName: \"Extension\"; ValueData: \".")
+                            .append(ext)
+                            .append("\"; Flags: uninsdeletevalue\r\n");
+                    } else {
+                        registryEntries.append("Root: HKCU; Subkey: \"Software\\Classes\\Mime\\Database\\Content Type\\")
+                                .append(mime)
+                                .append("\"; ValueType: string; ValueName: \"Extension\"; ValueData: \".")
+                                .append(ext)
+                                .append("\"; Flags: uninsdeletevalue\r\n");
+                    }
                 }
             }
 
-            //"Root: HKCR; Subkey: \"MyProgramFile\"; ValueType: string; ValueName: \"\"; ValueData: \"My Program File\"; Flags: uninsdeletekey"
-            registryEntries.append("Root: HKCR; Subkey: \"")
-                .append(entryName)
-                .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
-                .append(description)
-                .append("\"; Flags: uninsdeletekey\r\n");
+            if (isSystemWide) {
+                //"Root: HKCR; Subkey: \"MyProgramFile\"; ValueType: string; ValueName: \"\"; ValueData: \"My Program File\"; Flags: uninsdeletekey"
+                registryEntries.append("Root: HKCR; Subkey: \"")
+                    .append(entryName)
+                    .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
+                    .append(description)
+                    .append("\"; Flags: uninsdeletekey\r\n");
+            } else {
+                registryEntries.append("Root: HKCU; Subkey: \"Software\\Classes\\")
+                    .append(entryName)
+                    .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
+                    .append(description)
+                    .append("\"; Flags: uninsdeletekey\r\n");
+                
+            }
 
             if (icon != null && icon.exists()) {
-                // "Root: HKCR; Subkey: \"MyProgramFile\\DefaultIcon\"; ValueType: string; ValueName: \"\"; ValueData: \"{app}\\MYPROG.EXE,0\"\n" +
-                registryEntries.append("Root: HKCR; Subkey: \"")
+                if (isSystemWide) {
+                    // "Root: HKCR; Subkey: \"MyProgramFile\\DefaultIcon\"; ValueType: string; ValueName: \"\"; ValueData: \"{app}\\MYPROG.EXE,0\"\n" +
+                    registryEntries.append("Root: HKCR; Subkey: \"")
                         .append(entryName)
                         .append("\\DefaultIcon\"; ValueType: string; ValueName: \"\"; ValueData: \"{app}\\")
                         .append(icon.getName())
                         .append("\"\r\n");
+                } else {
+                    registryEntries.append("Root: HKCU; Subkey: \"Software\\Classes\\")
+                            .append(entryName)
+                            .append("\\DefaultIcon\"; ValueType: string; ValueName: \"\"; ValueData: \"{app}\\")
+                            .append(icon.getName())
+                            .append("\"\r\n");
+                }
             }
 
-            //"Root: HKCR; Subkey: \"MyProgramFile\\shell\\open\\command\"; ValueType: string; ValueName: \"\"; ValueData: \"\"\"{app}\\MYPROG.EXE\"\" \"\"%1\"\"\"\n"
-            registryEntries.append("Root: HKCR; Subkey: \"")
-                    .append(entryName)
-                    .append("\\shell\\open\\command\"; ValueType: string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
-                    .append(APP_NAME.fetchFrom(params))
-                    .append("\"\" \"\"%1\"\"\"\r\n");
+            if (isSystemWide) {
+                //"Root: HKCR; Subkey: \"MyProgramFile\\shell\\open\\command\"; ValueType: string; ValueName: \"\"; ValueData: \"\"\"{app}\\MYPROG.EXE\"\" \"\"%1\"\"\"\n"
+                registryEntries.append("Root: HKCR; Subkey: \"")
+                        .append(entryName)
+                        .append("\\shell\\open\\command\"; ValueType: string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
+                        .append(APP_NAME.fetchFrom(params))
+                        .append("\"\" \"\"%1\"\"\"\r\n");
+            } else {
+                registryEntries.append("Root: HKCU; Subkey: \"Software\\Classes\\")
+                        .append(entryName)
+                        .append("\\shell\\open\\command\"; ValueType: string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
+                        .append(APP_NAME.fetchFrom(params))
+                        .append("\"\" \"\"%1\"\"\"\r\n");
+            }
         }
         if (registryEntries.length() > 0) {
             data.put("FILE_ASSOCIATIONS", "ChangesAssociations=yes\r\n\r\n[Registry]\r\n" + registryEntries.toString());
--- a/modules/fxpackager/src/test/java/com/oracle/tools/packager/windows/WinExeBundlerTest.java	Fri Dec 26 11:15:06 2014 -0700
+++ b/modules/fxpackager/src/test/java/com/oracle/tools/packager/windows/WinExeBundlerTest.java	Mon Jan 05 22:18:00 2015 -0700
@@ -399,7 +399,7 @@
         Assume.assumeTrue(Boolean.parseBoolean(System.getProperty("FULL_TEST")));
 
         testFileAssociation("FASmoke 1", "Bogus File", "bogus", "application/x-vnd.test-bogus",
-                            new File(appResourcesDir, "small.ico"));
+                            new File(appResourcesDir, "small.ico"), false);
     }
 
     @Test
@@ -408,7 +408,7 @@
     {
         // association with no extension is still valid case (see RT-38625)
         testFileAssociation("FASmoke null", "Bogus File", null, "application/x-vnd.test-bogus",
-                            new File(appResourcesDir, "small.ico"));
+                            new File(appResourcesDir, "small.ico"), true);
     }
 
     @Test
@@ -419,7 +419,7 @@
         Assume.assumeTrue(Boolean.parseBoolean(System.getProperty("FULL_TEST")));
 
         testFileAssociation("FASmoke ME", "Bogus File", "bogus fake", "application/x-vnd.test-bogus",
-                new File(appResourcesDir, "small.ico"));
+                new File(appResourcesDir, "small.ico"), false);
     }
 
     @Test
@@ -433,7 +433,7 @@
                 new String[]{"Bogus File", "Fake file"},
                 new String[]{"bogus", "fake"},
                 new String[]{"application/x-vnd.test-bogus", "application/x-vnd.test-fake"},
-                new File[]{new File(appResourcesDir, "small.ico"), new File(appResourcesDir, "small.ico")});
+                new File[]{new File(appResourcesDir, "small.ico"), new File(appResourcesDir, "small.ico")}, true);
     }
 
     @Test
@@ -445,19 +445,19 @@
                 new String[]{"Bogus File", "Fake file"},
                 new String[]{"bogus boguser", "fake faker"},
                 new String[]{"application/x-vnd.test-bogus", "application/x-vnd.test-fake"},
-                new File[]{new File(appResourcesDir, "small.ico"), new File(appResourcesDir, "small.ico")});
+                new File[]{new File(appResourcesDir, "small.ico"), new File(appResourcesDir, "small.ico")}, false);
     }
 
     private void testFileAssociation(String appName, String description, String extensions,
-                                     String contentType, File icon)
+                                     String contentType, File icon, boolean systemWide)
             throws IOException, ConfigException, UnsupportedPlatformException
     {
         testFileAssociationMultiples(appName, new String[] {description}, new String[] {extensions},
-                new String[] {contentType}, new File[] {icon});
+                new String[] {contentType}, new File[] {icon}, systemWide);
     }
 
     private void testFileAssociationMultiples(String appName, String[] description, String[] extensions,
-                                              String[] contentType, File[] icon)
+                                              String[] contentType, File[] icon, boolean systemWide)
             throws IOException, ConfigException, UnsupportedPlatformException
     {
         assertEquals("Sanity: description same length as extensions", description.length, extensions.length);
@@ -484,7 +484,7 @@
         bundleParams.put(CLASSPATH.getID(), "mainApp.jar");
         bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
         bundleParams.put(VERBOSE.getID(), true);
-        bundleParams.put(SYSTEM_WIDE.getID(), true);
+        bundleParams.put(SYSTEM_WIDE.getID(), systemWide);
         bundleParams.put(VENDOR.getID(), "Packager Tests");
 
         List<Map<String, Object>> associations = new ArrayList<>();