8217902: jpackage fails with --app-image option on mac JDK-8200758-branch
authorherrick
Wed, 27 Feb 2019 19:45:26 -0500
branchJDK-8200758-branch
changeset 57218 8018ecf829bc
parent 57217 b1291b2cedc9
child 57219 bfa094e6ce15
8217902: jpackage fails with --app-image option on mac Reviewed-by: almatvee
src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinAppBundler.java
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java	Wed Feb 27 08:53:56 2019 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java	Wed Feb 27 19:45:26 2019 -0500
@@ -410,14 +410,9 @@
                 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
         if (appImage != null) {
             File appImageDir = new File(appImage);
-            if (!appImageDir.exists()) {
+            if (!appImageDir.exists() || appImageDir.list().length == 0) {
                 throw new PackagerException("ERR_AppImageNotExist", appImage);
             }
-
-            File appImageAppDir = new File(appImage + File.separator + "app");
-            if (!appImageAppDir.exists()) {
-                throw new PackagerException("ERR_AppImageInvalid", appImage);
-            }
         }
 
         // Validate build-root
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinAppBundler.java	Wed Feb 27 08:53:56 2019 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinAppBundler.java	Wed Feb 27 19:45:26 2019 -0500
@@ -29,6 +29,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.nio.file.Path;
 import java.text.MessageFormat;
 import java.util.Arrays;
 import java.util.Collection;
@@ -118,14 +119,23 @@
             if (appName == null) {
                 // Use WIN_APP_IMAGE here, since we already copy pre-defined
                 // image to WIN_APP_IMAGE
-                File appImageDir = new File(
-                        WIN_APP_IMAGE.fetchFrom(p).toString() + "\\app");
-                File [] files = appImageDir.listFiles(
+                File appImageDir = WIN_APP_IMAGE.fetchFrom(p);
+
+                File appDir = new File(appImageDir.toString() + "\\app");
+                File [] files = appDir.listFiles(
                         (File dir, String name) -> name.endsWith(".cfg"));
                 if (files == null || files.length == 0) {
-                    throw new RuntimeException(MessageFormat.format(
-                        I18N.getString("error.cannot-find-launcher"),
-                        appImageDir));
+                    String name = APP_NAME.fetchFrom(p);
+                    Path exePath = appImageDir.toPath().resolve(name + ".exe");
+                    Path icoPath = appImageDir.toPath().resolve(name + ".ico");
+                    if (exePath.toFile().exists() &&
+                            icoPath.toFile().exists()) {
+                        return name;
+                    } else {
+                        throw new RuntimeException(MessageFormat.format(
+                                I18N.getString("error.cannot-find-launcher"),
+                                appImageDir));
+                    }
                 } else {
                     appName = files[0].getName();
                     int index = appName.indexOf(".");