< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.tools.jlink.internal;
  26 
  27 import java.lang.module.Configuration;
  28 import java.lang.module.ModuleFinder;
  29 import java.nio.ByteOrder;

  30 import java.nio.file.Path;

  31 import java.util.ArrayList;
  32 import java.util.Collections;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Objects;
  36 import java.util.Set;
  37 
  38 import jdk.internal.module.ModulePath;
  39 import jdk.tools.jlink.plugin.Plugin;
  40 import jdk.tools.jlink.plugin.PluginException;
  41 import jdk.tools.jlink.builder.ImageBuilder;
  42 
  43 /**
  44  * API to call jlink.
  45  */
  46 public final class Jlink {
  47 
  48     /**
  49      * Create a plugin.
  50      *


 159          * @param output Output directory, must not exist.
 160          * @param modulepaths Modules paths
 161          * @param modules The possibly-empty set of root modules to resolve
 162          * @param limitmods Limit the universe of observable modules
 163          * @param endian Jimage byte order. Native order by default
 164          */
 165         public JlinkConfiguration(Path output,
 166                                   List<Path> modulepaths,
 167                                   Set<String> modules,
 168                                   Set<String> limitmods,
 169                                   ByteOrder endian) {
 170             if (Objects.requireNonNull(modulepaths).isEmpty()) {
 171                 throw new IllegalArgumentException("Empty module path");
 172             }
 173 
 174             this.output = output;
 175             this.modulepaths = modulepaths;
 176             this.modules = Objects.requireNonNull(modules);
 177             this.limitmods = Objects.requireNonNull(limitmods);
 178             this.endian = Objects.requireNonNull(endian);
 179             this.finder = moduleFinder();

















 180         }
 181 
 182         /**
 183          * @return the modulepaths
 184          */
 185         public List<Path> getModulepaths() {
 186             return modulepaths;
 187         }
 188 
 189         /**
 190          * @return the byte ordering
 191          */
 192         public ByteOrder getByteOrder() {
 193             return endian;
 194         }
 195 
 196         /**
 197          * @return the output
 198          */
 199         public Path getOutput() {


 227          * root modules with full service binding.
 228          */
 229         public Configuration resolveAndBind()
 230         {
 231             return Configuration.empty().resolveAndBind(finder,
 232                                                         ModuleFinder.of(),
 233                                                         modules);
 234         }
 235 
 236         /**
 237          * Returns a {@link Configuration} of the given module path,
 238          * root modules with no service binding.
 239          */
 240         public Configuration resolve()
 241         {
 242             return Configuration.empty().resolve(finder,
 243                                                  ModuleFinder.of(),
 244                                                  modules);
 245         }
 246 
 247         private ModuleFinder moduleFinder() {

 248             Path[] entries = modulepaths.toArray(new Path[0]);
 249             ModuleFinder finder = ModulePath.of(Runtime.version(), true, entries);
 250             if (!limitmods.isEmpty()) {
 251                 finder = JlinkTask.limitFinder(finder, limitmods, modules);
 252             }
 253             return finder;
 254         }
 255 
 256         @Override
 257         public String toString() {
 258             StringBuilder builder = new StringBuilder();
 259 
 260             builder.append("output=").append(output).append("\n");
 261             StringBuilder pathsBuilder = new StringBuilder();
 262             for (Path p : modulepaths) {
 263                 pathsBuilder.append(p).append(",");
 264             }
 265             builder.append("modulepaths=").append(pathsBuilder).append("\n");
 266 
 267             StringBuilder modsBuilder = new StringBuilder();




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.tools.jlink.internal;
  26 
  27 import java.lang.module.Configuration;
  28 import java.lang.module.ModuleFinder;
  29 import java.nio.ByteOrder;
  30 import java.nio.file.Files;
  31 import java.nio.file.Path;
  32 import java.nio.file.Paths;
  33 import java.util.ArrayList;
  34 import java.util.Collections;
  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.Objects;
  38 import java.util.Set;
  39 
  40 import jdk.internal.module.ModulePath;
  41 import jdk.tools.jlink.plugin.Plugin;
  42 import jdk.tools.jlink.plugin.PluginException;
  43 import jdk.tools.jlink.builder.ImageBuilder;
  44 
  45 /**
  46  * API to call jlink.
  47  */
  48 public final class Jlink {
  49 
  50     /**
  51      * Create a plugin.
  52      *


 161          * @param output Output directory, must not exist.
 162          * @param modulepaths Modules paths
 163          * @param modules The possibly-empty set of root modules to resolve
 164          * @param limitmods Limit the universe of observable modules
 165          * @param endian Jimage byte order. Native order by default
 166          */
 167         public JlinkConfiguration(Path output,
 168                                   List<Path> modulepaths,
 169                                   Set<String> modules,
 170                                   Set<String> limitmods,
 171                                   ByteOrder endian) {
 172             if (Objects.requireNonNull(modulepaths).isEmpty()) {
 173                 throw new IllegalArgumentException("Empty module path");
 174             }
 175 
 176             this.output = output;
 177             this.modulepaths = modulepaths;
 178             this.modules = Objects.requireNonNull(modules);
 179             this.limitmods = Objects.requireNonNull(limitmods);
 180             this.endian = Objects.requireNonNull(endian);
 181             ModuleFinder finder = moduleFinder(modulepaths, limitmods, modules);
 182             if (! finder.find("java.base").isPresent()) {
 183                 Path sysPath = getDefaultModulePath();
 184                 if (sysPath != null) {
 185                     this.modulepaths.add(sysPath);
 186                 }
 187                 // if java.base is still not found, error will be thrown later!
 188                 finder = moduleFinder(modulepaths, limitmods, modules);
 189             }
 190             this.finder = finder;
 191         }
 192 
 193         /**
 194          * @return the system module path or null
 195          */
 196         public static Path getDefaultModulePath() {
 197             Path jmods = Paths.get(System.getProperty("java.home"), "jmods");
 198             return Files.isDirectory(jmods)? jmods : null;
 199         }
 200 
 201         /**
 202          * @return the modulepaths
 203          */
 204         public List<Path> getModulepaths() {
 205             return modulepaths;
 206         }
 207 
 208         /**
 209          * @return the byte ordering
 210          */
 211         public ByteOrder getByteOrder() {
 212             return endian;
 213         }
 214 
 215         /**
 216          * @return the output
 217          */
 218         public Path getOutput() {


 246          * root modules with full service binding.
 247          */
 248         public Configuration resolveAndBind()
 249         {
 250             return Configuration.empty().resolveAndBind(finder,
 251                                                         ModuleFinder.of(),
 252                                                         modules);
 253         }
 254 
 255         /**
 256          * Returns a {@link Configuration} of the given module path,
 257          * root modules with no service binding.
 258          */
 259         public Configuration resolve()
 260         {
 261             return Configuration.empty().resolve(finder,
 262                                                  ModuleFinder.of(),
 263                                                  modules);
 264         }
 265 
 266         private static ModuleFinder moduleFinder(List<Path> modulepaths,
 267                 Set<String> limitmods, Set<String> modules) {
 268             Path[] entries = modulepaths.toArray(new Path[0]);
 269             ModuleFinder finder = ModulePath.of(Runtime.version(), true, entries);
 270             if (!limitmods.isEmpty()) {
 271                 finder = JlinkTask.limitFinder(finder, limitmods, modules);
 272             }
 273             return finder;
 274         }
 275 
 276         @Override
 277         public String toString() {
 278             StringBuilder builder = new StringBuilder();
 279 
 280             builder.append("output=").append(output).append("\n");
 281             StringBuilder pathsBuilder = new StringBuilder();
 282             for (Path p : modulepaths) {
 283                 pathsBuilder.append(p).append(",");
 284             }
 285             builder.append("modulepaths=").append(pathsBuilder).append("\n");
 286 
 287             StringBuilder modsBuilder = new StringBuilder();


< prev index next >