Package org.apache.maven.internal.impl
Class PathModularization
java.lang.Object
org.apache.maven.internal.impl.PathModularization
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final Attributes.Name
The attribute for automatic module name inMETA-INF/MANIFEST.MF
files.Module information for the path specified at construction time.private final String
Filename of the path specified at construction time.(package private) final boolean
Whether module hierarchy was detected.private static final String
Name of the file to use as a sentinel value for deciding if a directory or a JAR is modular.static final PathModularization
A unique constant for all non-modular dependencies. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Constructs an empty instance for non-modular dependencies.(package private)
PathModularization
(Path path, boolean resolve) Finds module information in the given JAR file, output directory, or test output directory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIfFilenameBasedAutomodules
(Collection<String> automodulesDetected) If the module has no name, adds the filename of the JAR file in the given collection.boolean
containsModule
(String name) Returns whether the dependency contains a module of the given name.Returns the type of path detected.toString()
Returns a string representation of this object for debugging purposes.
-
Field Details
-
NONE
A unique constant for all non-modular dependencies. -
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
The attribute for automatic module name inMETA-INF/MANIFEST.MF
files. -
filename
Filename of the path specified at construction time. -
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
orString
. The latter case happens when a JAR file has nomodule-info.class
entry but has an automatic name declared inMETA-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 isModuleHierarchyWhether 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 isfalse
, 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.
- 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 theMETA-INF/MANIFEST.MF
file, builds a singleton map with the value of that attribute.
- Parameters:
path
- directory or JAR file to testresolve
- 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
- Package hierarchy: if a
-
-
Method Details
-
getPathType
Returns the type of path detected. The return value isJavaPathType.MODULES
if the dependency is a modular JAR file or a directory containing module descriptor(s), orJavaPathType.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
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 onJavaPathType.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 amodule-info.class
file or with an"Automatic-Module-Name"
attribute in theMETA-INF/MANIFEST.MF
file, then this method does nothing. -
containsModule
Returns whether the dependency contains a module of the given name.- Returns:
- whether the dependency contains a module of the given name
-
toString
Returns a string representation of this object for debugging purposes. This string representation may change in any future version.
-