Class ManifestArtifactResourceResolver
- java.lang.Object
-
- io.microsphere.classloading.AbstractArtifactResourceResolver
-
- io.microsphere.classloading.StreamArtifactResourceResolver
-
- io.microsphere.classloading.ManifestArtifactResourceResolver
-
- All Implemented Interfaces:
ArtifactResourceResolver
,Prioritized
,java.lang.Comparable<Prioritized>
public class ManifestArtifactResourceResolver extends StreamArtifactResourceResolver
ArtifactResourceResolver
implementation that reads artifact metadata from JAR manifest files.This resolver looks for artifact information in the
META-INF/MANIFEST.MF
file of a JAR or directory. It extracts the artifact ID and version using configurable manifest attributes.Configuration Options
You can customize which manifest attributes are used to extract the artifact ID and version by setting system properties:
- "microsphere.artifact-id.manifest-attribute-names": A comma-separated list of attribute names to use for extracting the artifact ID. Default: "Bundle-Name,Automatic-Module-Name,Implementation-Title"
- "microsphere.artifact-version.manifest-attribute-names": A comma-separated list of attribute names to use for extracting the artifact version. Default: "Bundle-Version,Implementation-Version"
Example Usage
// Using default priority ArtifactResourceResolver resolver = new ManifestArtifactResourceResolver(); // With custom priority ArtifactResourceResolver resolver = new ManifestArtifactResourceResolver(10); // With custom class loader and priority ArtifactResourceResolver resolver = new ManifestArtifactResourceResolver(getClass().getClassLoader(), 10);
Manifest Attribute Examples
The resolver will look at standard and custom manifest attributes. Here's an example MANIFEST.MF:
Manifest-Version: 1.0 Bundle-Name: my-artifact Bundle-Version: 1.2.3 Implementation-Title: my-artifact Implementation-Version: 1.2.3 Automatic-Module-Name: com.example.myartifact
In this case, the resolver would extract:
- Artifact ID: "my-artifact" (from Bundle-Name)
- Version: "1.2.3" (from Bundle-Version)
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
StreamArtifactResourceResolver
,ArtifactResourceResolver
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_NAME
The configuration property name for specifying attribute names in the MANIFEST file to extract the artifact ID.static java.lang.String
DEFAULT_ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_VALUE
Default property value for attribute names used to extract the artifact ID from the MANIFEST file.static int
DEFAULT_PRIORITY
Default priority value for the ManifestArtifactResourceResolver.static java.lang.String
DEFAULT_VERSION_ATTRIBUTE_NAMES_PROPERTY_VALUE
Default property value for attribute names used to extract the artifact version from the MANIFEST file.static java.lang.String
VERSION_ATTRIBUTE_NAMES_PROPERTY_NAME
The configuration property name for specifying attribute names in the MANIFEST file to extract the artifact version.-
Fields inherited from class io.microsphere.classloading.AbstractArtifactResourceResolver
classLoader, logger, priority
-
Fields inherited from interface io.microsphere.lang.Prioritized
COMPARATOR, MAX_PRIORITY, MIN_PRIORITY, NORMAL_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description ManifestArtifactResourceResolver()
ManifestArtifactResourceResolver(int priority)
ManifestArtifactResourceResolver(java.lang.ClassLoader classLoader, int priority)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
isArtifactMetadata(java.lang.String relativePath)
protected Artifact
resolve(java.net.URL resourceURL, java.io.InputStream artifactMetadataData, java.lang.ClassLoader classLoader)
-
Methods inherited from class io.microsphere.classloading.StreamArtifactResourceResolver
findArtifactMetadata, findArtifactMetadataEntry, isArtifactMetadataEntry, isArtifactMetadataFile, readArtifactMetadataDataFromArchiveFile, readArtifactMetadataDataFromDirectory, readArtifactMetadataDataFromFile, readArtifactMetadataDataFromResource, resolve
-
Methods inherited from class io.microsphere.classloading.AbstractArtifactResourceResolver
getPriority, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.microsphere.lang.Prioritized
compareTo
-
-
-
-
Field Detail
-
DEFAULT_ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_VALUE
public static final java.lang.String DEFAULT_ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_VALUE
Default property value for attribute names used to extract the artifact ID from the MANIFEST file. The attributes are searched in order and the first non-null value is used as the artifact ID.The default attribute names are:
- Bundle-Name - typically used in OSGi environments
- Automatic-Module-Name - used for Java 9+ module systems
- Implementation-Title - standard JAR manifest attribute
- See Also:
- Constant Field Values
-
DEFAULT_VERSION_ATTRIBUTE_NAMES_PROPERTY_VALUE
public static final java.lang.String DEFAULT_VERSION_ATTRIBUTE_NAMES_PROPERTY_VALUE
Default property value for attribute names used to extract the artifact version from the MANIFEST file. The attributes are searched in order and the first non-null value is used as the artifact version.The default attribute names are:
- Bundle-Version - typically used in OSGi environments
- Implementation-Version - standard JAR manifest attribute
- See Also:
- Constant Field Values
-
ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_NAME
@ConfigurationProperty(type=java.lang.String[][].class, defaultValue="Bundle-Name,Automatic-Module-Name,Implementation-Title", description="The attribute names in the \'META-INF/MANIFEST\' resource are retrieved as the artifact id") public static final java.lang.String ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_NAME
The configuration property name for specifying attribute names in the MANIFEST file to extract the artifact ID.This property allows users to customize which manifest attributes should be used to determine the artifact ID. By default, it uses the values defined in
DEFAULT_ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_VALUE
.Example Usage
-Dmicrosphere.artifact-id.manifest-attribute-names=Custom-Name,Implementation-Title
- See Also:
- Constant Field Values
-
VERSION_ATTRIBUTE_NAMES_PROPERTY_NAME
@ConfigurationProperty(type=java.lang.String[][].class, defaultValue="Bundle-Version,Implementation-Version", description="The attribute names in the \'META-INF/MANIFEST\' resource are retrieved as the artifact version") public static final java.lang.String VERSION_ATTRIBUTE_NAMES_PROPERTY_NAME
The configuration property name for specifying attribute names in the MANIFEST file to extract the artifact version.This property allows users to customize which manifest attributes should be used to determine the artifact version. By default, it uses the values defined in
DEFAULT_VERSION_ATTRIBUTE_NAMES_PROPERTY_VALUE
.Example Usage
-Dmicrosphere.artifact-version.manifest-attribute-names=Custom-Version,Implementation-Version
- See Also:
- Constant Field Values
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
Default priority value for the ManifestArtifactResourceResolver. This priority determines the order in which this resolver is used compared to others. Lower values indicate higher priority.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ManifestArtifactResourceResolver
public ManifestArtifactResourceResolver()
-
ManifestArtifactResourceResolver
public ManifestArtifactResourceResolver(int priority)
-
ManifestArtifactResourceResolver
public ManifestArtifactResourceResolver(java.lang.ClassLoader classLoader, int priority)
-
-
Method Detail
-
isArtifactMetadata
protected boolean isArtifactMetadata(java.lang.String relativePath)
- Specified by:
isArtifactMetadata
in classStreamArtifactResourceResolver
-
resolve
protected Artifact resolve(java.net.URL resourceURL, java.io.InputStream artifactMetadataData, java.lang.ClassLoader classLoader) throws java.io.IOException
- Specified by:
resolve
in classStreamArtifactResourceResolver
- Throws:
java.io.IOException
-
-