Package io.microsphere.classloading
Class MavenArtifactResourceResolver
- java.lang.Object
-
- io.microsphere.classloading.AbstractArtifactResourceResolver
-
- io.microsphere.classloading.StreamArtifactResourceResolver
-
- io.microsphere.classloading.MavenArtifactResourceResolver
-
- All Implemented Interfaces:
ArtifactResourceResolver
,Prioritized
,java.lang.Comparable<Prioritized>
public class MavenArtifactResourceResolver extends StreamArtifactResourceResolver
A resolver implementation for Maven artifact metadata, extracting information from Maven POM properties files.This class extends the
StreamArtifactResourceResolver
, which provides a base for resolving artifacts by reading metadata from streams (either from archives or directly from resources). This resolver specifically targets Maven-style artifacts where metadata is stored in "pom.properties" files under the "META-INF/maven/" directory.How It Works
- The resolver checks if a given resource path matches the pattern of a Maven POM properties file using the
isArtifactMetadata(String)
method. The pattern is typically:META-INF/maven/<groupId>/<artifactId>/pom.properties
. - If a match is found, it reads the properties file via the
resolve(URL, InputStream, ClassLoader)
method and extracts key metadata: groupId, artifactId, and version. - It then constructs an
Artifact
object using these properties and associates it with the original URL.
Example Usage
// Create a resolver with default priority MavenArtifactResourceResolver resolver = new MavenArtifactResourceResolver(); // Resolve artifact metadata from a JAR that contains META-INF/maven/org.example/my-artifact/pom.properties URL resourceURL = new URL("jar:file:/path/to/your-artifact.jar!/some/path"); Artifact artifact = resolver.resolve(resourceURL); if (artifact != null) { System.out.println("Resolved Artifact:"); System.out.println("Group ID: " + artifact.getGroupId()); System.out.println("Artifact ID: " + artifact.getArtifactId()); System.out.println("Version: " + artifact.getVersion()); }
Customization
You may extend this class to customize how artifact metadata is resolved or how the resulting artifact object is constructed. For example, you could override the following methods:
isArtifactMetadata(String)
– to support custom metadata paths.resolveArtifactMetaInfoInMavenPomProperties(Properties, URL)
– to add additional logic when parsing the POM properties or to enrich the resulting artifact.
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
Artifact
,StreamArtifactResourceResolver
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ARTIFACT_ID_PROPERTY_NAME
static int
DEFAULT_PRIORITY
static java.lang.String
GROUP_ID_PROPERTY_NAME
static java.lang.String
MAVEN_POM_PROPERTIES_RESOURCE_PREFIX
static java.lang.String
MAVEN_POM_PROPERTIES_RESOURCE_SUFFIX
static java.lang.String
VERSION_PROPERTY_NAME
-
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 MavenArtifactResourceResolver()
MavenArtifactResourceResolver(int priority)
MavenArtifactResourceResolver(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
-
MAVEN_POM_PROPERTIES_RESOURCE_PREFIX
public static final java.lang.String MAVEN_POM_PROPERTIES_RESOURCE_PREFIX
- See Also:
- Constant Field Values
-
MAVEN_POM_PROPERTIES_RESOURCE_SUFFIX
public static final java.lang.String MAVEN_POM_PROPERTIES_RESOURCE_SUFFIX
- See Also:
- Constant Field Values
-
GROUP_ID_PROPERTY_NAME
public static final java.lang.String GROUP_ID_PROPERTY_NAME
- See Also:
- Constant Field Values
-
ARTIFACT_ID_PROPERTY_NAME
public static final java.lang.String ARTIFACT_ID_PROPERTY_NAME
- See Also:
- Constant Field Values
-
VERSION_PROPERTY_NAME
public static final java.lang.String VERSION_PROPERTY_NAME
- See Also:
- Constant Field Values
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
- See Also:
- Constant Field Values
-
-
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
-
-