8146721: FileCopierPlugin should not create fake module

Reviewed-by: jlaskey, alanb
This commit is contained in:
Athijegannathan Sundararajan 2016-08-04 19:39:42 +05:30
parent 4809e92cec
commit 70ad571a32
4 changed files with 14 additions and 15 deletions

View File

@ -56,7 +56,6 @@ import java.util.Optional;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import jdk.tools.jlink.internal.BasicImageWriter; 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.plugins.FileCopierPlugin.SymImageFile;
import jdk.tools.jlink.internal.ExecutableImage; import jdk.tools.jlink.internal.ExecutableImage;
import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePool;
@ -184,10 +183,6 @@ public final class DefaultImageBuilder implements ImageBuilder {
files.moduleView().modules().forEach(m -> { files.moduleView().modules().forEach(m -> {
// Only add modules that contain packages // Only add modules that contain packages
if (!m.packages().isEmpty()) { 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()); modules.add(m.name());
} }
}); });

View File

@ -213,7 +213,6 @@ public class ResourcePoolManager {
private final Map<String, ResourcePoolEntry> resources = new LinkedHashMap<>(); private final Map<String, ResourcePoolEntry> resources = new LinkedHashMap<>();
private final Map<String, ResourcePoolModule> modules = 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 ByteOrder order;
private final StringTable table; private final StringTable table;
private final ResourcePool poolImpl; private final ResourcePool poolImpl;
@ -272,11 +271,6 @@ public class ResourcePoolManager {
} }
String modulename = data.moduleName(); String modulename = data.moduleName();
ResourcePoolModuleImpl m = (ResourcePoolModuleImpl)modules.get(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) { if (m == null) {
m = new ResourcePoolModuleImpl(modulename); m = new ResourcePoolModuleImpl(modulename);
modules.put(modulename, m); modules.put(modulename, m);

View File

@ -58,8 +58,6 @@ public class FileCopierPlugin implements Plugin {
Path source; Path source;
Path target; Path target;
} }
public static final String FAKE_MODULE = "$jlink-file-copier";
private final List<CopiedFile> files = new ArrayList<>(); private final List<CopiedFile> files = new ArrayList<>();
/** /**
@ -159,7 +157,7 @@ public class FileCopierPlugin implements Plugin {
Objects.requireNonNull(file); Objects.requireNonNull(file);
Objects.requireNonNull(path); Objects.requireNonNull(path);
ResourcePoolEntry impl = ResourcePoolEntry.create( ResourcePoolEntry impl = ResourcePoolEntry.create(
"/" + FAKE_MODULE + "/other/" + path, "/java.base/other/" + path,
ResourcePoolEntry.Type.OTHER, file); ResourcePoolEntry.Type.OTHER, file);
try { try {
pool.add(impl); pool.add(impl);

View File

@ -41,6 +41,7 @@ import jdk.tools.jlink.internal.ResourcePoolManager;
import jdk.tools.jlink.builder.DefaultImageBuilder; import jdk.tools.jlink.builder.DefaultImageBuilder;
import jdk.tools.jlink.internal.plugins.FileCopierPlugin; import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePoolEntry; import jdk.tools.jlink.plugin.ResourcePoolEntry;
import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePool;
@ -103,7 +104,18 @@ public class FileCopierPluginTest {
}); });
Path root = new File(".").toPath(); Path root = new File(".").toPath();
DefaultImageBuilder imgbuilder = new DefaultImageBuilder(root); DefaultImageBuilder imgbuilder = new DefaultImageBuilder(root);
try {
imgbuilder.storeFiles(pool); 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()) { if (lic.exists()) {
File license = new File(root.toFile(), "LICENSE"); File license = new File(root.toFile(), "LICENSE");