8212164: resolve jre.list and jre.module.list JDK-8200758-branch
authorherrick
Tue, 11 Dec 2018 12:54:18 -0500
branchJDK-8200758-branch
changeset 57070 42783e8e73de
parent 57069 b8385a806d2b
child 57071 94e9270166f0
8212164: resolve jre.list and jre.module.list Reviewed-by: almatvee, kcr
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppBundler.java
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.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/JLinkBundlerHelper.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/RedistributableModules.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/jre.list
src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/jre.module.list
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinAppBundler.java
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/windows.jre.list
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppBundler.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppBundler.java	Tue Dec 11 12:54:18 2018 -0500
@@ -151,7 +151,7 @@
                     APP_NAME.fetchFrom(p), outputDirectory.toPath());
             File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
             if (predefined == null ) {
-                JLinkBundlerHelper.generateServerJre(p, appBuilder);
+                JLinkBundlerHelper.generateJre(p, appBuilder);
             } else {
                 return predefined;
             }
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java	Tue Dec 11 12:54:18 2018 -0500
@@ -206,7 +206,7 @@
     }
 
     @Override
-    public void prepareServerJreFiles() throws IOException {}
+    public void prepareJreFiles() throws IOException {}
 
     private void createLauncherForEntryPoint(Map<String, ? super Object> p,
             Path rootDir) throws IOException {
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java	Tue Dec 11 12:54:18 2018 -0500
@@ -352,7 +352,7 @@
                     APP_NAME.fetchFrom(p), outputDirectory.toPath());
             File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
             if (predefined == null ) {
-                JLinkBundlerHelper.generateServerJre(p, appBuilder);
+                JLinkBundlerHelper.generateJre(p, appBuilder);
             } else {
                 return predefined;
             }
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Tue Dec 11 12:54:18 2018 -0500
@@ -393,7 +393,7 @@
     }
 
     @Override
-    public void prepareServerJreFiles() throws IOException {
+    public void prepareJreFiles() throws IOException {
         copyRuntimeFiles();
         sign();
     }
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java	Tue Dec 11 12:54:18 2018 -0500
@@ -64,7 +64,7 @@
 
     public abstract InputStream getResourceAsStream(String name);
     public abstract void prepareApplicationFiles() throws IOException;
-    public abstract void prepareServerJreFiles() throws IOException;
+    public abstract void prepareJreFiles() throws IOException;
 
     public Map<String, Object> getProperties() {
         return this.properties;
@@ -264,8 +264,4 @@
         out.close();
     }
 
-    public String getPlatformSpecificModulesFile() {
-        return null;
-    }
-
 }
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java	Tue Dec 11 12:54:18 2018 -0500
@@ -44,6 +44,10 @@
 import java.util.Properties;
 import java.util.ResourceBundle;
 import java.util.Set;
+import java.util.Optional;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReference;
 
 import jdk.tools.jlink.internal.packager.AppRuntimeImageBuilder;
 
@@ -177,14 +181,14 @@
         Set<String> limitModules =
                 StandardBundlerParam.LIMIT_MODULES.fetchFrom(params);
         Path javaBasePath = findPathOfModule(modulePath, "java.base.jmod");
-        Set<String> addModules = getRedistributableModules(modulePath,
+        Set<String> addModules = getValidModules(modulePath,
                 StandardBundlerParam.ADD_MODULES.fetchFrom(params),
-                limitModules, JRE_MODULES_FILENAME);
+                limitModules, true);
 
 
         if (javaBasePath != null && javaBasePath.toFile().exists()) {
-            result = RedistributableModules.getModuleVersion(
-                   javaBasePath.toFile(), modulePath, addModules, limitModules);
+            result = getModuleVersion(javaBasePath.toFile(),
+                    modulePath, addModules, limitModules);
         }
 
         return result;
@@ -226,10 +230,11 @@
         return result;
     }
 
-    private static Set<String> getRedistributableModules(List<Path> modulePath,
-            Set<String> addModules, Set<String> limitModules, String filename) {
+    private static Set<String> getValidModules(List<Path> modulePath,
+            Set<String> addModules, Set<String> limitModules,
+            boolean forJRE) {
         ModuleHelper moduleHelper = new ModuleHelper(
-                modulePath, addModules, limitModules, filename);
+                modulePath, addModules, limitModules, forJRE);
         return removeInvalidModules(modulePath, moduleHelper.modules());
     }
 
@@ -259,7 +264,7 @@
         // Modules
 
         // The default for an unnamed jar is ALL_DEFAULT with the
-        // non-redistributable modules removed.
+        // non-valid modules removed.
         if (mainJarType == ModFile.ModType.UnnamedJar) {
             addModules.add(ModuleHelper.ALL_RUNTIME);
         } else if (mainJarType == ModFile.ModType.Unknown ||
@@ -277,16 +282,8 @@
                         modularJars.toString()));
             }
         }
-        Set<String> redistModules = getRedistributableModules(
-                modulePath, addModules, limitModules, JRE_MODULES_FILENAME);
-        addModules.addAll(redistModules);
-
-        if (imageBuilder.getPlatformSpecificModulesFile() != null) {
-            Set<String> platformModules =
-                    RedistributableModules.getRedistributableModules(
-                modulePath, imageBuilder.getPlatformSpecificModulesFile());
-            addModules.addAll(platformModules);
-        }
+        addModules.addAll(getValidModules(
+                modulePath, addModules, limitModules, false));
 
         Log.verbose(MessageFormat.format(
                 I18N.getString("message.modules"), addModules.toString()));
@@ -304,7 +301,7 @@
         imageBuilder.prepareApplicationFiles();
     }
 
-    static void generateServerJre(Map<String, ? super Object> params,
+    static void generateJre(Map<String, ? super Object> params,
             AbstractAppImageBuilder imageBuilder)
             throws IOException, Exception {
         List<Path> modulePath =
@@ -317,16 +314,10 @@
                 StandardBundlerParam.STRIP_NATIVE_COMMANDS.fetchFrom(params);
         Path outputDir = imageBuilder.getRoot();
         addModules.add(ModuleHelper.ALL_RUNTIME);
-        Set<String> redistModules = getRedistributableModules(modulePath,
-                addModules, limitModules, SERVER_JRE_MODULES_FILENAME);
+        Set<String> redistModules = getValidModules(modulePath,
+                addModules, limitModules, true);
         addModules.addAll(redistModules);
 
-        if (imageBuilder.getPlatformSpecificModulesFile() != null) {
-            Set<String> platformModules =
-                    RedistributableModules.getRedistributableModules(
-                    modulePath, imageBuilder.getPlatformSpecificModulesFile());
-            addModules.addAll(platformModules);
-        }
         Log.verbose(MessageFormat.format(
                 I18N.getString("message.modules"), addModules.toString()));
 
@@ -340,7 +331,7 @@
         appRuntimeBuilder.setUserArguments(new HashMap<String,String>());
 
         appRuntimeBuilder.build();
-        imageBuilder.prepareServerJreFiles();
+        imageBuilder.prepareJreFiles();
     }
 
     // Returns the path to the JDK modules in the user defined module path.
@@ -426,18 +417,44 @@
         return result;
     }
 
+    private static String getModuleVersion(File moduleFile,
+            List<Path> modulePath, Set<String> addModules,
+            Set<String> limitModules) {
+        String result = "";
+
+        ModFile modFile = new ModFile(moduleFile);
+        ModuleFinder finder = AppRuntimeImageBuilder.moduleFinder(modulePath,
+                addModules, limitModules);
+        Optional<ModuleReference> mref = finder.find(modFile.getModName());
+
+        if (mref.isPresent()) {
+            ModuleDescriptor descriptor = mref.get().descriptor();
+
+            if (descriptor != null) {
+                Optional<ModuleDescriptor.Version> version =
+                        descriptor.version();
+
+                if (version.isPresent()) {
+                    result = version.get().toString();
+                }
+            }
+        }
+
+        return result;
+    }
+
     private static class ModuleHelper {
         // The token for "all modules on the module path".
         private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
 
-        // The token for "all redistributable runtime modules".
+        // The token for "all valid runtime modules".
         static final String ALL_RUNTIME = "ALL-RUNTIME";
 
         private final Set<String> modules = new HashSet<>();
         private enum Macros {None, AllModulePath, AllRuntime}
 
         ModuleHelper(List<Path> paths, Set<String> roots,
-                Set<String> limitMods, String filename) {
+                Set<String> limitMods, boolean forJRE) {
             Macros macro = Macros.None;
 
             for (Iterator<String> iterator = roots.iterator();
@@ -463,14 +480,15 @@
                     this.modules.addAll(getModuleNamesFromPath(paths));
                     break;
                 case AllRuntime:
-                    Set<String> m =
-                            RedistributableModules.getRedistributableModules(
-                            paths, filename);
-
-                    if (m != null) {
-                        this.modules.addAll(m);
+                    Set<Module> runtimeModules =
+                            ModuleLayer.boot().modules();
+                    for (Module m : runtimeModules) {
+                        String name = m.getName();
+                        if (forJRE && isModuleExcludedFromJRE(name)) {
+                            continue;  // JRE does not include this module
+                        }
+                        this.modules.add(name);
                     }
-
                     break;
             }
         }
@@ -479,6 +497,10 @@
             return modules;
         }
 
+        private boolean isModuleExcludedFromJRE(String name) {
+            return false;  // not excluding any modules from JRE at this time
+        }
+
         private static Set<String> getModuleNamesFromPath(List<Path> Value) {
                 Set<String> result = new LinkedHashSet<String>();
                 ModuleManager mm = new ModuleManager(Value);
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/RedistributableModules.java	Mon Dec 10 16:55:17 2018 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.util.Optional;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleReference;
-import java.lang.module.ModuleReader;
-import java.nio.file.Path;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import jdk.tools.jlink.internal.packager.AppRuntimeImageBuilder;
-
-final class RedistributableModules {
-    private static final String JDK_JPACKAGE_MODULE = "jdk.jpackage";
-
-    private RedistributableModules() {}
-
-    static String stripComments(String line) {
-        String result = line.trim();
-        int i = result.indexOf(";");
-
-        if (i >= 0) {
-          result = result.substring(0, i);
-          result = result.trim();
-        }
-
-        return result;
-    }
-
-    static Set<String> getRedistributableModules(List<Path> modulePath,
-            String filename) {
-        Set<String> result = null;
-
-        Set<String> addModules = new HashSet<>();
-        Set<String> limitModules = new HashSet<>();
-        ModuleFinder finder = AppRuntimeImageBuilder.moduleFinder(
-                modulePath, addModules, limitModules);
-        Optional<ModuleReference> mref = finder.find(JDK_JPACKAGE_MODULE);
-
-        if (mref.isPresent()) {
-            ModuleReader reader = null;
-
-            try {
-                reader = mref.get().open();
-            } catch (NoSuchElementException | IOException ex) {
-            }
-
-            if (reader != null) {
-                Optional<InputStream> stream = null;
-
-                try {
-                    stream = reader.open(filename);
-                } catch (IOException ex) {
-                }
-
-                if (stream != null) {
-                    if (stream.isPresent()) {
-                        BufferedReader br = null;
-
-                        try {
-                            br = new BufferedReader(new InputStreamReader(
-                                    stream.get(), "UTF-8"));
-                        } catch (UnsupportedEncodingException ex) {
-                        }
-
-                        if (br != null) {
-                            result = new LinkedHashSet<String>();
-                            String line;
-
-                            try {
-                                while ((line = br.readLine()) != null) {
-                                    String module = stripComments(line);
-
-                                    if (!module.isEmpty()) {
-                                        result.add(module);
-                                    }
-                                }
-                            } catch (IOException ex) {
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        return result;
-    }
-
-    static String getModuleVersion(File moduleFile,
-            List<Path> modulePath, Set<String> addModules,
-            Set<String> limitModules) {
-        String result = "";
-
-        ModFile modFile = new ModFile(moduleFile);
-        ModuleFinder finder = AppRuntimeImageBuilder.moduleFinder(modulePath,
-                addModules, limitModules);
-        Optional<ModuleReference> mref = finder.find(modFile.getModName());
-
-        if (mref.isPresent()) {
-            ModuleDescriptor descriptor = mref.get().descriptor();
-
-            if (descriptor != null) {
-                Optional<ModuleDescriptor.Version> version =
-                        descriptor.version();
-
-                if (version.isPresent()) {
-                    result = version.get().toString();
-                }
-            }
-        }
-
-        return result;
-    }
-}
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/jre.list	Mon Dec 10 16:55:17 2018 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-; This file contains a list of all modules in a modular JDK that match a JRE.
-
-java.base
-java.compiler
-java.datatransfer
-java.xml
-java.prefs
-java.desktop
-java.instrument
-java.logging
-java.management
-java.security.sasl
-java.naming
-java.rmi
-java.management.rmi
-java.net.http
-java.scripting
-java.security.jgss
-java.transaction.xa
-java.sql
-java.sql.rowset
-java.xml.crypto
-java.smartcardio
-jdk.accessibility
-jdk.charsets
-jdk.crypto.ec
-jdk.crypto.cryptoki
-jdk.dynalink
-jdk.httpserver
-jdk.management
-jdk.unsupported
-jdk.jdeps
-jdk.jdwp.agent
-jdk.jlink
-jdk.jsobject
-jdk.localedata
-jdk.management.agent
-jdk.naming.dns
-jdk.naming.rmi
-jdk.net
-jdk.jpackage
-jdk.jpackage.runtime
-jdk.scripting.nashorn
-jdk.scripting.nashorn.shell
-jdk.sctp
-jdk.security.auth
-jdk.security.jgss
-jdk.xml.dom
-jdk.zipfs
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/jre.module.list	Mon Dec 10 16:55:17 2018 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-; This file contains a list of all modules in a modular JDK that match a JRE.
-
-java.base
-java.compiler
-java.datatransfer
-java.xml
-java.prefs
-java.desktop
-java.instrument
-java.logging
-java.management
-java.security.sasl
-java.naming
-java.rmi
-java.management.rmi
-java.net.http
-java.scripting
-java.security.jgss
-java.transaction.xa
-java.sql
-java.sql.rowset
-java.xml.crypto
-java.se
-java.smartcardio
-jdk.internal.jvmstat
-jdk.attach
-jdk.charsets
-jdk.compiler
-jdk.crypto.ec
-jdk.crypto.cryptoki
-jdk.dynalink
-jdk.httpserver
-jdk.internal.le
-jdk.internal.opt
-jdk.internal.vm.ci
-jdk.management
-jdk.unsupported
-jdk.internal.vm.compiler
-jdk.internal.vm.compiler.management
-jdk.jartool
-jdk.jcmd
-jdk.jdwp.agent
-jdk.jdi
-jdk.jsobject
-jdk.jstatd
-jdk.localedata
-jdk.management.agent
-jdk.naming.dns
-jdk.naming.rmi
-jdk.net
-jdk.scripting.nashorn
-jdk.sctp
-jdk.security.auth
-jdk.security.jgss
-jdk.xml.dom
-jdk.zipfs
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinAppBundler.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinAppBundler.java	Tue Dec 11 12:54:18 2018 -0500
@@ -201,7 +201,7 @@
                     outputDirectory.toPath());
             File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
             if (predefined == null ) {
-                JLinkBundlerHelper.generateServerJre(p, appBuilder);
+                JLinkBundlerHelper.generateJre(p, appBuilder);
             } else {
                 return predefined;
             }
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java	Mon Dec 10 16:55:17 2018 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java	Tue Dec 11 12:54:18 2018 -0500
@@ -60,9 +60,6 @@
     private static final ResourceBundle I18N = ResourceBundle.getBundle(
             "jdk.jpackage.internal.resources.WinResources");
 
-    private static final String MODULES_FILENAME =
-            "jdk/jpackage/internal/resources/windows.jre.list";
-
     private final static String EXECUTABLE_NAME = "WinLauncher.exe";
     private final static String LIBRARY_NAME = "applauncher.dll";
     private final static String REDIST_MSVCR = "vcruntimeVS_VER.dll";
@@ -289,7 +286,7 @@
     }
 
     @Override
-    public void prepareServerJreFiles() throws IOException {}
+    public void prepareJreFiles() throws IOException {}
 
     private void copyMSVCDLLs() throws IOException {
         AtomicReference<IOException> ioe = new AtomicReference<>();
@@ -472,9 +469,4 @@
         }
     }
 
-    @Override
-    public String getPlatformSpecificModulesFile() {
-        return MODULES_FILENAME;
-    }
-
 }
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/windows.jre.list	Mon Dec 10 16:55:17 2018 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-; This file contains Windows-specific modules.
-
-jdk.crypto.mscapi