< prev index next >

src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Arguments.java

Print this page

        

@@ -20,17 +20,18 @@
  *
  * 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.FileInputStream;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.EnumSet;

@@ -60,42 +61,22 @@
  * Generates List of Bundlers from BundleParams valid for this platform.
  * Executes each Bundler in the list.
  */
 public class Arguments {
     private static final ResourceBundle I18N = ResourceBundle.getBundle(
-            "jdk.jpackage.internal.resources.MainResources");
-
-    private static final String APPIMAGE_MODE = "create-app-image";
-    private static final String INSTALLER_MODE = "create-installer";
+            "jdk.incubator.jpackage.internal.resources.MainResources");
 
     private static final String FA_EXTENSIONS = "extension";
     private static final String FA_CONTENT_TYPE = "mime-type";
     private static final String FA_DESCRIPTION = "description";
     private static final String FA_ICON = "icon";
 
-    public static final BundlerParamInfo<Boolean> CREATE_APP_IMAGE =
-            new StandardBundlerParam<>(
-                    APPIMAGE_MODE,
-                    Boolean.class,
-                    p -> Boolean.FALSE,
-                    (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
-                            true : Boolean.valueOf(s));
-
-    public static final BundlerParamInfo<Boolean> CREATE_INSTALLER =
-            new StandardBundlerParam<>(
-                    INSTALLER_MODE,
-                    Boolean.class,
-                    p -> Boolean.FALSE,
-                    (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
-                            true : Boolean.valueOf(s));
-
     // regexp for parsing args (for example, for additional launchers)
     private static Pattern pattern = Pattern.compile(
           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
 
     private DeployParams deployParams = null;
-    private BundlerType bundleType = null;
 
     private int pos = 0;
     private List<String> argList = null;
 
     private List<CLIOptions> allOptions = null;

@@ -104,21 +85,17 @@
     private String output = null;
 
     private boolean hasMainJar = false;
     private boolean hasMainClass = false;
     private boolean hasMainModule = false;
-    private boolean hasTargetFormat = false;
-    private boolean hasAppImage = false;
     public boolean userProvidedBuildRoot = false;
 
     private String buildRoot = null;
     private String mainJarPath = null;
 
     private static boolean runtimeInstaller = false;
 
-    private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
-
     private List<AddLauncherArguments> addLaunchers = null;
 
     private static Map<String, CLIOptions> argIds = new HashMap<>();
     private static Map<String, CLIOptions> argShortIds = new HashMap<>();
 

@@ -130,76 +107,58 @@
                 argShortIds.put(option.getShortIdWithPrefix(), option);
             }
         });
     }
 
-    public Arguments(String[] args) throws PackagerException {
+    public Arguments(String[] args) {
         argList = new ArrayList<String>(args.length);
         for (String arg : args) {
             argList.add(arg);
         }
-        Log.debug ("\njpackage argument list: \n" + argList + "\n");
+        Log.verbose ("\njpackage argument list: \n" + argList + "\n");
         pos = 0;
 
         deployParams = new DeployParams();
-        bundleType = BundlerType.NONE;
 
         allOptions = new ArrayList<>();
 
         addLaunchers = new ArrayList<>();
+
+        output = Paths.get("").toAbsolutePath().toString();
+        deployParams.setOutput(new File(output));
     }
 
     // CLIOptions is public for DeployParamsTest
     public enum CLIOptions {
-        CREATE_APP_IMAGE(APPIMAGE_MODE, OptionCategories.MODE, () -> {
-            context().bundleType = BundlerType.IMAGE;
-            context().deployParams.setTargetFormat("image");
-            setOptionValue(APPIMAGE_MODE, true);
-        }),
-
-        CREATE_INSTALLER(INSTALLER_MODE, OptionCategories.MODE, () -> {
-            setOptionValue(INSTALLER_MODE, true);
-            context().bundleType = BundlerType.INSTALLER;
-            String format = "installer";
-            context().deployParams.setTargetFormat(format);
-        }),
-
-        INSTALLER_TYPE("installer-type", OptionCategories.PROPERTY, () -> {
-            String type = popArg();
-            if (BundlerType.INSTALLER.equals(context().bundleType)) {
-                context().deployParams.setTargetFormat(type);
-                context().hasTargetFormat = true;
-            }
-            setOptionValue("installer-type", type);
+        PACKAGE_TYPE("type", "t", OptionCategories.PROPERTY, () -> {
+            context().deployParams.setTargetFormat(popArg());
         }),
 
         INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
             context().input = popArg();
             setOptionValue("input", context().input);
         }),
 
-        OUTPUT ("output", "o", OptionCategories.PROPERTY, () -> {
+        OUTPUT ("dest", "d", OptionCategories.PROPERTY, () -> {
             context().output = popArg();
             context().deployParams.setOutput(new File(context().output));
         }),
 
-        DESCRIPTION ("description", "d", OptionCategories.PROPERTY),
+        DESCRIPTION ("description", OptionCategories.PROPERTY),
 
         VENDOR ("vendor", OptionCategories.PROPERTY),
 
         APPCLASS ("main-class", OptionCategories.PROPERTY, () -> {
             context().hasMainClass = true;
             setOptionValue("main-class", popArg());
         }),
 
         NAME ("name", "n", OptionCategories.PROPERTY),
 
-        IDENTIFIER ("identifier", OptionCategories.PROPERTY),
-
         VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
             setOptionValue("verbose", true);
-            Log.setVerbose(true);
+            Log.setVerbose();
         }),
 
         RESOURCE_DIR("resource-dir",
                 OptionCategories.PROPERTY, () -> {
             String resourceDir = popArg();

@@ -217,10 +176,12 @@
 
         LICENSE_FILE ("license-file", OptionCategories.PROPERTY),
 
         VERSION ("app-version", OptionCategories.PROPERTY),
 
+        RELEASE ("linux-app-release", OptionCategories.PROPERTY),
+
         JAVA_OPTIONS ("java-options", OptionCategories.PROPERTY, () -> {
             List<String> args = getArgumentList(popArg());
             args.forEach(a -> setOptionValue("java-options", a));
         }),
 

@@ -273,22 +234,19 @@
             }
             context().addLaunchers.add(
                 new AddLauncherArguments(name, filename));
         }),
 
-        TEMP_ROOT ("temp-root", OptionCategories.PROPERTY, () -> {
+        TEMP_ROOT ("temp", OptionCategories.PROPERTY, () -> {
             context().buildRoot = popArg();
             context().userProvidedBuildRoot = true;
-            setOptionValue("temp-root", context().buildRoot);
+            setOptionValue("temp", context().buildRoot);
         }),
 
         INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
 
-        PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY, ()-> {
-            setOptionValue("app-image", popArg());
-            context().hasAppImage = true;
-        }),
+        PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY),
 
         PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
 
         MAIN_JAR ("main-jar",  OptionCategories.PROPERTY, () -> {
             context().mainJarPath = popArg();

@@ -303,23 +261,24 @@
 
         ADD_MODULES ("add-modules", OptionCategories.MODULAR),
 
         MODULE_PATH ("module-path", "p", OptionCategories.MODULAR),
 
+        BIND_SERVICES ("bind-services", OptionCategories.PROPERTY, () -> {
+            setOptionValue("bind-services", true);
+        }),
+
         MAC_SIGN ("mac-sign", "s", OptionCategories.PLATFORM_MAC, () -> {
             setOptionValue("mac-sign", true);
         }),
 
-        MAC_BUNDLE_NAME ("mac-bundle-name", OptionCategories.PLATFORM_MAC),
+        MAC_BUNDLE_NAME ("mac-package-name", OptionCategories.PLATFORM_MAC),
 
-        MAC_BUNDLE_IDENTIFIER("mac-bundle-identifier",
+        MAC_BUNDLE_IDENTIFIER("mac-package-identifier",
                     OptionCategories.PLATFORM_MAC),
 
-        MAC_APP_STORE_CATEGORY ("mac-app-store-category",
-                    OptionCategories.PLATFORM_MAC),
-
-        MAC_BUNDLE_SIGNING_PREFIX ("mac-bundle-signing-prefix",
+        MAC_BUNDLE_SIGNING_PREFIX ("mac-package-signing-prefix",
                     OptionCategories.PLATFORM_MAC),
 
         MAC_SIGNING_KEY_NAME ("mac-signing-key-user-name",
                     OptionCategories.PLATFORM_MAC),
 

@@ -348,31 +307,37 @@
         WIN_DIR_CHOOSER ("win-dir-chooser",
                 OptionCategories.PLATFORM_WIN, () -> {
             setOptionValue("win-dir-chooser", true);
         }),
 
-        WIN_REGISTRY_NAME ("win-registry-name", OptionCategories.PLATFORM_WIN),
-
         WIN_UPGRADE_UUID ("win-upgrade-uuid",
                 OptionCategories.PLATFORM_WIN),
 
         WIN_CONSOLE_HINT ("win-console", OptionCategories.PLATFORM_WIN, () -> {
             setOptionValue("win-console", true);
         }),
 
-        LINUX_BUNDLE_NAME ("linux-bundle-name",
+        LINUX_BUNDLE_NAME ("linux-package-name",
                 OptionCategories.PLATFORM_LINUX),
 
         LINUX_DEB_MAINTAINER ("linux-deb-maintainer",
                 OptionCategories.PLATFORM_LINUX),
 
+        LINUX_CATEGORY ("linux-app-category",
+                OptionCategories.PLATFORM_LINUX),
+
         LINUX_RPM_LICENSE_TYPE ("linux-rpm-license-type",
                 OptionCategories.PLATFORM_LINUX),
 
         LINUX_PACKAGE_DEPENDENCIES ("linux-package-deps",
                 OptionCategories.PLATFORM_LINUX),
 
+        LINUX_SHORTCUT_HINT ("linux-shortcut",
+                OptionCategories.PLATFORM_LINUX, () -> {
+            setOptionValue("linux-shortcut", true);
+        }),
+
         LINUX_MENU_GROUP ("linux-menu-group", OptionCategories.PLATFORM_LINUX);
 
         private final String id;
         private final String shortId;
         private final OptionCategories category;

@@ -416,12 +381,11 @@
         public String getId() {
             return this.id;
         }
 
         String getIdWithPrefix() {
-            String prefix = isMode() ? "" : "--";
-            return prefix + this.id;
+            return "--" + this.id;
         }
 
         String getShortIdWithPrefix() {
             return this.shortId == null ? null : "-" + this.shortId;
         }

@@ -432,18 +396,10 @@
             } else {
                 defaultAction();
             }
         }
 
-        boolean isMode() {
-            return category == OptionCategories.MODE;
-        }
-
-        OptionCategories getCategory() {
-            return category;
-        }
-
         private void defaultAction() {
             context().deployParams.addBundleArgument(id, popArg());
         }
 
         private static void setOptionValue(String option, Object value) {

@@ -463,29 +419,24 @@
 
         private static void nextArg() {
             context().pos++;
         }
 
-        private static void prevArg() {
-            context().pos--;
-        }
-
         private static boolean hasNextArg() {
             return context().pos < context().argList.size();
         }
     }
 
     enum OptionCategories {
-        MODE,
         MODULAR,
         PROPERTY,
         PLATFORM_MAC,
         PLATFORM_WIN,
         PLATFORM_LINUX;
     }
 
-    public boolean processArguments() throws Exception {
+    public boolean processArguments() {
         try {
 
             // init context of arguments
             CLIOptions.setContext(this);
 

@@ -501,32 +452,25 @@
                 } else {
                     throw new PackagerException("ERR_InvalidOption", arg);
                 }
             }
 
-            if (allOptions.isEmpty() || !allOptions.get(0).isMode()) {
-                // first argument should always be a mode.
-                throw new PackagerException("ERR_MissingMode");
-            }
-
             if (hasMainJar && !hasMainClass) {
                 // try to get main-class from manifest
                 String mainClass = getMainClassFromManifest();
                 if (mainClass != null) {
                     CLIOptions.setOptionValue(
                             CLIOptions.APPCLASS.getId(), mainClass);
                 }
             }
 
-            // display warning for arguments that are not supported
+            // display error for arguments that are not supported
             // for current configuration.
 
             validateArguments();
 
-            addResources(deployParams, input);
-
-            deployParams.setBundleType(bundleType);
+            addResources(deployParams, input, mainJarPath);
 
             List<Map<String, ? super Object>> launchersAsMap =
                     new ArrayList<>();
 
             for (AddLauncherArguments sl : addLaunchers) {

@@ -565,171 +509,161 @@
             }
             if (runtimeInstaller && bp.getName() == null) {
                 throw new PackagerException("ERR_NoJreInstallerName");
             }
 
-            return generateBundle(bp.getBundleParamsAsMap());
+            generateBundle(bp.getBundleParamsAsMap());
+            return true;
         } catch (Exception e) {
             if (Log.isVerbose()) {
-                throw e;
+                Log.verbose(e);
             } else {
                 String msg1 = e.getMessage();
                 Log.error(msg1);
                 if (e.getCause() != null && e.getCause() != e) {
                     String msg2 = e.getCause().getMessage();
-                    if (!msg1.contains(msg2)) {
+                    if (msg2 != null && !msg1.contains(msg2)) {
                         Log.error(msg2);
                     }
                 }
-                return false;
             }
+            return false;
         }
     }
 
     private void validateArguments() throws PackagerException {
-        CLIOptions mode = allOptions.get(0);
-        boolean imageOnly = (mode == CLIOptions.CREATE_APP_IMAGE);
+        String type = deployParams.getTargetFormat();
+        String ptype = (type != null) ? type : "default";
+        boolean imageOnly = deployParams.isTargetAppImage();
         boolean hasAppImage = allOptions.contains(
                 CLIOptions.PREDEFINED_APP_IMAGE);
         boolean hasRuntime = allOptions.contains(
                 CLIOptions.PREDEFINED_RUNTIME_IMAGE);
         boolean installerOnly = !imageOnly && hasAppImage;
-        boolean runtimeInstall = !imageOnly && hasRuntime && !hasAppImage &&
+        runtimeInstaller = !imageOnly && hasRuntime && !hasAppImage &&
                 !hasMainModule && !hasMainJar;
 
         for (CLIOptions option : allOptions) {
             if (!ValidOptions.checkIfSupported(option)) {
                 // includes option valid only on different platform
                 throw new PackagerException("ERR_UnsupportedOption",
                         option.getIdWithPrefix());
             }
             if (imageOnly) {
                 if (!ValidOptions.checkIfImageSupported(option)) {
-                    throw new PackagerException("ERR_NotImageOption",
-                        option.getIdWithPrefix());
+                    throw new PackagerException("ERR_InvalidTypeOption",
+                        option.getIdWithPrefix(), type);
                 }
-            } else if (installerOnly || runtimeInstall) {
+            } else if (installerOnly || runtimeInstaller) {
                 if (!ValidOptions.checkIfInstallerSupported(option)) {
-                    String key = runtimeInstaller ?
-                        "ERR_NoInstallerEntryPoint" : "ERR_NotInstallerOption";
-                    throw new PackagerException(key, option.getIdWithPrefix());
+                    if (runtimeInstaller) {
+                        throw new PackagerException("ERR_NoInstallerEntryPoint",
+                            option.getIdWithPrefix());
+                    } else {
+                        throw new PackagerException("ERR_InvalidTypeOption",
+                            option.getIdWithPrefix(), ptype);
+                   }
                 }
             }
         }
         if (installerOnly && hasRuntime) {
             // note --runtime-image is only for image or runtime installer.
-            throw new PackagerException("ERR_NotInstallerOption",
-                    CLIOptions.PREDEFINED_RUNTIME_IMAGE.getIdWithPrefix());
+            throw new PackagerException("ERR_InvalidTypeOption",
+                    CLIOptions.PREDEFINED_RUNTIME_IMAGE.getIdWithPrefix(),
+                    ptype);
         }
         if (hasMainJar && hasMainModule) {
             throw new PackagerException("ERR_BothMainJarAndModule");
         }
         if (imageOnly && !hasMainJar && !hasMainModule) {
             throw new PackagerException("ERR_NoEntryPoint");
         }
     }
 
-    private List<jdk.jpackage.internal.Bundler> getPlatformBundlers() {
-
-        if (platformBundlers != null) {
-            return platformBundlers;
+    private jdk.incubator.jpackage.internal.Bundler getPlatformBundler() {
+        boolean appImage = deployParams.isTargetAppImage();
+        String type = deployParams.getTargetFormat();
+        String bundleType = (appImage ?  "IMAGE" : "INSTALLER");
+
+        for (jdk.incubator.jpackage.internal.Bundler bundler :
+                Bundlers.createBundlersInstance().getBundlers(bundleType)) {
+            if (type == null) {
+                 if (bundler.isDefault()
+                         && bundler.supported(runtimeInstaller)) {
+                     return bundler;
         }
-
-        platformBundlers = new ArrayList<>();
-        for (jdk.jpackage.internal.Bundler bundler :
-                Bundlers.createBundlersInstance().getBundlers(
-                        bundleType.toString())) {
-            if (hasTargetFormat && deployParams.getTargetFormat() != null &&
-                    !deployParams.getTargetFormat().equalsIgnoreCase(
-                    bundler.getID())) {
-                continue;
+            } else {
+                 if ((appImage || type.equalsIgnoreCase(bundler.getID()))
+                         && bundler.supported(runtimeInstaller)) {
+                     return bundler;
             }
-            if (bundler.supported(runtimeInstaller)) {
-                 platformBundlers.add(bundler);
             }
         }
-
-        return platformBundlers;
+        return null;
     }
 
-    private boolean generateBundle(Map<String,? super Object> params)
+    private void generateBundle(Map<String,? super Object> params)
             throws PackagerException {
 
         boolean bundleCreated = false;
 
-        // the temp-root needs to be fetched from the params early,
+        // the temp dir needs to be fetched from the params early,
         // to prevent each copy of the params (such as may be used for
-        // additional launchers) from generating a separate temp-root when
+        // additional launchers) from generating a separate temp dir when
         // the default is used (the default is a new temp directory)
         // The bundler.cleanup() below would not otherwise be able to
         // clean these extra (and unneeded) temp directories.
         StandardBundlerParam.TEMP_ROOT.fetchFrom(params);
-        List<jdk.jpackage.internal.Bundler> bundlers = getPlatformBundlers();
-        if (bundlers.isEmpty()) {
+
+        // determine what bundler to run
+        jdk.incubator.jpackage.internal.Bundler bundler = getPlatformBundler();
+
+        if (bundler == null) {
             throw new PackagerException("ERR_InvalidInstallerType",
                     deployParams.getTargetFormat());
         }
-        PackagerException pe = null;
-        for (jdk.jpackage.internal.Bundler bundler : bundlers) {
+
             Map<String, ? super Object> localParams = new HashMap<>(params);
             try {
-                if (bundler.validate(localParams)) {
-                    File result =
-                            bundler.execute(localParams, deployParams.outdir);
-                    if (!userProvidedBuildRoot) {
-                        bundler.cleanup(localParams);
-                    }
+            bundler.validate(localParams);
+            File result = bundler.execute(localParams, deployParams.outdir);
                     if (result == null) {
                         throw new PackagerException("MSG_BundlerFailed",
                                 bundler.getID(), bundler.getName());
                     }
-                    bundleCreated = true; // at least one bundle was created
-                }
                 Log.verbose(MessageFormat.format(
                         I18N.getString("message.bundle-created"),
                         bundler.getName()));
-            } catch (UnsupportedPlatformException upe) {
-                Log.debug(upe);
-                if (pe == null) {
-                    pe = new PackagerException(upe,
-                            "MSG_BundlerPlatformException", bundler.getName());
-                }
             } catch (ConfigException e) {
-                Log.debug(e);
-                if (pe == null) {
-                    pe = (e.getAdvice() != null) ?
-                            new PackagerException(e,
-                            "MSG_BundlerConfigException",
-                            bundler.getName(), e.getMessage(), e.getAdvice()) :
-                            new PackagerException(e,
+            Log.verbose(e);
+            if (e.getAdvice() != null)  {
+                throw new PackagerException(e, "MSG_BundlerConfigException",
+                        bundler.getName(), e.getMessage(), e.getAdvice());
+            } else {
+                throw new PackagerException(e,
                            "MSG_BundlerConfigExceptionNoAdvice",
                             bundler.getName(), e.getMessage());
                 }
             } catch (RuntimeException re) {
-                Log.debug(re);
-                if (pe == null) {
-                    pe = new PackagerException(re,
-                            "MSG_BundlerRuntimeException",
+            Log.verbose(re);
+            throw new PackagerException(re, "MSG_BundlerRuntimeException",
                             bundler.getName(), re.toString());
-                }
             } finally {
                 if (userProvidedBuildRoot) {
                     Log.verbose(MessageFormat.format(
                             I18N.getString("message.debug-working-directory"),
                             (new File(buildRoot)).getAbsolutePath()));
+            } else {
+                // always clean up the temporary directory created
+                // when --temp option not used.
+                bundler.cleanup(localParams);
                 }
             }
         }
-        if (pe != null) {
-            // throw packager exception only after trying all bundlers
-            throw pe;
-        }
-        return bundleCreated;
-    }
 
     private void addResources(DeployParams deployParams,
-            String inputdir) throws PackagerException {
+            String inputdir, String mainJar) throws PackagerException {
 
         if (inputdir == null || inputdir.isEmpty()) {
             return;
         }
 

@@ -750,39 +684,21 @@
         } catch (IOException e) {
             Log.error("Unable to add resources: " + e.getMessage());
         }
         fileNames.forEach(file -> deployParams.addResource(baseDir, file));
 
-        deployParams.setClasspath();
-    }
-
-    static boolean isCLIOption(String arg) {
-        return toCLIOption(arg) != null;
+        deployParams.setClasspath(mainJar);
     }
 
     static CLIOptions toCLIOption(String arg) {
         CLIOptions option;
         if ((option = argIds.get(arg)) == null) {
             option = argShortIds.get(arg);
         }
         return option;
     }
 
-    static Map<String, String> getArgumentMap(String inputString) {
-        Map<String, String> map = new HashMap<>();
-        List<String> list = getArgumentList(inputString);
-        for (String pair : list) {
-            int equals = pair.indexOf("=");
-            if (equals != -1) {
-                String key = pair.substring(0, equals);
-                String value = pair.substring(equals+1, pair.length());
-                map.put(key, value);
-            }
-        }
-        return map;
-    }
-
     static Map<String, String> getPropertiesFromFile(String filename) {
         Map<String, String> map = new HashMap<>();
         // load properties file
         File file = new File(filename);
         Properties properties = new Properties();
< prev index next >