8213962: JPackageCreateImageRuntimeModuleTest fails JDK-8200758-branch
authorherrick
Tue, 18 Dec 2018 15:10:45 -0500
branchJDK-8200758-branch
changeset 57077 8f9cf6ad59f0
parent 57076 687505381ca4
child 57078 db003bfc5bf7
8213962: JPackageCreateImageRuntimeModuleTest fails Reviewed-by: almatvee, kcr
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java
test/jdk/tools/jpackage/createimage/JPackageCreateImageBuildRootTest.java
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java	Tue Dec 18 15:10:45 2018 -0500
@@ -59,6 +59,7 @@
 
     private final Path root;
     private final Path appDir;
+    private final Path appModsDir;
     private final Path runtimeDir;
     private final Path resourcesDir;
     private final Path mdir;
@@ -91,6 +92,7 @@
 
         this.root = imageOutDir.resolve(APP_NAME.fetchFrom(config));
         this.appDir = root.resolve("app");
+        this.appModsDir = appDir.resolve("mods");
         this.runtimeDir = root.resolve("runtime");
         this.resourcesDir = root.resolve("resources");
         this.mdir = runtimeDir.resolve("lib");
@@ -110,6 +112,7 @@
 
         this.root = imageOutDir.resolve(appName);
         this.appDir = null;
+        this.appModsDir = null;
         this.runtimeDir = null;
         this.resourcesDir = null;
         this.mdir = null;
@@ -170,6 +173,16 @@
     }
 
     @Override
+    public Path getAppDir() {
+        return appDir;
+    }
+
+    @Override
+    public Path getAppModsDir() {
+        return appModsDir;
+    }
+
+    @Override
     public InputStream getResourceAsStream(String name) {
         return LinuxResources.class.getResourceAsStream(name);
     }
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Tue Dec 18 15:10:45 2018 -0500
@@ -77,6 +77,7 @@
     private final Path root;
     private final Path contentsDir;
     private final Path javaDir;
+    private final Path javaModsDir;
     private final Path resourcesDir;
     private final Path macOSDir;
     private final Path runtimeDir;
@@ -204,6 +205,7 @@
         this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params) + ".app");
         this.contentsDir = root.resolve("Contents");
         this.javaDir = contentsDir.resolve("Java");
+        this.javaModsDir = javaDir.resolve("mods");
         this.resourcesDir = contentsDir.resolve("Resources");
         this.macOSDir = contentsDir.resolve("MacOS");
         this.runtimeDir = contentsDir.resolve("PlugIns/Java.runtime");
@@ -225,6 +227,7 @@
         this.root = imageOutDir.resolve(jreName );
         this.contentsDir = root.resolve("Contents");
         this.javaDir = null;
+        this.javaModsDir = null;
         this.resourcesDir = null;
         this.macOSDir = null;
         this.runtimeDir = this.root;
@@ -315,6 +318,16 @@
     }
 
     @Override
+    public Path getAppDir() {
+        return javaDir;
+    }
+
+    @Override
+    public Path getAppModsDir() {
+        return javaModsDir;
+    }
+
+    @Override
     public InputStream getResourceAsStream(String name) {
         return MacResources.class.getResourceAsStream(name);
     }
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java	Tue Dec 18 15:10:45 2018 -0500
@@ -65,6 +65,8 @@
     public abstract InputStream getResourceAsStream(String name);
     public abstract void prepareApplicationFiles() throws IOException;
     public abstract void prepareJreFiles() throws IOException;
+    public abstract Path getAppDir();
+    public abstract Path getAppModsDir();
 
     public Map<String, Object> getProperties() {
         return this.properties;
@@ -242,6 +244,11 @@
         for (String arg : jvmargs) {
             out.println(arg);
         }
+        Path modsDir = getAppModsDir();
+        if (modsDir != null && modsDir.toFile().exists()) {
+            out.println("--module-path");
+            out.println(getAppDir().relativize(modsDir));
+        }
         Map<String, String> jvmProps = JVM_PROPERTIES.fetchFrom(params);
         for (Map.Entry<String, String> property : jvmProps.entrySet()) {
             out.println("-D" + property.getKey() + "=" + property.getValue());
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java	Tue Dec 18 15:10:45 2018 -0500
@@ -96,6 +96,31 @@
         });
     }
 
+    public static void copyRecursive(Path src, Path dest,
+            final List<String> excludes) throws IOException {
+        Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
+            @Override
+            public FileVisitResult preVisitDirectory(final Path dir,
+                    final BasicFileAttributes attrs) throws IOException {
+                if (excludes.contains(dir.toFile().getName())) {
+                    return FileVisitResult.SKIP_SUBTREE;
+                } else {
+                    Files.createDirectories(dest.resolve(src.relativize(dir)));
+                    return FileVisitResult.CONTINUE;
+                }
+            }
+
+            @Override
+            public FileVisitResult visitFile(final Path file,
+                    final BasicFileAttributes attrs) throws IOException {
+                if (!excludes.contains(file.toFile().getName())) {
+                    Files.copy(file, dest.resolve(src.relativize(file)));
+                }
+                return FileVisitResult.CONTINUE;
+            }
+        });
+    }
+
     public static void copyFromURL(URL location, File file) throws IOException {
         copyFromURL(location, file, false);
     }
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java	Tue Dec 18 15:10:45 2018 -0500
@@ -131,17 +131,6 @@
                     }
             );
 
-    @SuppressWarnings("unchecked")
-    static final StandardBundlerParam<List<File>> SOURCE_FILES =
-            new StandardBundlerParam<>(
-                    I18N.getString("param.source-files.name"),
-                    I18N.getString("param.source-files.description"),
-                    Arguments.CLIOptions.FILES.getId(),
-                    (Class<List<File>>) (Object) List.class,
-                    p -> null,
-                    (s, p) -> null
-            );
-
     // note that each bundler is likely to replace this one with
     // their own converter
     static final StandardBundlerParam<RelativeFileSet> MAIN_JAR =
@@ -664,7 +653,25 @@
                     "message.runtime-image-dir-does-not-exist.advice"),
                     PREDEFINED_RUNTIME_IMAGE.getID()));
         }
-        IOUtils.copyRecursive(image.toPath(), appBuilder.getRoot());
+        // copy whole runtime, need to skip jmods and src.zip
+        final List<String> excludes = Arrays.asList("jmods", "src.zip");
+        IOUtils.copyRecursive(image.toPath(), appBuilder.getRoot(), excludes);
+
+        // if module-path given - copy modules to appDir/mods
+        List<Path> modulePath =
+                StandardBundlerParam.MODULE_PATH.fetchFrom(p);
+        List<Path> defaultModulePath = getDefaultModulePath();
+        Path dest = appBuilder.getAppModsDir();
+        
+        if (dest != null) {
+            for (Path mp : modulePath) {
+                if (!defaultModulePath.contains(mp)) {
+                    Files.createDirectories(dest);
+                    IOUtils.copyRecursive(mp, dest);
+                }
+            }
+        }
+
         appBuilder.prepareApplicationFiles();
     }
 
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties	Tue Dec 18 15:10:45 2018 -0500
@@ -65,8 +65,6 @@
 param.jvm-system-properties.description=JVM System Properties (of the -Dname\=value variety).
 param.license-file.name=License
 param.license-file.description=The license file, relative to the assembled application directory.
-param.source-files.name=Files
-param.source-files.description=Set of files from input directory to be bundled.
 param.main-class.name=Main Class
 param.main-class.description=The main class for the application.  Either a javafx.application.Application instance or a java class with a main method.
 param.main-module.name=Main Module
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties	Tue Dec 18 15:10:45 2018 -0500
@@ -65,8 +65,6 @@
 param.jvm-system-properties.description=JVM System Properties (of the -Dname\=value variety).
 param.license-file.name=License
 param.license-file.description=The license file, relative to the assembled application directory.
-param.source-files.name=Files
-param.source-files.description=Set of files from input directory to be bundled.
 param.main-class.name=Main Class
 param.main-class.description=The main class for the application.  Either a javafx.application.Application instance or a java class with a main method.
 param.main-module.name=Main Module
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties	Tue Dec 18 15:10:45 2018 -0500
@@ -65,8 +65,6 @@
 param.jvm-system-properties.description=JVM System Properties (of the -Dname\=value variety).
 param.license-file.name=License
 param.license-file.description=The license file, relative to the assembled application directory.
-param.source-files.name=Files
-param.source-files.description=Set of files from input directory to be bundled.
 param.main-class.name=Main Class
 param.main-class.description=The main class for the application.  Either a javafx.application.Application instance or a java class with a main method.
 param.main-module.name=Main Module
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java	Tue Dec 18 15:08:56 2018 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java	Tue Dec 18 15:10:45 2018 -0500
@@ -72,6 +72,7 @@
 
     private final Path root;
     private final Path appDir;
+    private final Path appModsDir;
     private final Path runtimeDir;
     private final Path mdir;
 
@@ -140,6 +141,7 @@
 
         this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params));
         this.appDir = root.resolve("app");
+        this.appModsDir = appDir.resolve("mods");
         this.runtimeDir = root.resolve("runtime");
         this.mdir = runtimeDir.resolve("lib");
         Files.createDirectories(appDir);
@@ -155,6 +157,7 @@
         this.params = null;
         this.root = imageOutDir.resolve(jreName);
         this.appDir = null;
+        this.appModsDir = null;
         this.runtimeDir = root;
         this.mdir = runtimeDir.resolve("lib");
         Files.createDirectories(runtimeDir);
@@ -241,6 +244,16 @@
     }
 
     @Override
+    public Path getAppDir() {
+        return appDir;
+    }
+
+    @Override
+    public Path getAppModsDir() {
+        return appModsDir;
+    }
+
+    @Override
     public InputStream getResourceAsStream(String name) {
         return WinResources.class.getResourceAsStream(name);
     }
--- a/test/jdk/tools/jpackage/createimage/JPackageCreateImageBuildRootTest.java	Tue Dec 18 15:08:56 2018 -0500
+++ b/test/jdk/tools/jpackage/createimage/JPackageCreateImageBuildRootTest.java	Tue Dec 18 15:10:45 2018 -0500
@@ -25,6 +25,7 @@
 
  /*
  * @test
+ * @requires (os.family == "windows")
  * @summary jpackage create image to test --build-root
  * @library ../helpers
  * @build JPackageHelper