8230653: jpackage error on macOS system without xcode JDK-8200758-branch
authorherrick
Thu, 12 Sep 2019 12:03:00 -0400
branchJDK-8200758-branch
changeset 58117 69465ef51b0c
parent 58116 93b8c1305de2
child 58118 992df93db66a
8230653: jpackage error on macOS system without xcode Submitted-by: almatvee Reviewed-by: herrick, asemenyuk
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java	Thu Sep 12 10:46:10 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java	Thu Sep 12 12:03:00 2019 -0400
@@ -29,8 +29,6 @@
 import java.io.IOException;
 import java.math.BigInteger;
 import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
@@ -278,6 +276,20 @@
                         I18N.getString("error.explicit-sign-no-cert"),
                         I18N.getString("error.explicit-sign-no-cert.advice"));
             }
+
+            // Signing will not work without Xcode with command line developer tools
+            try {
+                ProcessBuilder pb = new ProcessBuilder("xcrun", "--help");
+                Process p = pb.start();
+                int code = p.waitFor();
+                if (code != 0) {
+                    throw new ConfigException(
+                        I18N.getString("error.no.xcode.signing"),
+                        I18N.getString("error.no.xcode.signing.advice"));
+                }
+            } catch (IOException | InterruptedException ex) {
+                throw new ConfigException(ex);
+            }
         }
 
         return true;
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java	Thu Sep 12 10:46:10 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java	Thu Sep 12 12:03:00 2019 -0400
@@ -217,13 +217,32 @@
         String typicalPaths[] = {"/Developer/Tools/SetFile",
                 "/usr/bin/SetFile", "/Developer/usr/bin/SetFile"};
 
+        String setFilePath = null;
         for (String path: typicalPaths) {
             File f = new File(path);
             if (f.exists() && f.canExecute()) {
-                return path;
+                setFilePath = path;
+                break;
             }
         }
 
+        // Validate SetFile, if Xcode is not installed it will run, but exit with error
+        // code
+        if (setFilePath != null) {
+            try {
+                ProcessBuilder pb = new ProcessBuilder(setFilePath, "-h");
+                Process p = pb.start();
+                int code = p.waitFor();
+                if (code == 0) {
+                    return setFilePath;
+                }
+            } catch (Exception ignored) {}
+
+            // No need for generic find attempt. We found it, but it does not work.
+            // Probably due to missing xcode.
+            return null;
+        }
+
         // generic find attempt
         try {
             ProcessBuilder pb = new ProcessBuilder("xcrun", "-find", "SetFile");
@@ -340,8 +359,7 @@
                 Log.verbose("Cannot enable custom icon using SetFile utility");
             }
         } else {
-            Log.verbose(
-                "Skip enabling custom icon as SetFile utility is not found");
+            Log.verbose(I18N.getString("message.setfile.dmg"));
         }
 
         // Detach the temporary image
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties	Thu Sep 12 10:46:10 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties	Thu Sep 12 12:03:00 2019 -0400
@@ -42,6 +42,8 @@
 error.no-pkg-signing-key=No Mac App Store Installer Signing Key
 error.no-pkg-signing-key.advice=Install your app signing keys into your Mac Keychain using XCode.
 error.certificate.expired=Error: Certificate expired {0}
+error.no.xcode.signing=Xcode with command line developer tools is required for signing
+error.no.xcode.signing.advice=Install Xcode with command line developer tools.
 
 resource.bundle-config-file=Bundle config file
 resource.app-info-plist=Application Info.plist
@@ -86,4 +88,4 @@
 message.preparing-scripts=Preparing package scripts.
 message.preparing-distribution-dist=Preparing distribution.dist: {0}.
 message.signing.pkg=Warning: For signing PKG, you might need to set "Always Trust" for your certificate using "Keychain Access" tool.
-
+message.setfile.dmg=Setting custom icon on DMG file skipped because 'SetFile' utility was not found. Installing Xcode with Command Line Tools should resolve this issue.
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties	Thu Sep 12 10:46:10 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties	Thu Sep 12 12:03:00 2019 -0400
@@ -42,6 +42,8 @@
 error.no-pkg-signing-key=No Mac App Store Installer Signing Key
 error.no-pkg-signing-key.advice=Install your app signing keys into your Mac Keychain using XCode.
 error.certificate.expired=Error: Certificate expired {0}
+error.no.xcode.signing=Xcode with command line developer tools is required for signing
+error.no.xcode.signing.advice=Install Xcode with command line developer tools.
 
 resource.bundle-config-file=Bundle config file
 resource.app-info-plist=Application Info.plist
@@ -86,4 +88,4 @@
 message.preparing-scripts=Preparing package scripts.
 message.preparing-distribution-dist=Preparing distribution.dist: {0}.
 message.signing.pkg=Warning: For signing PKG, you might need to set "Always Trust" for your certificate using "Keychain Access" tool.
-
+message.setfile.dmg=Setting custom icon on DMG file skipped because 'SetFile' utility was not found. Installing Xcode with Command Line Tools should resolve this issue.
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties	Thu Sep 12 10:46:10 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties	Thu Sep 12 12:03:00 2019 -0400
@@ -42,6 +42,8 @@
 error.no-pkg-signing-key=No Mac App Store Installer Signing Key
 error.no-pkg-signing-key.advice=Install your app signing keys into your Mac Keychain using XCode.
 error.certificate.expired=Error: Certificate expired {0}
+error.no.xcode.signing=Xcode with command line developer tools is required for signing
+error.no.xcode.signing.advice=Install Xcode with command line developer tools.
 
 resource.bundle-config-file=Bundle config file
 resource.app-info-plist=Application Info.plist
@@ -86,4 +88,4 @@
 message.preparing-scripts=Preparing package scripts.
 message.preparing-distribution-dist=Preparing distribution.dist: {0}.
 message.signing.pkg=Warning: For signing PKG, you might need to set "Always Trust" for your certificate using "Keychain Access" tool.
-
+message.setfile.dmg=Setting custom icon on DMG file skipped because 'SetFile' utility was not found. Installing Xcode with Command Line Tools should resolve this issue.