Package org.apache.maven.internal.impl
Class DefaultDependencyResolverResult
java.lang.Object
org.apache.maven.internal.impl.DefaultDependencyResolverResult
- All Implemented Interfaces:
DependencyResolverResult
The result of collecting dependencies with a dependency resolver.
New instances are initially empty. Callers must populate with calls
to the following methods, in that order:
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PathModularizationCache
Cache of module information about each dependency.private final Map
<Dependency, Path> The dependencies together with the path to each dependency.The file paths of all dependencies, dispatched according the Java options where to place them.The exceptions that occurred while building the dependency graph.The ordered list of the flattened dependency nodes.private PathModularization
Information about modules in the main output.The file paths of all dependencies, regardless on which Java tool option those paths should be placed.private final Node
The root node of the dependency graph. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultDependencyResolverResult
(PathModularizationCache cache, List<Exception> exceptions, Node root, int count) Creates an initially empty result. -
Method Summary
Modifier and TypeMethodDescription(package private) void
addDependency
(Node node, Dependency dep, Predicate<PathType> filter, Path path) Adds a dependency to the result.(package private) void
Adds a dependency node to the result.(package private) void
addOutputDirectory
(Path main, Path test) Adds main and test output directories to the result.private void
addPathElement
(PathType type, Path path) Adds the given path element to the specified type of path.private boolean
containsModule
(String moduleName) Returns whether at least one previously added modular dependency contains a module of the given name.private boolean
containsPatches
(Set<PathType> types) Returns whether the given set of path types contains at least one patch for a module.private Path
findArtifactPath
(String group, String artifact) Searches an artifact of the given group and artifact identifiers, and returns its pathReturns all dependencies associated to their paths.Returns the file paths of all dependencies, dispatched according the tool options where to place them.Gets the exceptions that occurred while building the dependency graph.getModuleDescriptor
(Path dependency) Returns the Java module descriptor of the dependency at the given path.getModuleName
(Path dependency) Returns the Java module name of the dependency at the given path.getNodes()
The ordered list of the flattened dependency nodes.getPaths()
Returns the file paths of all dependencies, regardless on which tool option those paths should be placed.getRoot()
Gets the root node of the dependency graph.private static String
Returns the module name for the given value of thePathModularization.descriptors
map.If the module-path contains at least one filename-based auto-module, prepares a warning message.
-
Field Details
-
exceptions
The exceptions that occurred while building the dependency graph. -
root
The root node of the dependency graph. -
nodes
The ordered list of the flattened dependency nodes. -
paths
The file paths of all dependencies, regardless on which Java tool option those paths should be placed. -
dispatchedPaths
The file paths of all dependencies, dispatched according the Java options where to place them. -
dependencies
The dependencies together with the path to each dependency. -
outputModules
Information about modules in the main output. This field is initially null and is set to a non-null value when the output directories have been set, or when it is too late for setting them. -
cache
Cache of module information about each dependency.
-
-
Constructor Details
-
DefaultDependencyResolverResult
DefaultDependencyResolverResult(PathModularizationCache cache, List<Exception> exceptions, Node root, int count) Creates an initially empty result. Callers should add path elements by calls toaddDependency(Node, Dependency, Predicate, Path)
.- Parameters:
cache
- cache of module information about each dependencyexceptions
- the exceptions that occurred while building the dependency graphroot
- the root node of the dependency graphcount
- estimated number of dependencies
-
-
Method Details
-
addPathElement
Adds the given path element to the specified type of path.- Parameters:
type
- the type of path (class-path, module-path, …)path
- the path element to add
-
addOutputDirectory
Adds main and test output directories to the result. This method adds the main output directory to the module-path if it contains amodule-info.class
, or to the class-path otherwise. For the test output directory, the rules are more complex and are governed by the fact that Java does not accept the placement of two modules of the same name on the module-path. So the modular test output directory usually needs to be placed in a--path-module
option.- If the test output directory is modular, then:
- If a test module name is identical to a main module name,
place the test directory in a
--patch-module
option. - Otherwise, place the test directory on the module-path. However, this case (a module existing only in test output, not in main output) should be uncommon.
- If a test module name is identical to a main module name,
place the test directory in a
- Otherwise (test output contains no module information), then:
- If the main output is on the module-path, place the test output
on a
--patch-module
option. - Otherwise (main output on the class-path), place the test output on the class-path too.
- If the main output is on the module-path, place the test output
on a
addDependency(Node, Dependency, Predicate, Path)
if output directories are desired on the class-path or module-path. This method can be invoked at most once.- Parameters:
main
- the main output directory, ornull
if nonetest
- the test output directory, ornull
if none- Throws:
IOException
- if an error occurred while reading module information TODO: this is currently not called. This is intended for use by Surefire and may move there.
- If the test output directory is modular, then:
-
addNode
Adds a dependency node to the result.- Parameters:
node
- the dependency node
-
addDependency
void addDependency(Node node, Dependency dep, Predicate<PathType> filter, Path path) throws IOException Adds a dependency to the result. This method populates thenodes
,paths
,dispatchedPaths
anddependencies
collections with the given arguments.- Parameters:
node
- the dependency nodedep
- the dependency for the given node, ornull
if nonefilter
- filter the paths accepted by the tool which will consume the path.path
- the path to the dependency, ornull
if the dependency was null- Throws:
IOException
- if an error occurred while reading module information
-
containsPatches
Returns whether the given set of path types contains at least one patch for a module. -
containsModule
Returns whether at least one previously added modular dependency contains a module of the given name.- Parameters:
moduleName
- name of the module to search- Throws:
IOException
-
findArtifactPath
Searches an artifact of the given group and artifact identifiers, and returns its path- Parameters:
group
- the group identifier to searchartifact
- the artifact identifier to search- Returns:
- path to the desired artifact, or
null
if not found - Throws:
IOException
-
getExceptions
Description copied from interface:DependencyResolverResult
Gets the exceptions that occurred while building the dependency graph.- Specified by:
getExceptions
in interfaceDependencyResolverResult
- Returns:
- the exceptions that occurred, never
null
-
getRoot
Description copied from interface:DependencyResolverResult
Gets the root node of the dependency graph.- Specified by:
getRoot
in interfaceDependencyResolverResult
- Returns:
- the root node of the dependency graph or
null
if none
-
getNodes
Description copied from interface:DependencyResolverResult
The ordered list of the flattened dependency nodes.- Specified by:
getNodes
in interfaceDependencyResolverResult
- Returns:
- the ordered list of the flattened dependency nodes
-
getPaths
Description copied from interface:DependencyResolverResult
Returns the file paths of all dependencies, regardless on which tool option those paths should be placed. The returned list may contain a mix of Java class-path, Java module-path, and other types of path elements. This collection has the same content thangetDependencies.values()
except that it does not contain null elements.- Specified by:
getPaths
in interfaceDependencyResolverResult
- Returns:
- the paths of all dependencies
-
getDispatchedPaths
Description copied from interface:DependencyResolverResult
Returns the file paths of all dependencies, dispatched according the tool options where to place them. ThePathType
keys identify, for example,--class-path
or--module-path
options. In the case of Java tools, the map may also contain--patch-module
options, which are handled in a special way.Design note
All types of path are determined together because they are sometime mutually exclusive. For example, an artifact of type "jar" can be placed either on the class-path or on the module-path. The project needs to make a choice (possibly using heuristic rules), then to add the dependency in only one of the options identified byPathType
.- Specified by:
getDispatchedPaths
in interfaceDependencyResolverResult
- Returns:
- file paths to place on the different tool options
-
getDependencies
Description copied from interface:DependencyResolverResult
Returns all dependencies associated to their paths. Some dependencies may be associated to a null value if there is no path available.- Specified by:
getDependencies
in interfaceDependencyResolverResult
- Returns:
- all dependencies associated to their paths
-
getModuleDescriptor
Description copied from interface:DependencyResolverResult
Returns the Java module descriptor of the dependency at the given path. The given dependency should be one of the paths returned byDependencyResolverResult.getDependencies()
. The module descriptor is extracted from themodule-info.class
file if present.DependencyResolverResult.getModuleName(Path)
is preferred when only the module name is desired, because a name may be present even if the descriptor is absent. This method is for cases when more information is desired, such as the set of exported packages.- Specified by:
getModuleDescriptor
in interfaceDependencyResolverResult
- Parameters:
dependency
- path to the dependency for which to get the module name- Returns:
- module name of the dependency at the given path, or empty if the dependency is not modular
- Throws:
IOException
- if the module information of the specified dependency cannot be read
-
getModuleName
Description copied from interface:DependencyResolverResult
Returns the Java module name of the dependency at the given path. The given dependency should be one of the paths returned byDependencyResolverResult.getDependencies()
. The module name is extracted from themodule-info.class
file if present, otherwise from the"Automatic-Module-Name"
attribute of theMETA-INF/MANIFEST.MF
file if present.A typical usage is to invoke this method for all dependencies having a
TEST
orTEST_ONLY
scope. An--add-reads
option may need to be generated for compiling and running the test classes that use such dependencies.- Specified by:
getModuleName
in interfaceDependencyResolverResult
- Parameters:
dependency
- path to the dependency for which to get the module name- Returns:
- module name of the dependency at the given path, or empty if the dependency is not modular
- Throws:
IOException
- if the module information of the specified dependency cannot be read
-
name
Returns the module name for the given value of thePathModularization.descriptors
map. -
warningForFilenameBasedAutomodules
Description copied from interface:DependencyResolverResult
If the module-path contains at least one filename-based auto-module, prepares a warning message. The module path is the collection of dependencies associated toJavaPathType.MODULES
. It is caller's responsibility to send the message to a logger.- Specified by:
warningForFilenameBasedAutomodules
in interfaceDependencyResolverResult
- Returns:
- warning message if at least one filename-based auto-module was found
-