Class PathModularization

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

class PathModularization extends Object
Information about the modules contained in a path element. The path element may be a JAR file or a directory. Directories may use either package hierarchy or module hierarchy, but not module source hierarchy. The latter is excluded because this class is for path elements of compiled codes.
  • Field Details

    • NONE

      public static final PathModularization NONE
      A unique constant for all non-modular dependencies.
    • MODULE_INFO

      private static final String MODULE_INFO
      Name of the file to use as a sentinel value for deciding if a directory or a JAR is modular.
      See Also:
    • AUTO_MODULE_NAME

      private static final Attributes.Name AUTO_MODULE_NAME
      The attribute for automatic module name in META-INF/MANIFEST.MF files.
    • filename

      private final String filename
      Filename of the path specified at construction time.
    • descriptors

      @Nonnull final Map<Path,Object> descriptors
      Module information for the path specified at construction time. This map is usually either empty if no module was found, or a singleton map. It may however contain more than one entry if module hierarchy was detected, in which case there is one key per sub-directory.

      Values are instances of either ModuleDescriptor or String. The latter case happens when a JAR file has no module-info.class entry but has an automatic name declared in META-INF/MANIFEST.MF.

      This map may contain null values if the constructor was invoked with resolve parameter set to false. This is more efficient when only the module existence needs to be tested, and module descriptors are not needed.

    • isModuleHierarchy

      final boolean isModuleHierarchy
      Whether module hierarchy was detected. If false, then package hierarchy is assumed. In a package hierarchy, the descriptors map has either zero or one entry. In a module hierarchy, the descriptors map may have an arbitrary number of entries, including one (so the map size cannot be used as a criterion).
  • Constructor Details

    • PathModularization

      private PathModularization()
      Constructs an empty instance for non-modular dependencies.
      See Also:
    • PathModularization

      PathModularization(Path path, boolean resolve) throws IOException
      Finds module information in the given JAR file, output directory, or test output directory. If no module is found, or if module information cannot be extracted, then this constructor builds an empty map.

      If the resolve parameter value is false, then some or all map values may be null instead of the actual module name. This option can avoid the cost of reading module descriptors when only the modules existence needs to be verified.

      Algorithm: If the given path is a directory, then there is a choice:

      • Package hierarchy: if a module-info.class file is found at the root, then builds a singleton map with the module name declared in that descriptor.
      • Module hierarchy: if module-info.class files are found in sub-directories, at a deep intentionally restricted to one level, then builds a map of module names found in the descriptor of each sub-directory.
      Otherwise if the given path is a JAR file, then there is a choice:
      • If a module-info.class file is found in the root directory or in a "META-INF/versions/{n}/" subdirectory, builds a singleton map with the module name declared in that descriptor.
      • Otherwise if an "Automatic-Module-Name" attribute is declared in the META-INF/MANIFEST.MF file, builds a singleton map with the value of that attribute.
      Otherwise builds an empty map.
      Parameters:
      path - directory or JAR file to test
      resolve - whether the module names are requested. If false, null values may be used instead
      Throws:
      IOException - if an error occurred while reading the JAR file or the module descriptor
  • Method Details

    • getPathType

      public JavaPathType getPathType()
      Returns the type of path detected. The return value is JavaPathType.MODULES if the dependency is a modular JAR file or a directory containing module descriptor(s), or JavaPathType.CLASSES otherwise. A JAR file without module descriptor but with an "Automatic-Module-Name" manifest attribute is considered modular.
      Returns:
      the type of path detected
    • addIfFilenameBasedAutomodules

      public void addIfFilenameBasedAutomodules(Collection<String> automodulesDetected)
      If the module has no name, adds the filename of the JAR file in the given collection. This method should be invoked for dependencies placed on JavaPathType.MODULES for preparing a warning asking to not deploy the build artifact on a public repository. If the module has an explicit name either with a module-info.class file or with an "Automatic-Module-Name" attribute in the META-INF/MANIFEST.MF file, then this method does nothing.
    • containsModule

      public boolean containsModule(String name)
      Returns whether the dependency contains a module of the given name.
      Returns:
      whether the dependency contains a module of the given name
    • toString

      public String toString()
      Returns a string representation of this object for debugging purposes. This string representation may change in any future version.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object for debugging purposes