Class PathModularizationCache

java.lang.Object
org.apache.maven.internal.impl.PathModularizationCache

class PathModularizationCache extends Object
Cache of PathModularization instances computed for given Path elements. The cache is used for avoiding the need to reopen the same files many times when the same dependency is used for different scope. For example a path used for compilation is typically also used for tests.
  • Field Details

    • moduleInfo

      private final Map<Path,PathModularization> moduleInfo
      Module information for each JAR file or output directories. Cached when first requested to avoid decoding the module descriptors multiple times.
      See Also:
    • pathTypes

      private final Map<Path,PathType> pathTypes
      Whether JAR files are modular. This map is redundant with moduleInfo, but cheaper to compute when the module names are not needed.
      See Also:
  • Constructor Details

    • PathModularizationCache

      PathModularizationCache()
      Creates an initially empty cache.
  • Method Details

    • getModuleInfo

      PathModularization getModuleInfo(Path path) throws IOException
      Gets module information for the given JAR file or output directory. Module descriptors are read when first requested, then cached.
      Throws:
      IOException
    • getPathType

      private PathType getPathType(Path path) throws IOException
      Returns JavaPathType.MODULES if the given JAR file or output directory is modular. This is used in heuristic rules for deciding whether to place a dependency on the class-path or on the module-path when the "jar" artifact type is used.
      Throws:
      IOException
    • selectPathType

      Optional<PathType> selectPathType(Set<PathType> types, Predicate<PathType> filter, Path path) throws IOException
      Selects the type of path where to place the given dependency. This method returns one of the values specified in the given collection. This method does not handle the patch-module paths, because the patches depend on which modules have been previously added on the module-paths.

      If the dependency can be a constituent of both the class-path and the module-path, then the path type is determined by checking if the dependency is modular.

      Parameters:
      types - types of path where a dependency can be placed
      filter - filter the paths accepted by the tool which will consume the path
      path - path to the JAR file or output directory of the dependency
      Returns:
      where to place the dependency, or an empty value if the placement cannot be determined
      Throws:
      IOException - if an error occurred while reading module information
    • warningForFilenameBasedAutomodules

      Optional<String> warningForFilenameBasedAutomodules(Collection<Path> modulePaths) throws IOException
      If the module-path contains a filename-based auto-module, prepares a warning message. It is caller's responsibility to send the message to a logger.
      Parameters:
      modulePaths - content of the module path, or null if none
      Returns:
      warning message if at least one filename-based auto-module was found
      Throws:
      IOException - if an error occurred while reading module information