8146721: FileCopierPlugin should not create fake module
authorsundar
Thu, 04 Aug 2016 19:39:42 +0530
changeset 40121 4204d69de3a9
parent 40120 ac96fa31cdf3
child 40122 4f81380d441a
8146721: FileCopierPlugin should not create fake module Reviewed-by: jlaskey, alanb
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java
jdk/test/tools/jlink/plugins/FileCopierPluginTest.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/jdk/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/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/jdk/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/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/jdk/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/jdk/test/tools/jlink/plugins/FileCopierPluginTest.java	Thu Aug 04 16:05:37 2016 +0300
+++ b/jdk/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");