public static final class ModuleDescriptor.Builder extends Object
ModuleDescriptor
objects.
ModuleDescriptor
defines the newModule
,
newOpenModule
, and newAutomaticModule
methods to create builders for building
normal, open, and automatic modules.
The set of packages in the module are accumulated by the
Builder
as the exports
,
opens
,
packages
,
provides
, and
mainClass
methods are
invoked.
The module names, package names, and class names that are parameters specified to the builder methods are the module names, package names, and qualified names of classes (in named packages) as defined in the The Java™ Language Specification.
Example usage:
ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
.requires("java.base")
.exports("org.acme.stats.core.clustering")
.exports("org.acme.stats.core.regression")
.packages(Set.of("org.acme.stats.core.internal"))
.build();
Builder
checks the components and invariants as
components are added to the builder. The rationale for this is to detect
errors as early as possible and not defer all validation to the
build
method.Modifier and Type | Method | Description |
---|---|---|
ModuleDescriptor |
build() |
Builds and returns a
ModuleDescriptor from its components. |
ModuleDescriptor.Builder |
exports(ModuleDescriptor.Exports e) |
Adds an exported package.
|
ModuleDescriptor.Builder |
exports(String pn) |
Adds an exported package.
|
ModuleDescriptor.Builder |
exports(String pn,
Set<String> targets) |
Adds an exported package.
|
ModuleDescriptor.Builder |
exports(Set<ModuleDescriptor.Exports.Modifier> ms,
String pn) |
Adds an exported package with the given (and possibly empty) set of
modifiers.
|
ModuleDescriptor.Builder |
exports(Set<ModuleDescriptor.Exports.Modifier> ms,
String pn,
Set<String> targets) |
Adds an exported package with the given (and possibly empty) set of
modifiers.
|
ModuleDescriptor.Builder |
mainClass(String mc) |
Sets the module main class.
|
ModuleDescriptor.Builder |
opens(ModuleDescriptor.Opens obj) |
Adds an open package.
|
ModuleDescriptor.Builder |
opens(String pn) |
Adds an open package.
|
ModuleDescriptor.Builder |
opens(String pn,
Set<String> targets) |
Adds an open package.
|
ModuleDescriptor.Builder |
opens(Set<ModuleDescriptor.Opens.Modifier> ms,
String pn) |
Adds an open package with the given (and possibly empty) set of
modifiers.
|
ModuleDescriptor.Builder |
opens(Set<ModuleDescriptor.Opens.Modifier> ms,
String pn,
Set<String> targets) |
Adds an open package with the given (and possibly empty) set of
modifiers.
|
ModuleDescriptor.Builder |
osArch(String arch) |
Sets the operating system architecture.
|
ModuleDescriptor.Builder |
osName(String name) |
Sets the operating system name.
|
ModuleDescriptor.Builder |
osVersion(String version) |
Sets the operating system version.
|
ModuleDescriptor.Builder |
packages(Set<String> pns) |
Adds packages to the module.
|
ModuleDescriptor.Builder |
provides(ModuleDescriptor.Provides p) |
Provides a service with one or more implementations.
|
ModuleDescriptor.Builder |
provides(String service,
List<String> providers) |
Provides implementations of a service.
|
ModuleDescriptor.Builder |
requires(ModuleDescriptor.Requires req) |
Adds a dependence on a module.
|
ModuleDescriptor.Builder |
requires(String mn) |
Adds a dependence on a module with an empty set of modifiers.
|
ModuleDescriptor.Builder |
requires(Set<ModuleDescriptor.Requires.Modifier> ms,
String mn) |
Adds a dependence on a module with the given (and possibly empty)
set of modifiers.
|
ModuleDescriptor.Builder |
requires(Set<ModuleDescriptor.Requires.Modifier> ms,
String mn,
ModuleDescriptor.Version compiledVersion) |
Adds a dependence on a module with the given (and possibly empty)
set of modifiers.
|
ModuleDescriptor.Builder |
uses(String service) |
Adds a service dependence.
|
ModuleDescriptor.Builder |
version(ModuleDescriptor.Version v) |
Sets the module version.
|
ModuleDescriptor.Builder |
version(String vs) |
Sets the module version.
|
public ModuleDescriptor.Builder requires(ModuleDescriptor.Requires req)
req
- The dependenceIllegalArgumentException
- If the dependence is on the module that this builder was
initialized to buildIllegalStateException
- If the dependence on the module has already been declared
or this builder is for an automatic modulepublic ModuleDescriptor.Builder requires(Set<ModuleDescriptor.Requires.Modifier> ms, String mn, ModuleDescriptor.Version compiledVersion)
ms
- The set of modifiersmn
- The module namecompiledVersion
- The version of the module recorded at compile-timeIllegalArgumentException
- If the module name is null
, is not a legal module
name, or is equal to the module name that this builder
was initialized to buildIllegalStateException
- If the dependence on the module has already been declared
or this builder is for an automatic modulepublic ModuleDescriptor.Builder requires(Set<ModuleDescriptor.Requires.Modifier> ms, String mn)
ms
- The set of modifiersmn
- The module nameIllegalArgumentException
- If the module name is null
, is not a legal module
name, or is equal to the module name that this builder
was initialized to buildIllegalStateException
- If the dependence on the module has already been declared
or this builder is for an automatic modulepublic ModuleDescriptor.Builder requires(String mn)
mn
- The module nameIllegalArgumentException
- If the module name is null
, is not a legal module
name, or is equal to the module name that this builder
was initialized to buildIllegalStateException
- If the dependence on the module has already been declared
or this builder is for an automatic modulepublic ModuleDescriptor.Builder exports(ModuleDescriptor.Exports e)
e
- The exportIllegalStateException
- If the package
is already declared as
exported or this builder is for an automatic modulepublic ModuleDescriptor.Builder exports(Set<ModuleDescriptor.Exports.Modifier> ms, String pn, Set<String> targets)
ms
- The set of modifierspn
- The package nametargets
- The set of target modules namesIllegalArgumentException
- If the package name is null
or is not a legal
package name, the set of target modules is empty, or the set
of target modules contains a name that is not a legal module
nameIllegalStateException
- If the package is already declared as exported
or this builder is for an automatic modulepublic ModuleDescriptor.Builder exports(Set<ModuleDescriptor.Exports.Modifier> ms, String pn)
ms
- The set of modifierspn
- The package nameIllegalArgumentException
- If the package name is null
or is not a legal
package nameIllegalStateException
- If the package is already declared as exported
or this builder is for an automatic modulepublic ModuleDescriptor.Builder exports(String pn, Set<String> targets)
pn
- The package nametargets
- The set of target modules namesIllegalArgumentException
- If the package name is null
or is not a legal
package name, the set of target modules is empty, or the set
of target modules contains a name that is not a legal module
nameIllegalStateException
- If the package is already declared as exported
or this builder is for an automatic modulepublic ModuleDescriptor.Builder exports(String pn)
pn
- The package nameIllegalArgumentException
- If the package name is null
or is not a legal
package nameIllegalStateException
- If the package is already declared as exported
or this builder is for an automatic modulepublic ModuleDescriptor.Builder opens(ModuleDescriptor.Opens obj)
obj
- The Opens
objectIllegalStateException
- If the package is already declared as open, or this is a
builder for an open module or automatic modulepublic ModuleDescriptor.Builder opens(Set<ModuleDescriptor.Opens.Modifier> ms, String pn, Set<String> targets)
ms
- The set of modifierspn
- The package nametargets
- The set of target modules namesIllegalArgumentException
- If the package name is null
or is not a legal
package name, the set of target modules is empty, or the set
of target modules contains a name that is not a legal module
nameIllegalStateException
- If the package is already declared as open, or this is a
builder for an open module or automatic modulepublic ModuleDescriptor.Builder opens(Set<ModuleDescriptor.Opens.Modifier> ms, String pn)
ms
- The set of modifierspn
- The package nameIllegalArgumentException
- If the package name is null
or is not a legal
package nameIllegalStateException
- If the package is already declared as open, or this is a
builder for an open module or automatic modulepublic ModuleDescriptor.Builder opens(String pn, Set<String> targets)
pn
- The package nametargets
- The set of target modules namesIllegalArgumentException
- If the package name is null
or is not a legal
package name, the set of target modules is empty, or the set
of target modules contains a name that is not a legal module
nameIllegalStateException
- If the package is already declared as open, or this is a
builder for an open module or automatic modulepublic ModuleDescriptor.Builder opens(String pn)
pn
- The package nameIllegalArgumentException
- If the package name is null
or is not a legal
package nameIllegalStateException
- If the package is already declared as open, or this is a
builder for an open module or automatic modulepublic ModuleDescriptor.Builder uses(String service)
service
- The service typeIllegalArgumentException
- If the service type is null
or not a qualified name of
a class in a named packageIllegalStateException
- If a dependency on the service type has already been declared
or this is a builder for an an automatic modulepublic ModuleDescriptor.Builder provides(ModuleDescriptor.Provides p)
provider
(or provider factory) is
added to the module if not already added.p
- The providesIllegalStateException
- If the providers for the service type have already been
declaredpublic ModuleDescriptor.Builder provides(String service, List<String> providers)
service
- The service typeproviders
- The list of provider or provider factory class namesIllegalArgumentException
- If the service type or any of the provider class names is
null
or not a qualified name of a class in a named
package, or the list of provider class names is emptyIllegalStateException
- If the providers for the service type have already been
declaredpublic ModuleDescriptor.Builder packages(Set<String> pns)
pns
- The (possibly empty) set of package namesIllegalArgumentException
- If any of the package names is null
or is not a
legal package namepublic ModuleDescriptor.Builder version(ModuleDescriptor.Version v)
v
- The versionpublic ModuleDescriptor.Builder version(String vs)
vs
- The version string to parseIllegalArgumentException
- If vs
is null
or cannot be parsed as a
version stringModuleDescriptor.Version.parse(String)
public ModuleDescriptor.Builder mainClass(String mc)
mc
- The module main classIllegalArgumentException
- If mainClass
is null
or not a qualified
name of a class in a named packagepublic ModuleDescriptor.Builder osName(String name)
name
- The operating system nameIllegalArgumentException
- If name
is null
or the empty Stringpublic ModuleDescriptor.Builder osArch(String arch)
arch
- The operating system architectureIllegalArgumentException
- If name
is null
or the empty Stringpublic ModuleDescriptor.Builder osVersion(String version)
version
- The operating system versionIllegalArgumentException
- If name
is null
or the empty Stringpublic ModuleDescriptor build()
ModuleDescriptor
from its components.
The module will require "java.base
" even if the dependence
has not been declared (the exception is when building a module named
"java.base
" as it cannot require itself). The dependence on
"java.base
" will have the MANDATED
modifier if the dependence was not declared.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-internal+0-adhoc.mlchung.jdk9-jdeps