changeset 17288:763bb540b895

8146721: FileCopierPlugin should not create fake module Reviewed-by: jlaskey, alanb
author sundar
date Thu, 04 Aug 2016 19:39:42 +0530
parents 80d1205d3299
children 52e1f122bf03
files src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java test/tools/jlink/plugins/FileCopierPluginTest.java
diffstat 4 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java	Thu Aug 04 19:39:42 2016 +0530
@@ -56,7 +56,6 @@
 import java.util.Properties;
 import java.util.Set;
 import jdk.tools.jlink.internal.BasicImageWriter;
-import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
 import jdk.tools.jlink.internal.plugins.FileCopierPlugin.SymImageFile;
 import jdk.tools.jlink.internal.ExecutableImage;
 import jdk.tools.jlink.plugin.ResourcePool;
@@ -184,10 +183,6 @@
             files.moduleView().modules().forEach(m -> {
                 // Only add modules that contain packages
                 if (!m.packages().isEmpty()) {
-                    // Skip the fake module used by FileCopierPlugin when copying files.
-                    if (m.name().equals(FileCopierPlugin.FAKE_MODULE)) {
-                        return;
-                    }
                     modules.add(m.name());
                 }
             });
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java	Thu Aug 04 19:39:42 2016 +0530
@@ -213,7 +213,6 @@
 
     private final Map<String, ResourcePoolEntry> resources = new LinkedHashMap<>();
     private final Map<String, ResourcePoolModule> modules = new LinkedHashMap<>();
-    private final ResourcePoolModuleImpl fileCopierModule = new ResourcePoolModuleImpl(FileCopierPlugin.FAKE_MODULE);
     private final ByteOrder order;
     private final StringTable table;
     private final ResourcePool poolImpl;
@@ -272,11 +271,6 @@
         }
         String modulename = data.moduleName();
         ResourcePoolModuleImpl m = (ResourcePoolModuleImpl)modules.get(modulename);
-        // ## TODO: FileCopierPlugin should not add content to a module
-        // FAKE_MODULE is not really a module to be added in the image
-        if (FileCopierPlugin.FAKE_MODULE.equals(modulename)) {
-            m = fileCopierModule;
-        }
         if (m == null) {
             m = new ResourcePoolModuleImpl(modulename);
             modules.put(modulename, m);
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java	Thu Aug 04 19:39:42 2016 +0530
@@ -58,8 +58,6 @@
         Path source;
         Path target;
     }
-    public static final String FAKE_MODULE = "$jlink-file-copier";
-
     private final List<CopiedFile> files = new ArrayList<>();
 
     /**
@@ -159,7 +157,7 @@
         Objects.requireNonNull(file);
         Objects.requireNonNull(path);
         ResourcePoolEntry impl = ResourcePoolEntry.create(
-                "/" + FAKE_MODULE + "/other/" + path,
+                "/java.base/other/" + path,
                 ResourcePoolEntry.Type.OTHER, file);
         try {
             pool.add(impl);
--- a/test/tools/jlink/plugins/FileCopierPluginTest.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/test/tools/jlink/plugins/FileCopierPluginTest.java	Thu Aug 04 19:39:42 2016 +0530
@@ -41,6 +41,7 @@
 import jdk.tools.jlink.builder.DefaultImageBuilder;
 
 import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
+import jdk.tools.jlink.plugin.PluginException;
 import jdk.tools.jlink.plugin.ResourcePoolEntry;
 import jdk.tools.jlink.plugin.ResourcePool;
 
@@ -103,7 +104,18 @@
         });
         Path root = new File(".").toPath();
         DefaultImageBuilder imgbuilder = new DefaultImageBuilder(root);
-        imgbuilder.storeFiles(pool);
+        try {
+            imgbuilder.storeFiles(pool);
+        } catch (PluginException e) {
+            // We didn't add any .class resource of the java.base module!
+            // This cannot happen in non-testing scenario as java.base module
+            // is minimum mandatory module in a .jimage. jlink depends on java.base
+            // to generate 'release' file. If the current exception came from that
+            // part of the code, then it is okay.
+            if (!e.getMessage().contains("No module-info for java.base module")) {
+                throw e;
+            }
+        }
 
         if (lic.exists()) {
             File license = new File(root.toFile(), "LICENSE");