Class DefaultDependencyResolverResult

java.lang.Object
org.apache.maven.impl.DefaultDependencyResolverResult
All Implemented Interfaces:
DependencyResolverResult, Result<DependencyResolverRequest>

public class DefaultDependencyResolverResult extends Object implements 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:
  • addOutputDirectory(Path, Path) (optional)
  • addDependency(Node, Dependency, Predicate, Path)
See Also:
  • Constructor Details

    • DefaultDependencyResolverResult

      public DefaultDependencyResolverResult(DependencyResolverRequest request, org.apache.maven.impl.PathModularizationCache cache, List<Exception> exceptions, Node root, int count)
      Creates an initially empty result. Callers should add path elements by calls to addDependency(Node, Dependency, Predicate, Path).
      Parameters:
      request - the corresponding request
      cache - cache of module information about each dependency
      exceptions - the exceptions that occurred while building the dependency graph
      root - the root node of the dependency graph
      count - estimated number of dependencies
  • Method Details

    • getRequest

      public DependencyResolverRequest getRequest()
      Description copied from interface: Result
      Returns the request that produced this result.
      Specified by:
      getRequest in interface Result<DependencyResolverRequest>
      Returns:
      the originating request instance, never null
    • getExceptions

      public List<Exception> getExceptions()
      Description copied from interface: DependencyResolverResult
      Gets the exceptions that occurred while building the dependency graph.
      Specified by:
      getExceptions in interface DependencyResolverResult
      Returns:
      the exceptions that occurred, never null
    • getRoot

      public Node getRoot()
      Description copied from interface: DependencyResolverResult
      Gets the root node of the dependency graph.
      Specified by:
      getRoot in interface DependencyResolverResult
      Returns:
      the root node of the dependency graph or null if none
    • getNodes

      public List<Node> getNodes()
      Description copied from interface: DependencyResolverResult
      The ordered list of the flattened dependency nodes.
      Specified by:
      getNodes in interface DependencyResolverResult
      Returns:
      the ordered list of the flattened dependency nodes
    • getPaths

      public List<Path> 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 as getDependencies.values() except that it does not contain null elements.
      Specified by:
      getPaths in interface DependencyResolverResult
      Returns:
      the paths of all dependencies
    • getDispatchedPaths

      public Map<PathType,List<Path>> getDispatchedPaths()
      Description copied from interface: DependencyResolverResult
      Returns the file paths of all dependencies, dispatched according the tool options where to place them. The PathType 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 by PathType.
      Specified by:
      getDispatchedPaths in interface DependencyResolverResult
      Returns:
      file paths to place on the different tool options
    • getDependencies

      public Map<Dependency,Path> 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 interface DependencyResolverResult
      Returns:
      all dependencies associated to their paths
    • getModuleDescriptor

      public Optional<ModuleDescriptor> getModuleDescriptor(Path dependency) throws IOException
      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 by DependencyResolverResult.getDependencies(). The module descriptor is extracted from the module-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 interface DependencyResolverResult
      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

      public Optional<String> getModuleName(Path dependency) throws IOException
      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 by DependencyResolverResult.getDependencies(). The module name is extracted from the module-info.class file if present, otherwise from the "Automatic-Module-Name" attribute of the META-INF/MANIFEST.MF file if present.

      A typical usage is to invoke this method for all dependencies having a TEST or TEST_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 interface DependencyResolverResult
      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
    • warningForFilenameBasedAutomodules

      public Optional<String> 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 with JavaPathType.MODULES. It is caller's responsibility to send the message to a logger.
      Specified by:
      warningForFilenameBasedAutomodules in interface DependencyResolverResult
      Returns:
      warning message if at least one filename-based auto-module was found