Class 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 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
    • Constructor Detail

      • MavenArtifactResourceResolver

        public MavenArtifactResourceResolver()
      • MavenArtifactResourceResolver

        public MavenArtifactResourceResolver​(int priority)
      • MavenArtifactResourceResolver

        public MavenArtifactResourceResolver​(java.lang.ClassLoader classLoader,
                                             int priority)