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.NameThe attribute for automatic module name inMETA-INF/MANIFEST.MFfiles.Module information for the path specified at construction time.private final StringFilename of the path specified at construction time.(package private) final booleanWhether module hierarchy was detected.private static final StringName of the file to use as a sentinel value for deciding if a directory or a JAR is modular.static final PathModularizationA unique constant for all non-modular dependencies. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateConstructs 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 TypeMethodDescriptionvoidaddIfFilenameBasedAutomodules(Collection<String> automodulesDetected) If the module has no name, adds the filename of the JAR file in the given collection.booleancontainsModule(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.MFfiles. -
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
ModuleDescriptororString. The latter case happens when a JAR file has nomodule-info.classentry but has an automatic name declared inMETA-INF/MANIFEST.MF.This map may contain null values if the constructor was invoked with
resolveparameter 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
resolveparameter 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.classfile is found at the root, then builds a singleton map with the module name declared in that descriptor. - Module hierarchy: if
module-info.classfiles 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.classfile 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.MFfile, 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.MODULESif the dependency is a modular JAR file or a directory containing module descriptor(s), orJavaPathType.CLASSESotherwise. 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.MODULESfor 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.classfile or with an"Automatic-Module-Name"attribute in theMETA-INF/MANIFEST.MFfile, 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.
-