< prev index next >
src/java.base/share/classes/jdk/internal/module/Builder.java
Print this page
*** 28,42 ****
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens;
import java.lang.module.ModuleDescriptor.Provides;
import java.lang.module.ModuleDescriptor.Requires;
import java.lang.module.ModuleDescriptor.Version;
- import java.util.ArrayList;
import java.util.Collections;
- import java.util.HashMap;
import java.util.List;
- import java.util.Map;
import java.util.Set;
import jdk.internal.misc.JavaLangModuleAccess;
import jdk.internal.misc.SharedSecrets;
--- 28,39 ----
*** 50,120 ****
* sets/maps created in this Builder.
*
* SystemModules should contain modules for the boot layer.
*/
final class Builder {
! private static final JavaLangModuleAccess jlma =
SharedSecrets.getJavaLangModuleAccess();
// Static cache of the most recently seen Version to cheaply deduplicate
// most Version objects. JDK modules have the same version.
static Version cachedVersion;
/**
! * Returns a {@link Requires} for a dependence on a module
! * with the given (and possibly empty) set of modifiers.
*/
public static Requires newRequires(Set<Requires.Modifier> mods,
String mn)
{
! return jlma.newRequires(mods, mn);
}
/**
* Returns a {@link Exports} for a qualified export, with
* the given (and possibly empty) set of modifiers,
* to a set of target modules.
*/
public static Exports newExports(Set<Exports.Modifier> ms,
String pn,
Set<String> targets) {
! return jlma.newExports(ms, pn, targets);
}
/**
* Returns an {@link Opens} for an unqualified open with a given set of
* modifiers.
*/
public static Opens newOpens(Set<Opens.Modifier> ms, String pn) {
! return jlma.newOpens(ms, pn);
}
/**
* Returns an {@link Opens} for a qualified opens, with
* the given (and possibly empty) set of modifiers,
* to a set of target modules.
*/
public static Opens newOpens(Set<Opens.Modifier> ms,
String pn,
Set<String> targets) {
! return jlma.newOpens(ms, pn, targets);
}
/**
* Returns a {@link Exports} for an unqualified export with a given set
* of modifiers.
*/
public static Exports newExports(Set<Exports.Modifier> ms, String pn) {
! return jlma.newExports(ms, pn);
}
/**
* Returns a {@link Provides} for a service with a given list of
* implementation classes.
*/
public static Provides newProvides(String st, List<String> pcs) {
! return jlma.newProvides(st, pcs);
}
final String name;
boolean open;
boolean automatic;
--- 47,140 ----
* sets/maps created in this Builder.
*
* SystemModules should contain modules for the boot layer.
*/
final class Builder {
! private static final JavaLangModuleAccess JLMA =
SharedSecrets.getJavaLangModuleAccess();
// Static cache of the most recently seen Version to cheaply deduplicate
// most Version objects. JDK modules have the same version.
static Version cachedVersion;
/**
! * Returns a {@link Requires} for a dependence on a module with the given
! * (and possibly empty) set of modifiers, and optionally the version
! * recorded at compile time.
! */
! public static Requires newRequires(Set<Requires.Modifier> mods,
! String mn,
! String compiledVersion)
! {
! Version version = null;
! if (compiledVersion != null) {
! // use the cached version if the same version string
! Version ver = cachedVersion;
! if (ver != null && compiledVersion.equals(ver.toString())) {
! version = ver;
! } else {
! version = Version.parse(compiledVersion);
! }
! }
! return JLMA.newRequires(mods, mn, version);
! }
!
! /**
! * Returns a {@link Requires} for a dependence on a module with the given
! * (and possibly empty) set of modifiers, and optionally the version
! * recorded at compile time.
*/
public static Requires newRequires(Set<Requires.Modifier> mods,
String mn)
{
! return newRequires(mods, mn, null);
}
/**
* Returns a {@link Exports} for a qualified export, with
* the given (and possibly empty) set of modifiers,
* to a set of target modules.
*/
public static Exports newExports(Set<Exports.Modifier> ms,
String pn,
Set<String> targets) {
! return JLMA.newExports(ms, pn, targets);
}
/**
* Returns an {@link Opens} for an unqualified open with a given set of
* modifiers.
*/
public static Opens newOpens(Set<Opens.Modifier> ms, String pn) {
! return JLMA.newOpens(ms, pn);
}
/**
* Returns an {@link Opens} for a qualified opens, with
* the given (and possibly empty) set of modifiers,
* to a set of target modules.
*/
public static Opens newOpens(Set<Opens.Modifier> ms,
String pn,
Set<String> targets) {
! return JLMA.newOpens(ms, pn, targets);
}
/**
* Returns a {@link Exports} for an unqualified export with a given set
* of modifiers.
*/
public static Exports newExports(Set<Exports.Modifier> ms, String pn) {
! return JLMA.newExports(ms, pn);
}
/**
* Returns a {@link Provides} for a service with a given list of
* implementation classes.
*/
public static Provides newProvides(String st, List<String> pcs) {
! return JLMA.newProvides(st, pcs);
}
final String name;
boolean open;
boolean automatic;
*** 128,139 ****
Version version;
String mainClass;
String osName;
String osArch;
String osVersion;
- String algorithm;
- Map<String, byte[]> hashes;
Builder(String name) {
this.name = name;
this.requires = Collections.emptySet();
this.exports = Collections.emptySet();
--- 148,157 ----
*** 273,323 ****
this.osVersion = version;
return this;
}
/**
- * Sets the algorithm of the module hashes
- */
- public Builder algorithm(String algorithm) {
- this.algorithm = algorithm;
- return this;
- }
-
- /**
- * Sets the module hash for the given module name
- */
- public Builder moduleHash(String mn, byte[] hash) {
- if (hashes == null)
- hashes = new HashMap<>();
-
- hashes.put(mn, hash);
- return this;
- }
-
- /**
* Builds a {@code ModuleDescriptor} from the components.
*/
public ModuleDescriptor build(int hashCode) {
assert name != null;
! ModuleHashes moduleHashes =
! hashes != null ? new ModuleHashes(algorithm, hashes) : null;
!
! return jlma.newModuleDescriptor(name,
open,
automatic,
synthetic,
requires,
exports,
opens,
uses,
provides,
! version,
mainClass,
osName,
osArch,
osVersion,
- packages,
- moduleHashes,
hashCode);
}
}
--- 291,318 ----
this.osVersion = version;
return this;
}
/**
* Builds a {@code ModuleDescriptor} from the components.
*/
public ModuleDescriptor build(int hashCode) {
assert name != null;
! return JLMA.newModuleDescriptor(name,
! version,
open,
automatic,
synthetic,
requires,
exports,
opens,
uses,
provides,
! packages,
mainClass,
osName,
osArch,
osVersion,
hashCode);
}
}
< prev index next >