< prev index next >

src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacAppBundler.java

Print this page

        

@@ -21,106 +21,38 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package jdk.jpackage.internal;
+package jdk.incubator.jpackage.internal;
 
 import java.io.File;
 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;
 import java.util.ResourceBundle;
 
-import static jdk.jpackage.internal.StandardBundlerParam.*;
-import static jdk.jpackage.internal.MacBaseInstallerBundler.*;
-import jdk.jpackage.internal.AbstractAppImageBuilder;
+import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;
+import static jdk.incubator.jpackage.internal.MacBaseInstallerBundler.*;
 
 public class MacAppBundler extends AbstractImageBundler {
 
     private static final ResourceBundle I18N = ResourceBundle.getBundle(
-            "jdk.jpackage.internal.resources.MacResources");
+            "jdk.incubator.jpackage.internal.resources.MacResources");
 
-    private static final String TEMPLATE_BUNDLE_ICON = "GenericApp.icns";
-
-    public static Map<String, String> getMacCategories() {
-        Map<String, String> map = new HashMap<>();
-        map.put("Business", "public.app-category.business");
-        map.put("Developer Tools", "public.app-category.developer-tools");
-        map.put("Education", "public.app-category.education");
-        map.put("Entertainment", "public.app-category.entertainment");
-        map.put("Finance", "public.app-category.finance");
-        map.put("Games", "public.app-category.games");
-        map.put("Graphics & Design", "public.app-category.graphics-design");
-        map.put("Healthcare & Fitness",
-                "public.app-category.healthcare-fitness");
-        map.put("Lifestyle", "public.app-category.lifestyle");
-        map.put("Medical", "public.app-category.medical");
-        map.put("Music", "public.app-category.music");
-        map.put("News", "public.app-category.news");
-        map.put("Photography", "public.app-category.photography");
-        map.put("Productivity", "public.app-category.productivity");
-        map.put("Reference", "public.app-category.reference");
-        map.put("Social Networking", "public.app-category.social-networking");
-        map.put("Sports", "public.app-category.sports");
-        map.put("Travel", "public.app-category.travel");
-        map.put("Utilities", "public.app-category.utilities");
-        map.put("Video", "public.app-category.video");
-        map.put("Weather", "public.app-category.weather");
-
-        map.put("Action Games", "public.app-category.action-games");
-        map.put("Adventure Games", "public.app-category.adventure-games");
-        map.put("Arcade Games", "public.app-category.arcade-games");
-        map.put("Board Games", "public.app-category.board-games");
-        map.put("Card Games", "public.app-category.card-games");
-        map.put("Casino Games", "public.app-category.casino-games");
-        map.put("Dice Games", "public.app-category.dice-games");
-        map.put("Educational Games", "public.app-category.educational-games");
-        map.put("Family Games", "public.app-category.family-games");
-        map.put("Kids Games", "public.app-category.kids-games");
-        map.put("Music Games", "public.app-category.music-games");
-        map.put("Puzzle Games", "public.app-category.puzzle-games");
-        map.put("Racing Games", "public.app-category.racing-games");
-        map.put("Role Playing Games", "public.app-category.role-playing-games");
-        map.put("Simulation Games", "public.app-category.simulation-games");
-        map.put("Sports Games", "public.app-category.sports-games");
-        map.put("Strategy Games", "public.app-category.strategy-games");
-        map.put("Trivia Games", "public.app-category.trivia-games");
-        map.put("Word Games", "public.app-category.word-games");
-
-        return map;
-    }
-
-    public static final EnumeratedBundlerParam<String> MAC_CATEGORY =
-            new EnumeratedBundlerParam<>(
-                    Arguments.CLIOptions.MAC_APP_STORE_CATEGORY.getId(),
-                    String.class,
-                    params -> "Unknown",
-                    (s, p) -> s,
-                    getMacCategories(),
-                    false //strict - for MacStoreBundler this should be strict
-            );
+    private static final String TEMPLATE_BUNDLE_ICON = "java.icns";
 
     public static final BundlerParamInfo<String> MAC_CF_BUNDLE_NAME =
             new StandardBundlerParam<>(
                     Arguments.CLIOptions.MAC_BUNDLE_NAME.getId(),
                     String.class,
                     params -> null,
                     (s, p) -> s);
 
-    public static final BundlerParamInfo<String> MAC_CF_BUNDLE_IDENTIFIER =
-            new StandardBundlerParam<>(
-                    Arguments.CLIOptions.MAC_BUNDLE_IDENTIFIER.getId(),
-                    String.class,
-                    IDENTIFIER::fetchFrom,
-                    (s, p) -> s);
-
     public static final BundlerParamInfo<String> MAC_CF_BUNDLE_VERSION =
             new StandardBundlerParam<>(
                     "mac.CFBundleVersion",
                     String.class,
                     p -> {

@@ -149,12 +81,11 @@
                             "Developer ID Application: "
                             + SIGNING_KEY_USER.fetchFrom(params),
                             SIGNING_KEYCHAIN.fetchFrom(params),
                             VERBOSE.fetchFrom(params));
                     if (result != null) {
-                        MacCertificate certificate = new MacCertificate(result,
-                                VERBOSE.fetchFrom(params));
+                        MacCertificate certificate = new MacCertificate(result);
 
                         if (!certificate.isValid()) {
                             Log.error(MessageFormat.format(I18N.getString(
                                     "error.certificate.expired"), result));
                         }

@@ -239,11 +170,11 @@
         return true;
     }
 
     @Override
     public boolean validate(Map<String, ? super Object> params)
-            throws UnsupportedPlatformException, ConfigException {
+            throws ConfigException {
         try {
             return doValidate(params);
         } catch (RuntimeException re) {
             if (re.getCause() instanceof ConfigException) {
                 throw (ConfigException) re.getCause();

@@ -251,63 +182,76 @@
                 throw new ConfigException(re);
             }
         }
     }
 
-    private boolean doValidate(Map<String, ? super Object> p)
-            throws UnsupportedPlatformException, ConfigException {
-        if (Platform.getPlatform() != Platform.MAC) {
-            throw new UnsupportedPlatformException();
-        }
+    private boolean doValidate(Map<String, ? super Object> params)
+            throws ConfigException {
 
-        imageBundleValidation(p);
+        imageBundleValidation(params);
 
-        if (StandardBundlerParam.getPredefinedAppImage(p) != null) {
+        if (StandardBundlerParam.getPredefinedAppImage(params) != null) {
             return true;
         }
 
         // validate short version
-        if (!validCFBundleVersion(MAC_CF_BUNDLE_VERSION.fetchFrom(p))) {
+        if (!validCFBundleVersion(MAC_CF_BUNDLE_VERSION.fetchFrom(params))) {
             throw new ConfigException(
                     I18N.getString("error.invalid-cfbundle-version"),
                     I18N.getString("error.invalid-cfbundle-version.advice"));
         }
 
         // reject explicitly set sign to true and no valid signature key
         if (Optional.ofNullable(MacAppImageBuilder.
-                    SIGN_BUNDLE.fetchFrom(p)).orElse(Boolean.FALSE)) {
-            String signingIdentity = DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(p);
+                    SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) {
+            String signingIdentity =
+                    DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params);
             if (signingIdentity == null) {
                 throw new ConfigException(
                         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;
     }
 
-    File doBundle(Map<String, ? super Object> p, File outputDirectory,
+    File doBundle(Map<String, ? super Object> params, File outputDirectory,
             boolean dependentTask) throws PackagerException {
-        if (StandardBundlerParam.isRuntimeInstaller(p)) {
-            return PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
+        if (StandardBundlerParam.isRuntimeInstaller(params)) {
+            return PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
         } else {
-            return doAppBundle(p, outputDirectory, dependentTask);
+            return doAppBundle(params, outputDirectory, dependentTask);
         }
     }
 
-    File doAppBundle(Map<String, ? super Object> p, File outputDirectory,
+    File doAppBundle(Map<String, ? super Object> params, File outputDirectory,
             boolean dependentTask) throws PackagerException {
         try {
-            File rootDirectory = createRoot(p, outputDirectory, dependentTask,
-                    APP_NAME.fetchFrom(p) + ".app");
+            File rootDirectory = createRoot(params, outputDirectory,
+                    dependentTask, APP_NAME.fetchFrom(params) + ".app");
             AbstractAppImageBuilder appBuilder =
-                    new MacAppImageBuilder(p, outputDirectory.toPath());
-            if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) {
-                JLinkBundlerHelper.execute(p, appBuilder);
+                    new MacAppImageBuilder(params, outputDirectory.toPath());
+            if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(params) == null ) {
+                JLinkBundlerHelper.execute(params, appBuilder);
             } else {
-                StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder);
+                StandardBundlerParam.copyPredefinedRuntimeImage(
+                        params, appBuilder);
             }
             return rootDirectory;
         } catch (PackagerException pe) {
             throw pe;
         } catch (Exception ex) {

@@ -324,59 +268,31 @@
     public String getName() {
         return I18N.getString("app.bundler.name");
     }
 
     @Override
-    public String getDescription() {
-        return I18N.getString("app.bundler.description");
-    }
-
-    @Override
     public String getID() {
         return "mac.app";
     }
 
     @Override
     public String getBundleType() {
         return "IMAGE";
     }
 
     @Override
-    public Collection<BundlerParamInfo<?>> getBundleParameters() {
-        return getAppBundleParameters();
-    }
-
-    public static Collection<BundlerParamInfo<?>> getAppBundleParameters() {
-        return Arrays.asList(
-                APP_NAME,
-                APP_RESOURCES,
-                ARGUMENTS,
-                BUNDLE_ID_SIGNING_PREFIX,
-                CLASSPATH,
-                DEVELOPER_ID_APP_SIGNING_KEY,
-                ICON_ICNS,
-                JAVA_OPTIONS,
-                MAC_CATEGORY,
-                MAC_CF_BUNDLE_IDENTIFIER,
-                MAC_CF_BUNDLE_NAME,
-                MAC_CF_BUNDLE_VERSION,
-                MAIN_CLASS,
-                MAIN_JAR,
-                SIGNING_KEYCHAIN,
-                VERSION,
-                VERBOSE
-        );
-    }
-
-
-    @Override
     public File execute(Map<String, ? super Object> params,
             File outputParentDir) throws PackagerException {
         return doBundle(params, outputParentDir, false);
     }
 
     @Override
     public boolean supported(boolean runtimeInstaller) {
-        return Platform.getPlatform() == Platform.MAC;
+        return true;
+    }
+
+    @Override
+    public boolean isDefault() {
+        return false;
     }
 
 }
< prev index next >