8221101: Update JNLPConverter to support latest jpackage CLI changes JDK-8200758-branch
authorherrick
Tue, 26 Mar 2019 08:54:43 -0400
branchJDK-8200758-branch
changeset 57282 c9c2c08854f5
parent 57276 eac9018748b3
child 57283 0b0be19f79e4
8221101: Update JNLPConverter to support latest jpackage CLI changes Submitten-by: almatvee Reviewed-by: herrick
src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/JNLPConverter.java
src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/Options.java
src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/exception/BadFieldException.java
src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/exception/MissingFieldException.java
src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/xml/XMLParser.java
--- a/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/JNLPConverter.java	Thu Mar 21 13:46:28 2019 -0400
+++ b/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/JNLPConverter.java	Tue Mar 26 08:54:43 2019 -0400
@@ -88,7 +88,7 @@
             saveLaunchArgs();
             runJPackage();
         } catch (Exception ex) {
-            Log.error(ex.getLocalizedMessage());
+            Log.error(ex.getMessage());
         }
     }
 
@@ -391,7 +391,10 @@
             if (options.getInstallerType() == null) {
                 addLaunchArg("create-installer", launchArgs);
             } else {
-                addLaunchArg("create-installer", options.getInstallerType(), launchArgs);
+                addLaunchArg("create-installer", launchArgs);
+                if (options.getInstallerType() != null) {
+                    addLaunchArg("--installer-type", options.getInstallerType(), launchArgs);
+                }
             }
         }
 
@@ -403,59 +406,61 @@
         addLaunchArg("--input", getJarDownloadFolder(), launchArgs);
         addLaunchArg("--output", options.getOutput(), launchArgs);
         addLaunchArg("--name", jnlpd.getName(), launchArgs);
-        addLaunchArg("--version", jnlpd.getVersion(), launchArgs);
+        addLaunchArg("--app-version", jnlpd.getVersion(), launchArgs);
         addLaunchArg("--vendor", jnlpd.getVendor(), launchArgs);
         addLaunchArg("--description", jnlpd.getDescription(), launchArgs);
         addLaunchArg("--icon", jnlpd.getIconLocation(), launchArgs);
         addLaunchArg("--main-jar", jnlpd.getMainJar(), launchArgs);
-        addLaunchArg("--class", jnlpd.getMainClass(), launchArgs);
+        addLaunchArg("--main-class", jnlpd.getMainClass(), launchArgs);
 
         addFiles(launchArgs);
         addArguments(launchArgs);
         addJVMArgs(launchArgs);
 
-        if (jnlpd.isDesktopHint()) {
-            if (Platform.isWindows()) {
-                addLaunchArg("--win-shortcut", launchArgs);
-            } else {
-                Log.warning("Ignoring shortcut hint, since it is not supported on current platform.");
+        if (options.createInstaller()) {
+            if (jnlpd.isDesktopHint()) {
+                if (Platform.isWindows()) {
+                    addLaunchArg("--win-shortcut", launchArgs);
+                } else {
+                    Log.warning("Ignoring shortcut hint, since it is not supported on current platform.");
+                }
             }
-        }
 
-        if (jnlpd.isMenuHint()) {
-            if (Platform.isWindows()) {
-                addLaunchArg("--win-menu", launchArgs);
-                addLaunchArg("--win-menu-group", jnlpd.getSubMenu(), launchArgs);
-            } else {
-                Log.warning("Ignoring menu hint, since it is not supported on current platform.");
+            if (jnlpd.isMenuHint()) {
+                if (Platform.isWindows()) {
+                    addLaunchArg("--win-menu", launchArgs);
+                    addLaunchArg("--win-menu-group", jnlpd.getSubMenu(), launchArgs);
+                } else {
+                    Log.warning("Ignoring menu hint, since it is not supported on current platform.");
+                }
             }
-        }
 
-        AssociationDesc [] associations = jnlpd.getAssociations();
-        if (associations != null) {
-            for (AssociationDesc association : associations) {
-                String file = getFileAssociationsFile();
-                markFileToDelete(file);
+            AssociationDesc[] associations = jnlpd.getAssociations();
+            if (associations != null) {
+                for (AssociationDesc association : associations) {
+                    String file = getFileAssociationsFile();
+                    markFileToDelete(file);
 
-                try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)))) {
-                    if (association.getExtensions() != null && association.getMimeType() != null) {
-                        out.println(FA_EXTENSIONS + "=" + quote(association.getExtensions()));
-                        out.println(FA_CONTENT_TYPE + "=" + quote(association.getMimeType()));
+                    try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)))) {
+                        if (association.getExtensions() != null && association.getMimeType() != null) {
+                            out.println(FA_EXTENSIONS + "=" + quote(association.getExtensions()));
+                            out.println(FA_CONTENT_TYPE + "=" + quote(association.getMimeType()));
 
-                        if (association.getMimeDescription() != null) {
-                            out.println(FA_DESCRIPTION + "=" + association.getMimeDescription());
-                        }
+                            if (association.getMimeDescription() != null) {
+                                out.println(FA_DESCRIPTION + "=" + association.getMimeDescription());
+                            }
 
-                        if (association.getIconLocalLocation() != null) {
-                            out.println(FA_ICON + "=" + quote(association.getIconLocalLocation()));
+                            if (association.getIconLocalLocation() != null) {
+                                out.println(FA_ICON + "=" + quote(association.getIconLocalLocation()));
+                            }
+
+                            addLaunchArg("--file-associations", file, launchArgs);
                         }
-
-                        addLaunchArg("--file-associations", file, launchArgs);
-                    }
-                } catch (Exception ex) {
-                    Log.warning(ex.toString());
-                    if (association.getExtensions() != null) {
-                        Log.warning("File assoication for " + association.getExtensions() + " will be ignored due to exception above.");
+                    } catch (Exception ex) {
+                        Log.warning(ex.toString());
+                        if (association.getExtensions() != null) {
+                            Log.warning("File assoication for " + association.getExtensions() + " will be ignored due to exception above.");
+                        }
                     }
                 }
             }
@@ -682,11 +687,7 @@
                     case '"':
                         // " -> \" -> \\\"
                         if (i == 0 || in.codePointAt(i - 1) != '\\') {
-                            if (Platform.isWindows()) {
                                 sb.appendCodePoint('\\');
-                                sb.appendCodePoint('\\');
-                            }
-                            sb.appendCodePoint('\\');
                             sb.appendCodePoint(code);
                         }
                         break;
@@ -705,9 +706,6 @@
                                 sb.appendCodePoint(code);
                             }
                         } else {
-                            if (Platform.isWindows()) {
-                                sb.appendCodePoint('\\');
-                            }
                             sb.appendCodePoint(code);
                         }
                         break;
@@ -739,7 +737,7 @@
 
                 downloadFolder = file.getAbsolutePath();
             } catch (IOException e) {
-                Log.error(e.getLocalizedMessage());
+                Log.error(e.getMessage());
             }
         }
 
--- a/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/Options.java	Thu Mar 21 13:46:28 2019 -0400
+++ b/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/Options.java	Tue Mar 26 08:54:43 2019 -0400
@@ -48,13 +48,13 @@
     private static final String OUTPUT_OPTION_SHORT_PREFIX = "-o";
     private static final String KEEP_OPTION_SHORT_PREFIX = "-k";
 
-    private static final String [] INSTALLER_TYPES = {"msi", "rpm", "deb",
-                                                      "dmg", "pkg", "pkg-app-store"};
+    private static final String [] INSTALLER_TYPES = {"msi", "exe", "dmg", "pkg",
+                                                      "rpm", "deb"};
 
-    // --output, -o, --input, -i, --files, -f, --main-jar, -j, --class, -c
+    // --output, -o, --input, -i, --files, -f, --main-jar, --main-class
     private static final String [] BLOCKED_JPACKAGE_OPTIONS = {"--output", "-o", "--input", "-i",
                                                                 "--files", "-f", "--main-jar",
-                                                                "-j", "--class", "-c"};
+                                                                "--main-class"};
 
     private static final String RUNTIME_IMAGE_OPTION = "--runtime-image";
 
@@ -204,11 +204,8 @@
         System.out.println("where mode is one of:");
         System.out.println("  create-image");
         System.out.println("          Generates a platform-specific application image.");
-        System.out.println("  create-installer <type>");
+        System.out.println("  create-installer");
         System.out.println("          Generates a platform-specific installer for the application.");
-        System.out.println("          Valid values for \"type\" are \"msi\", \"rpm\", \"deb\", \"dmg\", \"pkg\",");
-        System.out.println("          \"pkg-app-store\". If \"type\" is omitted, all supported types of installable");
-        System.out.println("          packages for current platform will be generated.");
         System.out.println("");
         System.out.println("Possible options include:");
         System.out.println("  -j, --jnlp <path>");
@@ -222,6 +219,12 @@
         System.out.println("          Specify additional jpackage options or overwrite provided by JNLPConverter.");
         System.out.println("          All jpackage options can be specified except: --output -o, --input -i,");
         System.out.println("          --files -f, --main-jar -j and --class -c.");
+        System.out.println("      --installer-type <type>");
+        System.out.println("          The type of the installer to create");
+        System.out.println("          Valid values are: {\"exe\", \"msi\", \"rpm\", \"deb\", \"pkg\", \"dmg\"}");
+        System.out.println("          If this option is not specified (in create-installer mode) all");
+        System.out.println("          supported types of installable packages for the current");
+        System.out.println("          platform will be created.");
         System.out.println("  -h, --help, -?");
         System.out.println("          Print this help message");
         System.out.println("  -v, --verbose");
@@ -256,12 +259,6 @@
                 case "create-installer":
                     options.createInstaller = true;
                     index = 1;
-                    if (args.length >= 2) {
-                        if (isInstallerType(args[1])) {
-                            options.installerType = args[1];
-                            index = 2;
-                        }
-                    }
                     break;
                 case "-h":
                 case "--help":
@@ -338,6 +335,13 @@
                     }
                     options.jpackageOptions.add(args[i]);
                 }
+            } else if (arg.equals("--installer-type")) {
+                if ((i + 1) < args.length) {
+                    if (isInstallerType(args[i + 1])) {
+                        options.installerType = args[i + 1];
+                        i++;
+                    }
+                }
             } else {
                 optionError(ERR_UNKNOWN_OPTION, arg);
             }
--- a/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/exception/BadFieldException.java	Thu Mar 21 13:46:28 2019 -0400
+++ b/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/exception/BadFieldException.java	Tue Mar 26 08:54:43 2019 -0400
@@ -55,4 +55,9 @@
     public String toString() {
         return "BadFieldException[ " + getField() + "," + getValue() + "]";
     }
+
+    @Override
+    public String getMessage(){
+        return toString();
+    }
 }
--- a/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/exception/MissingFieldException.java	Thu Mar 21 13:46:28 2019 -0400
+++ b/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/exception/MissingFieldException.java	Tue Mar 26 08:54:43 2019 -0400
@@ -46,4 +46,9 @@
     public String toString() {
         return "MissingFieldException[ " + getField() + "]";
     }
+
+    @Override
+    public String getMessage(){
+        return toString();
+    }
 }
--- a/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/xml/XMLParser.java	Thu Mar 21 13:46:28 2019 -0400
+++ b/src/demo/share/jpackage/JNLPConverter/src/jnlp/converter/parser/xml/XMLParser.java	Tue Mar 26 08:54:43 2019 -0400
@@ -157,6 +157,13 @@
     }
 
     @Override
+    public void characters(char[] chars, int start, int length)
+            throws SAXException {
+        String s = new String(chars, start, length);
+        _characters = ((_characters == null) ? s : _characters + s);
+    }
+
+    @Override
     public void ignorableWhitespace(char[] chars, int start, int length)
             throws SAXException {
         String s = new String(chars, start, length);