changeset 346:b80a8efca46c

8170703: Fix failing testcases in javapackager test suite Reviewed-by: cbensen
author rgangadhar
date Wed, 07 Dec 2016 11:54:42 +0530
parents 0f148fa7a249
children 0787febc9b94
files functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/ConsoleBundlingManager.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/Constants.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxAbstractBundlerUtils.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxDebBundlerUtils.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxRPMBundlerUtils.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/MacDMGBundlerUtils.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/MacPKGBundlerUtils.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/WinAbstractBundlerUtils.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/FileAssociationTest.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/InstallDirTest.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/MainClassTest.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/jdk9test/CheckExecutablesAvailableTest.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/jdk9test/UnnamedModuleDependsOn3rdPartyModulesBundledWithEntireJreTest.java
diffstat 13 files changed, 106 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/ConsoleBundlingManager.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/ConsoleBundlingManager.java	Wed Dec 07 11:54:42 2016 +0530
@@ -61,7 +61,6 @@
             put("App Name", "-name");
             put("Title", "-title");
             put(VENDOR, "-vendor");
-            put(SERVICE_HINT, "-" + SERVICE_HINT);
 
             /*
              * JDK 9 CLI GNU style parameters
@@ -77,7 +76,7 @@
                     ICON, EMAIL, COPYRIGHT, LICENSE_TYPE, CATEGORY,
                     SHORTCUT_HINT, MENU_HINT, SYSTEM_WIDE, JVM_OPTIONS,
                     JVM_PROPERTIES, USER_JVM_OPTIONS,
-                    // SERVICE_HINT,
+                    SERVICE_HINT,
                     PREFERENCES_ID, MAIN_JAR, CLASSPATH,
                     BundleParams.PARAM_RUNTIME, MAC_APP_STORE_APP_SIGNING_KEY,
                     MAC_APP_STORE_ENTITLEMENTS, MAC_APP_STORE_PKG_SIGNING_KEY,
@@ -230,10 +229,6 @@
                 break;
             case "fxPackaging": // do nothing
                 break;
-            case SERVICE_HINT:
-                key2Value.add(new Pair<>(getMappedKeyAndCheck(key),
-                        new ArrayList<>(0)));
-                break;
             case APP_RESOURCES_LIST:
                 break;
 
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/Constants.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/Constants.java	Wed Dec 07 11:54:42 2016 +0530
@@ -12,16 +12,16 @@
  */
 public interface Constants {
     String MENU_HINT = "menuHint";
-    String SERVICE_HINT = "daemon";
+    String SERVICE_HINT = "serviceHint";
     String START_ON_INSTALL = "startOnInstall";
     String RUN_AT_STARTUP = "runAtStartup";
     String USER_JVM_OPTIONS = "userJvmOptions";
     String SHORTCUT_HINT = "shortcutHint";
-    String VENDOR = "Vendor";
+    String VENDOR = "vendor";
     String VERSION = "appVersion";
     String SYSTEM_WIDE = "systemWide";
     String EXE_SYSTEM_WIDE = "win.exe.systemWide";
-    String TITLE = "Title";
+    String TITLE = "title";
     String MENU_GROUP = "win.menuGroup";
     String DESCRIPTION = "description";
     String MAIN_JAR = "mainJar";
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxAbstractBundlerUtils.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxAbstractBundlerUtils.java	Wed Dec 07 11:54:42 2016 +0530
@@ -247,4 +247,28 @@
     public String getJavaExecutable() {
         return "java";
     }
+
+    protected Path findByExtension(Path dir, String extension, int maxDepth,
+            String applicationTitle) throws IOException {
+        Optional<Path> result = Files
+                .find(dir, maxDepth,
+                        (file, attr) -> {
+                            String name = file.toFile().getName();
+                            return name.toLowerCase().contains(
+                                    applicationTitle.toLowerCase())
+                            && name.endsWith("." + extension);
+                        })
+                .findFirst();
+
+        if (!result.isPresent()) {
+            result = Files.find(dir, maxDepth, (file, attr) -> file.toFile()
+                    .getName().endsWith("." + extension)).findFirst();
+        }
+
+        if (!result.isPresent()) {
+            throw new FileNotFoundException("*." + extension
+                    + " not found under " + dir + " with maxDepth=" + maxDepth);
+        }
+        return result.get();
+    }
 }
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxDebBundlerUtils.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxDebBundlerUtils.java	Wed Dec 07 11:54:42 2016 +0530
@@ -125,7 +125,7 @@
     public String install(AppWrapper app, String applicationTitle)
             throws IOException {
         String debPath = this.findByExtension(app.getBundlesDir(), "deb",
-                ROOT_DIRECTORY_DEPTH).toString();
+                ROOT_DIRECTORY_DEPTH, applicationTitle).toString();
         try {
             LOG.log(Level.INFO, "Installing {0}.", new Object[] { debPath });
             String[] cmd = new String[] { "sudo", "dpkg", "--install",
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxRPMBundlerUtils.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/LinuxRPMBundlerUtils.java	Wed Dec 07 11:54:42 2016 +0530
@@ -103,7 +103,7 @@
     public String install(AppWrapper app, String applicationTitle)
             throws IOException {
         String rpmPath = findByExtension(app.getBundlesDir(), "rpm",
-                ROOT_DIRECTORY_DEPTH).toString();
+                ROOT_DIRECTORY_DEPTH, applicationTitle).toString();
         try {
             LOG.log(Level.INFO, "Installing {0}.", rpmPath);
             String[] cmd = new String[] { "sudo", "rpm", "--install",
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/MacDMGBundlerUtils.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/MacDMGBundlerUtils.java	Wed Dec 07 11:54:42 2016 +0530
@@ -34,7 +34,7 @@
     public String install(AppWrapper app, String applicationTitle)
             throws IOException {
         Path dmg = findByExtension(app.getBundlesDir(), "dmg",
-                ROOT_DIRECTORY_DEPTH);
+                ROOT_DIRECTORY_DEPTH, applicationTitle);
         try {
             LOG.log(Level.INFO, "Installing {0}.", dmg);
             String[] cmd = new String[] { "hdiutil", "attach", dmg.toString() };
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/MacPKGBundlerUtils.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/MacPKGBundlerUtils.java	Wed Dec 07 11:54:42 2016 +0530
@@ -38,7 +38,7 @@
     public String install(AppWrapper app, String applicationTitle)
             throws IOException {
         Path pkg = findByExtension(app.getBundlesDir(), "pkg",
-                ROOT_DIRECTORY_DEPTH);
+                ROOT_DIRECTORY_DEPTH, applicationTitle);
         try {
             LOG.log(Level.INFO, "Installing {0}.", pkg);
             String[] cmd = new String[] { "sudo", "installer", "-pkg",
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/WinAbstractBundlerUtils.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/WinAbstractBundlerUtils.java	Wed Dec 07 11:54:42 2016 +0530
@@ -162,7 +162,7 @@
         return (value, app, applicationTitle) -> {
             try {
                 ProcessOutput out = Utils.runCommand(
-                        new String[] { "sc", "qc", applicationTitle }, true,
+                        new String[] { "sc", "qc",  applicationTitle, Integer.toString(2000) }, true,
                         CONFIG_INSTANCE.getRunTimeout());
                 assertTrue(
                         out.getOutputStream().parallelStream().map(String::trim)
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/FileAssociationTest.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/FileAssociationTest.java	Wed Dec 07 11:54:42 2016 +0530
@@ -11,6 +11,7 @@
 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.WIN_USER_FILE_ASSOCIATIONS;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
@@ -70,9 +71,10 @@
                     Arrays.asList(association1, association2));
             additionalParams.put(SYSTEM_WIDE, true);
             additionalParams.put(JVM_OPTIONS,
-                    DOUBLE_HYPHEN + ADD_EXPORTS + SPACE
+                    new ArrayList<String>(Arrays.asList(DOUBLE_HYPHEN
+                            + ADD_EXPORTS + SPACE
                             + "java.desktop/com.apple.eawt=ALL-UNNAMED" + ","
-                            + FileAssociationTest.COM_RM_MODULE_NAME);
+                            + FileAssociationTest.COM_RM_MODULE_NAME)));
             return additionalParams;
         };
     }
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/InstallDirTest.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/InstallDirTest.java	Wed Dec 07 11:54:42 2016 +0530
@@ -10,16 +10,25 @@
 import static com.oracle.appbundlers.utils.Config.CONFIG_INSTANCE;
 import static com.oracle.appbundlers.utils.Config.LICENSE_FILE_NAME;
 
+import java.io.File;
 import java.io.IOException;
+import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import com.oracle.appbundlers.tests.functionality.functionalinterface.AdditionalParams;
 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions;
 import com.oracle.appbundlers.utils.BundlerUtils;
+import com.oracle.appbundlers.utils.BundlingManager;
 import com.oracle.appbundlers.utils.ExtensionType;
+import com.oracle.appbundlers.utils.JavaApiBundlingManager;
+import com.oracle.appbundlers.utils.Utils;
 import com.oracle.tools.packager.RelativeFileSet;
 
 /**
@@ -30,34 +39,43 @@
  * Tests {@code installdirChooser} option.
  */
 public class InstallDirTest extends TestBase {
-    private Path licenseFileSrc;
     private String licenseFileContent;
-
-    public void initializeVars() throws IOException {
-        licenseFileSrc = CONFIG_INSTANCE.getResourceFilePath(LICENSE_FILE_NAME);
-    }
+    private Path licenseFileSrcInSuite;
+    private Path licenseFolder;
 
     @Override
     protected BundlerUtils[] getBundlerUtils() {
         return new BundlerUtils[] { EXE, MSI };
     }
 
-    public AdditionalParams getAdditionalParams(ExtensionType extension) {
+    protected AdditionalParams getAdditionalParams(ExtensionType extension)
+            throws IOException {
         return () -> {
             Map<String, Object> additionalParams = new HashMap<>();
-            RelativeFileSet existingRelativeFileSet = (RelativeFileSet) this.currentParameter
+            RelativeFileSet appResources = (RelativeFileSet) this.currentParameter
                     .getBasicParamsMap().get(APP_RESOURCES);
-            if (existingRelativeFileSet == null) {
-                RelativeFileSet newRelativeFileSet = this.currentParameter
-                        .getApp().getNewRelativeFileSetBasedOnExtension(extension);
-                newRelativeFileSet.getIncludedFiles().add(LICENSE_FILE_NAME);
-                additionalParams.put(APP_RESOURCES, newRelativeFileSet);
+            if (extension == ExtensionType.NormalJar) {
+                appResources.getIncludedFiles().add(LICENSE_FILE_NAME);
             } else {
-                existingRelativeFileSet.getIncludedFiles()
-                        .add(LICENSE_FILE_NAME);
+                List<RelativeFileSet> appResourcesList = new ArrayList<RelativeFileSet>();
+                appResourcesList.add(appResources);
+                List<Path> licenses = new ArrayList<>();
+                try (DirectoryStream<Path> licenseFileStream = Files
+                        .newDirectoryStream(Paths.get(licenseFolder.toString()),
+                                "*")) {
+                    licenseFileStream.forEach(licenses::add);
+                }
+
+                RelativeFileSet licenseAppResource = new RelativeFileSet(
+                        new File(licenseFolder.toString()), licenses.stream()
+                                .map(Path::toFile).collect(Collectors.toSet()));
+                appResourcesList.add(licenseAppResource);
+                additionalParams.put(APP_RESOURCES_LIST, appResourcesList);
+                additionalParams.put(DUMMY_RELATIVE_FILESET,
+                        licenseAppResource);
             }
-            additionalParams.put(INSTALLDIR_CHOOSER, "true");
             additionalParams.put(LICENSE_FILE, LICENSE_FILE_NAME);
+            additionalParams.put(INSTALLDIR_CHOOSER, true);
             return additionalParams;
         };
     }
@@ -72,7 +90,7 @@
 
     @Override
     protected void prepareTestEnvironment() throws Exception {
-        Path licenseFile = null;
+        Path licenseFileInTestAppFolder = null;
         for (ExtensionType extension : getExtensionArray()) {
             if (!isTestCaseApplicableForExtensionType(extension)) {
                 continue;
@@ -81,13 +99,20 @@
                     .get(extension);
             overrideParameters(extension);
             initializeAndPrepareApp();
-            licenseFile = this.currentParameter.getApp()
-                    .getJavaExtensionDirPathBasedonExtension(extension)
-                    .resolve(LICENSE_FILE_NAME);
-            initializeVars();
-            Files.copy(licenseFileSrc, licenseFile);
-            licenseFileContent = new String(Files.readAllBytes(licenseFile),
+            licenseFileSrcInSuite = CONFIG_INSTANCE.getResourceFilePath(LICENSE_FILE_NAME);
+            licenseFileContent = new String(Files.readAllBytes(licenseFileSrcInSuite),
                     "UTF-8");
+
+            if(extension == ExtensionType.NormalJar) {
+                licenseFolder = this.currentParameter.getApp().getJarDir();
+            } else {
+                licenseFolder = this.currentParameter.getApp().getWorkDir()
+                        .resolve("license");
+                Utils.createDir(licenseFolder);
+            }
+
+            licenseFileInTestAppFolder = licenseFolder.resolve(LICENSE_FILE_NAME);
+            Files.copy(licenseFileSrcInSuite, licenseFileInTestAppFolder);
         }
     }
 
@@ -97,4 +122,23 @@
                 .setAdditionalParams(getAdditionalParams(extension));
         this.currentParameter.setVerifiedOptions(getVerifiedOptions());
     }
+
+    @Override
+    protected void executeJavaPackager(BundlingManager bundlingManager,
+            Map<String, Object> allParams, ExtensionType extension) throws IOException {
+
+        if (bundlingManager instanceof JavaApiBundlingManager) {
+            if (allParams.containsKey(DUMMY_RELATIVE_FILESET)
+                    && (extension != ExtensionType.NormalJar)) {
+                RelativeFileSet dummyRelativeFileSet = (RelativeFileSet) allParams
+                        .get(DUMMY_RELATIVE_FILESET);
+                allParams.put("srcdir",
+                        dummyRelativeFileSet.getBaseDirectory().getPath());
+                allParams.put("srcfiles",
+                        dummyRelativeFileSet.getIncludedFiles());
+                allParams.remove(DUMMY_RELATIVE_FILESET);
+            }
+        }
+        bundlingManager.execute(allParams, this.currentParameter.getApp(), true);
+    }
 }
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/MainClassTest.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/MainClassTest.java	Wed Dec 07 11:54:42 2016 +0530
@@ -41,11 +41,6 @@
         return COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME;
     }
 
-    @Override
-    public String getResultingAppName() {
-        return mainClassName();
-    }
-
     public AdditionalParams getAdditionalParams() {
         return () -> {
             Map<String, Object> additionalParams = new HashMap<>();
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/jdk9test/CheckExecutablesAvailableTest.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/jdk9test/CheckExecutablesAvailableTest.java	Wed Dec 07 11:54:42 2016 +0530
@@ -9,6 +9,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import com.oracle.appbundlers.tests.functionality.TestBase;
 import com.oracle.appbundlers.tests.functionality.functionalinterface.AdditionalParams;
 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions;
 import com.oracle.appbundlers.utils.ExtensionType;
@@ -19,7 +20,7 @@
  *
  * @author Ramesh BG
  */
-public class CheckExecutablesAvailableTest extends ModuleTestBase {
+public class CheckExecutablesAvailableTest extends TestBase {
 
     public AdditionalParams getAdditionalParams() {
         return () -> {
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/jdk9test/UnnamedModuleDependsOn3rdPartyModulesBundledWithEntireJreTest.java	Fri Dec 02 18:28:41 2016 +0300
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/jdk9test/UnnamedModuleDependsOn3rdPartyModulesBundledWithEntireJreTest.java	Wed Dec 07 11:54:42 2016 +0530
@@ -95,7 +95,7 @@
         app.writeSourcesToAppDirectory();
         app.compileAndCreateJavaExtensionType(
                 new String[] { DOUBLE_HYPHEN + ADD_EXPORTS,
-                        "custom.util/testapp.util=ALL-UNNAMED" },
+                        "custom.util/testapp.util=ALL-UNNAMED", DOUBLE_HYPHEN + ADD_MODS, CUSTOM_UTIL_MODULE_NAME},
                 extension);
     }