8155955: packager needs to determine the root modules to create JRE image

Reviewed-by: alanb
This commit is contained in:
Mandy Chung 2016-06-19 16:46:49 -07:00
parent 491d8743c3
commit d3e5142694
2 changed files with 28 additions and 44 deletions

View File

@ -39,15 +39,7 @@ import java.nio.ByteOrder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.Formatter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import jdk.internal.module.ConfigurableModuleFinder;
@ -96,11 +88,9 @@ public class JlinkTask {
}, "--help"),
new Option<JlinkTask>(true, (task, opt, arg) -> {
String[] dirs = arg.split(File.pathSeparator);
task.options.modulePath = new Path[dirs.length];
int i = 0;
for (String dir : dirs) {
task.options.modulePath[i++] = Paths.get(dir);
}
Arrays.stream(dirs)
.map(Paths::get)
.forEach(task.options.modulePath::add);
}, "--modulepath", "--mp"),
new Option<JlinkTask>(true, (task, opt, arg) -> {
for (String mn : arg.split(",")) {
@ -176,7 +166,7 @@ public class JlinkTask {
String saveoptsfile;
boolean version;
boolean fullVersion;
Path[] modulePath;
List<Path> modulePath = new ArrayList<>();
Set<String> limitMods = new HashSet<>();
Set<String> addMods = new HashSet<>();
Path output;
@ -203,7 +193,7 @@ public class JlinkTask {
return EXIT_OK;
}
if (taskHelper.getExistingImage() == null) {
if (options.modulePath == null || options.modulePath.length == 0) {
if (options.modulePath == null || options.modulePath.isEmpty()) {
throw taskHelper.newBadArgs("err.modulepath.must.be.specified").showUsage(true);
}
createImage();
@ -245,7 +235,7 @@ public class JlinkTask {
* Jlink API entry point.
*/
public static void createImage(JlinkConfiguration config,
PluginsConfiguration plugins)
PluginsConfiguration plugins)
throws Exception {
Objects.requireNonNull(config);
Objects.requireNonNull(config.getOutput());
@ -254,10 +244,9 @@ public class JlinkTask {
if (config.getModulepaths().isEmpty()) {
throw new Exception("Empty module paths");
}
Path[] arr = new Path[config.getModulepaths().size()];
arr = config.getModulepaths().toArray(arr);
ModuleFinder finder
= newModuleFinder(arr, config.getLimitmods(), config.getModules());
= newModuleFinder(config.getModulepaths(), config.getLimitmods(), config.getModules());
// First create the image provider
ImageProvider imageProvider
@ -332,10 +321,12 @@ public class JlinkTask {
return addMods;
}
private static ModuleFinder newModuleFinder(Path[] paths,
Set<String> limitMods,
Set<String> addMods) {
ModuleFinder finder = ModuleFinder.of(paths);
public static ModuleFinder newModuleFinder(List<Path> paths,
Set<String> limitMods,
Set<String> addMods)
{
ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[0]));
// jmods are located at link-time
if (finder instanceof ConfigurableModuleFinder) {

View File

@ -27,36 +27,19 @@ package jdk.tools.jlink.internal.packager;
import jdk.tools.jlink.Jlink;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.builder.DefaultImageBuilder;
import jdk.tools.jlink.internal.JlinkTask;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.builder.*;
import jdk.tools.jlink.plugin.ModulePool;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.lang.module.ModuleFinder;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Collectors;
/**
* AppRuntimeImageBuilder is a private API used only by the Java Packager to generate
@ -143,4 +126,14 @@ public final class AppRuntimeImageBuilder {
Jlink jlink = new Jlink();
jlink.build(jlinkConfig, pluginConfig);
}
/**
* Returns a ModuleFinder that limits observability to the given root
* modules, their transitive dependences, plus a set of other modules.
*/
public static ModuleFinder moduleFinder(List<Path> modulepaths,
Set<String> roots,
Set<String> otherModules) {
return JlinkTask.newModuleFinder(modulepaths, roots, otherModules);
}
}