< prev index next >
src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2015, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 22,40 ****
--- 22,44 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
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;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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;
/**
*** 145,156 ****
private final List<Path> modulepaths;
private final Path output;
private final Set<String> modules;
private final Set<String> limitmods;
-
private final ByteOrder endian;
/**
* jlink configuration,
*
* @param output Output directory, must not exist.
--- 149,160 ----
private final List<Path> modulepaths;
private final Path output;
private final Set<String> modules;
private final Set<String> limitmods;
private final ByteOrder endian;
+ private final ModuleFinder finder;
/**
* jlink configuration,
*
* @param output Output directory, must not exist.
*** 162,192 ****
public JlinkConfiguration(Path output,
List<Path> modulepaths,
Set<String> modules,
Set<String> 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;
}
! /**
! * 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<Path> modulepaths,
! Set<String> modules,
! Set<String> limitmods) {
! this(output, modulepaths, modules, limitmods,
! ByteOrder.nativeOrder());
}
/**
* @return the modulepaths
*/
--- 166,188 ----
public JlinkConfiguration(Path output,
List<Path> modulepaths,
Set<String> modules,
Set<String> limitmods,
ByteOrder endian) {
! if (Objects.requireNonNull(modulepaths).isEmpty()) {
! throw new IllegalArgumentException("Empty module path");
! }
! if (Objects.requireNonNull(modules).isEmpty()) {
! throw new IllegalArgumentException("Empty modules");
}
! this.output = output;
! this.modulepaths = modulepaths;
! this.modules = modules;
! this.limitmods = Objects.requireNonNull(limitmods);
! this.endian = Objects.requireNonNull(endian);
! this.finder = moduleFinder();
}
/**
* @return the modulepaths
*/
*** 220,229 ****
--- 216,264 ----
*/
public Set<String> getLimitmods() {
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();
builder.append("output=").append(output).append("\n");
< prev index next >