8214021: Create additional automated tests for jpackager JDK-8200758-branch
authorherrick
Wed, 21 Nov 2018 12:00:01 -0500
branchJDK-8200758-branch
changeset 57030 902f4c4fba42
parent 57029 750a23664c11
child 57031 ea4755429ed8
8214021: Create additional automated tests for jpackager Submitten-by: almatvee Reviewed-by: herrick. kcr
src/jdk.jpackager/linux/classes/jdk/jpackager/internal/builders/linux/LinuxAppImageBuilder.java
src/jdk.jpackager/linux/classes/jdk/jpackager/internal/linux/LinuxDebBundler.java
src/jdk.jpackager/linux/classes/jdk/jpackager/internal/linux/LinuxRpmBundler.java
src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacAppBundler.java
src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacAppStoreBundler.java
src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacDmgBundler.java
src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacPkgBundler.java
src/jdk.jpackager/share/classes/jdk/jpackager/internal/AbstractBundler.java
src/jdk.jpackager/share/classes/jdk/jpackager/internal/DeployParams.java
src/jdk.jpackager/share/classes/jdk/jpackager/main/Main.java
src/jdk.jpackager/windows/classes/jdk/jpackager/internal/builders/windows/WindowsAppImageBuilder.java
src/jdk.jpackager/windows/classes/jdk/jpackager/internal/windows/WinExeBundler.java
src/jdk.jpackager/windows/classes/jdk/jpackager/internal/windows/WinMsiBundler.java
test/jdk/tools/jpackager/JPackagerHelpTest.java
test/jdk/tools/jpackager/JPackagerInvalidArgTest.java
test/jdk/tools/jpackager/JPackagerNoArgTest.java
--- a/src/jdk.jpackager/linux/classes/jdk/jpackager/internal/builders/linux/LinuxAppImageBuilder.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/linux/classes/jdk/jpackager/internal/builders/linux/LinuxAppImageBuilder.java	Wed Nov 21 12:00:01 2018 -0500
@@ -109,7 +109,7 @@
         Files.createDirectories(runtimeDir);
         Files.createDirectories(resourcesDir);
     }
-    
+
     public LinuxAppImageBuilder(String appName, Path imageOutDir)
             throws IOException {
         super(null, imageOutDir.resolve(appName));
@@ -186,37 +186,31 @@
     public void prepareApplicationFiles() throws IOException {
         Map<String, ? super Object> originalParams = new HashMap<>(params);
 
-        try {
-            // create the primary launcher
-            createLauncherForEntryPoint(params, root);
+        // create the primary launcher
+        createLauncherForEntryPoint(params, root);
 
-            // Copy library to the launcher folder
-            try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) {
-               writeEntry(is_lib,  root.resolve(LIBRARY_NAME));
-            }
+        // Copy library to the launcher folder
+        try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) {
+            writeEntry(is_lib, root.resolve(LIBRARY_NAME));
+        }
 
-            // create the secondary launchers, if any
-            List<Map<String, ? super Object>> entryPoints =
-                    StandardBundlerParam.SECONDARY_LAUNCHERS.fetchFrom(params);
-            for (Map<String, ? super Object> entryPoint : entryPoints) {
-                Map<String, ? super Object> tmp = new HashMap<>(originalParams);
-                tmp.putAll(entryPoint);
-                // remove name.fs that was calculated for main launcher.
-                // otherwise, wrong launcher name will be selected.
-                tmp.remove(APP_FS_NAME.getID());
-                createLauncherForEntryPoint(tmp, root);
-            }
+        // create the secondary launchers, if any
+        List<Map<String, ? super Object>> entryPoints
+                = StandardBundlerParam.SECONDARY_LAUNCHERS.fetchFrom(params);
+        for (Map<String, ? super Object> entryPoint : entryPoints) {
+            Map<String, ? super Object> tmp = new HashMap<>(originalParams);
+            tmp.putAll(entryPoint);
+            // remove name.fs that was calculated for main launcher.
+            // otherwise, wrong launcher name will be selected.
+            tmp.remove(APP_FS_NAME.getID());
+            createLauncherForEntryPoint(tmp, root);
+        }
 
-            // Copy class path entries to Java folder
-            copyApplication();
+        // Copy class path entries to Java folder
+        copyApplication();
 
-            // Copy icon to Resources folder
-            copyIcon();
-
-        } catch (IOException ex) {
-            Log.error("Exception: " + ex);
-            Log.debug(ex);
-        }
+        // Copy icon to Resources folder
+        copyIcon();
     }
 
     @Override
--- a/src/jdk.jpackager/linux/classes/jdk/jpackager/internal/linux/LinuxDebBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/linux/classes/jdk/jpackager/internal/linux/LinuxDebBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -410,7 +410,8 @@
                         PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
                         (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
                         !Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
-                        !Log.isDebug()) {
+                        !Log.isDebug() &&
+                        !Log.isVerbose()) {
                     IOUtils.deleteRecursive(imageDir);
                 } else if (imageDir != null) {
                     Log.verbose(MessageFormat.format(I18N.getString(
--- a/src/jdk.jpackager/linux/classes/jdk/jpackager/internal/linux/LinuxRpmBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/linux/classes/jdk/jpackager/internal/linux/LinuxRpmBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -322,7 +322,8 @@
                         PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
                         (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
                         !Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
-                        !Log.isDebug()) {
+                        !Log.isDebug() &&
+                        !Log.isVerbose()) {
                     IOUtils.deleteRecursive(imageDir);
                 } else if (imageDir != null) {
                     Log.verbose(MessageFormat.format(I18N.getString(
@@ -713,7 +714,7 @@
         pb = pb.directory(RPM_IMAGE_DIR.fetchFrom(params));
         IOUtils.exec(pb, false);
 
-        if (!Log.isDebug()) {
+        if (!Log.isDebug() && !Log.isVerbose()) {
             IOUtils.deleteRecursive(broot);
         }
 
--- a/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacAppBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacAppBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -403,6 +403,10 @@
     }
 
     public void cleanupConfigFiles(Map<String, ? super Object> params) {
+        if (Log.isDebug() || Log.isVerbose()) {
+            return;
+        }
+
         if (CONFIG_ROOT.fetchFrom(params) != null) {
             getConfig_Icon(params).delete();
             getConfig_InfoPlist(params).delete();
--- a/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacAppStoreBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacAppStoreBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -229,7 +229,8 @@
                        PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
                        (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
                        !Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
-                       !Log.isDebug()) {
+                       !Log.isDebug() &&
+                       !Log.isVerbose()) {
                     IOUtils.deleteRecursive(appImageDir);
                 } else if (appImageDir != null) {
                     Log.verbose(MessageFormat.format(I18N.getString(
@@ -248,6 +249,10 @@
     }
 
     protected void cleanupConfigFiles(Map<String, ? super Object> params) {
+        if (Log.isDebug() || Log.isVerbose()) {
+            return;
+        }
+
         if (getConfig_Entitlements(params) != null) {
             getConfig_Entitlements(params).delete();
         }
--- a/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacDmgBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacDmgBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -103,7 +103,8 @@
                         PREDEFINED_APP_IMAGE.fetchFrom(params) == null &&
                         (PREDEFINED_RUNTIME_IMAGE.fetchFrom(params) == null ||
                         !Arguments.CREATE_JRE_INSTALLER.fetchFrom(params)) &&
-                        !Log.isDebug()) {
+                        !Log.isDebug() &&
+                        !Log.isVerbose()) {
                     IOUtils.deleteRecursive(appImageDir);
                 } else if (appImageDir != null) {
                     Log.verbose(MessageFormat.format(I18N.getString(
@@ -123,6 +124,10 @@
 
     //remove
     protected void cleanupConfigFiles(Map<String, ? super Object> params) {
+        if (Log.isDebug() || Log.isVerbose()) {
+            return;
+        }
+
         if (getConfig_VolumeBackground(params) != null) {
             getConfig_VolumeBackground(params).delete();
         }
--- a/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacPkgBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/macosx/classes/jdk/jpackager/internal/mac/MacPkgBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -201,7 +201,8 @@
                         PREDEFINED_APP_IMAGE.fetchFrom(params) == null &&
                         (PREDEFINED_RUNTIME_IMAGE.fetchFrom(params) == null ||
                         !Arguments.CREATE_JRE_INSTALLER.fetchFrom(params)) &&
-                        !Log.isDebug()) {
+                        !Log.isDebug() &&
+                        !Log.isVerbose()) {
                     IOUtils.deleteRecursive(appImageDir);
                 } else if (appImageDir != null) {
                     Log.verbose(MessageFormat.format(I18N.getString(
@@ -230,6 +231,10 @@
     }
 
     private void cleanupPackagesFiles(Map<String, ? super Object> params) {
+        if (Log.isDebug() || Log.isVerbose()) {
+            return;
+        }
+
         if (getPackages_AppPackage(params) != null) {
             getPackages_AppPackage(params).delete();
         }
@@ -258,6 +263,10 @@
     }
 
     private void cleanupConfigFiles(Map<String, ? super Object> params) {
+        if (Log.isDebug() || Log.isVerbose()) {
+            return;
+        }
+
         if (getConfig_DistributionXMLFile(params) != null) {
             getConfig_DistributionXMLFile(params).delete();
         }
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/AbstractBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/AbstractBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -184,7 +184,7 @@
     @Override
     public void cleanup(Map<String, ? super Object> params) {
         try {
-            if (!Log.isDebug()) {
+            if (!Log.isDebug() && !Log.isVerbose()) {
                 IOUtils.deleteRecursive(
                         StandardBundlerParam.BUILD_ROOT.fetchFrom(params));
             }
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/DeployParams.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/DeployParams.java	Wed Nov 21 12:00:01 2018 -0500
@@ -341,22 +341,6 @@
             throw new PackagerException("ERR_MissingArgument", "--output");
         }
 
-        if (getBundleType() == BundlerType.IMAGE) {
-            String input = (String)bundlerArguments.get(Arguments.CLIOptions.INPUT.getId());
-            if (input == null) {
-                throw new PackagerException("ERR_MissingArgument", "--input");
-            }
-        } else if (getBundleType() == BundlerType.INSTALLER) {
-            if (!Arguments.isJreInstaller()) {
-                String input = (String)bundlerArguments.get(Arguments.CLIOptions.INPUT.getId());
-                String appImage = (String)bundlerArguments.get(
-                    Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
-                if (input == null && appImage == null) {
-                    throw new PackagerException("ERR_MissingArgument", "--input or --app-image");
-                }
-            }
-        }
-
         boolean hasModule = (bundlerArguments.get(
                 Arguments.CLIOptions.MODULE.getId()) != null);
         boolean hasImage = (bundlerArguments.get(
@@ -365,6 +349,41 @@
                 Arguments.CLIOptions.APPCLASS.getId()) != null);
         boolean hasMain = (bundlerArguments.get(
                 Arguments.CLIOptions.MAIN_JAR.getId()) != null);
+        boolean hasRuntimeImage = (bundlerArguments.get(
+                Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
+        boolean hasInput = (bundlerArguments.get(
+                Arguments.CLIOptions.INPUT.getId()) != null);
+        boolean hasModulePath = (bundlerArguments.get(
+                Arguments.CLIOptions.MODULE_PATH.getId()) != null);
+        boolean hasAppImage = (bundlerArguments.get(
+                Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null);
+
+        if (getBundleType() == BundlerType.IMAGE) {
+            // Module application requires --runtime-image or --module-path
+            if (hasModule) {
+                if (!hasModulePath && !hasRuntimeImage) {
+                    throw new PackagerException("ERR_MissingArgument",
+                            "--runtime-image or --module-path");
+                }
+            } else {
+                if (!hasInput) {
+                    throw new PackagerException("ERR_MissingArgument", "--input");
+                }
+            }
+        } else if (getBundleType() == BundlerType.INSTALLER) {
+            if (!Arguments.isJreInstaller()) {
+                if (hasModule) {
+                    if (!hasModulePath && !hasRuntimeImage && !hasAppImage) {
+                        throw new PackagerException("ERR_MissingArgument",
+                            "--runtime-image, --module-path or --app-image");
+                    }
+                } else {
+                    if (!hasInput && !hasAppImage) {
+                        throw new PackagerException("ERR_MissingArgument", "--input or --app-image");
+                    }
+                }
+            }
+        }
 
         // if bundling non-modular image, or installer without app-image
         // then we need some resources and a main class
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/main/Main.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/main/Main.java	Wed Nov 21 12:00:01 2018 -0500
@@ -37,7 +37,7 @@
             ResourceBundle.getBundle("jdk.jpackager.internal.resources.Bundle");
 
     private static final String version = bundle.getString("MSG_Version")
-            + " " + System.getProperty("java.version") + "\n";
+            + " " + System.getProperty("java.version");
 
     /**
      * main(String... args)
--- a/src/jdk.jpackager/windows/classes/jdk/jpackager/internal/builders/windows/WindowsAppImageBuilder.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/windows/classes/jdk/jpackager/internal/builders/windows/WindowsAppImageBuilder.java	Wed Nov 21 12:00:01 2018 -0500
@@ -246,6 +246,10 @@
     }
 
     protected void cleanupConfigFiles(Map<String, ? super Object> params) {
+        if (Log.isDebug() || Log.isVerbose()) {
+            return;
+        }
+
         getConfig_AppIcon(params).delete();
         getConfig_ExecutableProperties(params).delete();
     }
@@ -290,10 +294,6 @@
                 tmp.putAll(entryPoint);
                 createLauncherForEntryPoint(tmp);
             }
-
-        } catch (IOException ex) {
-            Log.error("Exception: "+ex);
-            Log.verbose(ex);
         } finally {
             cleanupConfigFiles(params);
         }
--- a/src/jdk.jpackager/windows/classes/jdk/jpackager/internal/windows/WinExeBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/windows/classes/jdk/jpackager/internal/windows/WinExeBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -488,7 +488,8 @@
                         PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
                         (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
                         !Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
-                        !Log.isDebug()) {
+                        !Log.isDebug() &&
+                        !Log.isVerbose()) {
                     IOUtils.deleteRecursive(imageDir);
                 } else if (imageDir != null) {
                     Log.verbose(MessageFormat.format(
@@ -823,7 +824,7 @@
         // if there interior double quotes replace them with '-'
         return s.replaceAll("\"", "-");
     }
-        
+
     private final static String DEFAULT_INNO_SETUP_ICON =
             "icon_inno_setup.bmp";
 
--- a/src/jdk.jpackager/windows/classes/jdk/jpackager/internal/windows/WinMsiBundler.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/src/jdk.jpackager/windows/classes/jdk/jpackager/internal/windows/WinMsiBundler.java	Wed Nov 21 12:00:01 2018 -0500
@@ -596,7 +596,8 @@
                         PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
                         (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
                         !Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
-                        !Log.isDebug()) {
+                        !Log.isDebug() &&
+                        !Log.isVerbose()) {
                     IOUtils.deleteRecursive(imageDir);
                 } else if (imageDir != null) {
                     Log.verbose(MessageFormat.format(
@@ -614,6 +615,10 @@
     }
 
     protected void cleanupConfigFiles(Map<String, ? super Object> params) {
+        if (Log.isDebug() || Log.isVerbose()) {
+            return;
+        }
+
         if (getConfig_ProjectFile(params) != null) {
             getConfig_ProjectFile(params).delete();
         }
--- a/test/jdk/tools/jpackager/JPackagerHelpTest.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/test/jdk/tools/jpackager/JPackagerHelpTest.java	Wed Nov 21 12:00:01 2018 -0500
@@ -24,7 +24,9 @@
  /*
  * @test
  * @summary jpackager help test
+ * @library helpers
  * @build JPackagerHelper
+ * @build JPackagerPath
  * @modules jdk.jpackager
  * @run main/othervm -Xmx512m JPackagerHelpTest
  */
--- a/test/jdk/tools/jpackager/JPackagerInvalidArgTest.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/test/jdk/tools/jpackager/JPackagerInvalidArgTest.java	Wed Nov 21 12:00:01 2018 -0500
@@ -24,7 +24,9 @@
  /*
  * @test
  * @summary jpackager invalid argument test
+ * @library helpers
  * @build JPackagerHelper
+ * @build JPackagerPath
  * @modules jdk.jpackager
  * @run main/othervm -Xmx512m JPackagerInvalidArgTest
  */
--- a/test/jdk/tools/jpackager/JPackagerNoArgTest.java	Sun Nov 18 17:45:09 2018 -0500
+++ b/test/jdk/tools/jpackager/JPackagerNoArgTest.java	Wed Nov 21 12:00:01 2018 -0500
@@ -24,7 +24,9 @@
  /*
  * @test
  * @summary jpackager no argument test
+ * @library helpers
  * @build JPackagerHelper
+ * @build JPackagerPath
  * @modules jdk.jpackager
  * @run main/othervm -Xmx512m JPackagerNoArgTest
  */