--- old/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java 2017-03-23 14:42:17.000000000 -0700 +++ new/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java 2017-03-23 14:42:16.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, 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 @@ -24,6 +24,8 @@ */ package jdk.tools.jlink.internal; +import java.lang.module.Configuration; +import java.lang.module.ModuleFinder; import java.lang.reflect.Layer; import java.nio.ByteOrder; import java.nio.file.Path; @@ -33,6 +35,8 @@ import java.util.Map; import java.util.Objects; import java.util.Set; + +import jdk.internal.module.ModulePath; import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.builder.ImageBuilder; @@ -147,8 +151,8 @@ private final Path output; private final Set modules; private final Set limitmods; - private final ByteOrder endian; + private final ModuleFinder finder; /** * jlink configuration, @@ -160,31 +164,23 @@ * @param endian Jimage byte order. Native order by default */ public JlinkConfiguration(Path output, - List modulepaths, - Set modules, - Set limitmods, - ByteOrder endian) { - this.output = output; - this.modulepaths = modulepaths == null ? Collections.emptyList() : modulepaths; - this.modules = modules == null ? Collections.emptySet() : modules; - this.limitmods = limitmods == null ? Collections.emptySet() : limitmods; - this.endian = endian == null ? ByteOrder.nativeOrder() : endian; - } + List modulepaths, + Set modules, + Set limitmods, + ByteOrder endian) { + if (Objects.requireNonNull(modulepaths).isEmpty()) { + throw new IllegalArgumentException("Empty module path"); + } + if (Objects.requireNonNull(modules).isEmpty()) { + throw new IllegalArgumentException("Empty modules"); + } - /** - * jlink configuration, - * - * @param output Output directory, must not exist. - * @param modulepaths Modules paths - * @param modules Root modules to resolve - * @param limitmods Limit the universe of observable modules - */ - public JlinkConfiguration(Path output, - List modulepaths, - Set modules, - Set limitmods) { - this(output, modulepaths, modules, limitmods, - ByteOrder.nativeOrder()); + this.output = output; + this.modulepaths = modulepaths; + this.modules = modules; + this.limitmods = Objects.requireNonNull(limitmods); + this.endian = Objects.requireNonNull(endian); + this.finder = moduleFinder(); } /** @@ -222,6 +218,45 @@ return limitmods; } + /** + * Returns {@link ModuleFinder} that finds all observable modules + * for this jlink configuration. + */ + public ModuleFinder finder() { + return finder; + } + + /** + * Returns a {@link Configuration} of the given module path, + * root modules with full service binding. + */ + public Configuration resolveAndBind() + { + return Configuration.empty().resolveAndBind(finder, + ModuleFinder.of(), + modules); + } + + /** + * Returns a {@link Configuration} of the given module path, + * root modules with no service binding. + */ + public Configuration resolve() + { + return Configuration.empty().resolve(finder, + ModuleFinder.of(), + modules); + } + + private ModuleFinder moduleFinder() { + Path[] entries = modulepaths.toArray(new Path[0]); + ModuleFinder finder = ModulePath.of(Runtime.version(), true, entries); + if (!limitmods.isEmpty()) { + finder = JlinkTask.limitFinder(finder, limitmods, modules); + } + return finder; + } + @Override public String toString() { StringBuilder builder = new StringBuilder();