Package io.microsphere.classloading
Class ArchiveFileArtifactResourceResolver
- java.lang.Object
-
- io.microsphere.classloading.AbstractArtifactResourceResolver
-
- io.microsphere.classloading.ArchiveFileArtifactResourceResolver
-
- All Implemented Interfaces:
ArtifactResourceResolver
,Prioritized
,java.lang.Comparable<Prioritized>
public class ArchiveFileArtifactResourceResolver extends AbstractArtifactResourceResolver
A concrete implementation ofArtifactResourceResolver
that resolves artifacts based on archive files.ArchiveFileArtifactResourceResolver
interprets the naming convention of archive files to extract artifact metadata such asartifactId
andversion
. The resolver expects file names to follow a specific format:[artifactId]-[version].[extension]
, where only theartifactId
is mandatory.Resolution Logic
- If the given URL points to a directory or cannot be resolved to a valid archive file, resolution fails.
- The filename is parsed using hyphen (
'-'
) as the delimiter between artifact ID and version. - If no hyphen is found, only the artifact ID will be extracted, and the version will be set to null.
Example Usages
// Example 1: With both artifactId and version URL url = new File("my-artifact-1.0.0.jar").toURI().toURL(); Artifact artifact = resolver.resolve(url); System.out.println(artifact.getArtifactId()); // Outputs: "my-artifact" System.out.println(artifact.getVersion()); // Outputs: "1.0.0" // Example 2: With only artifactId URL url = new File("my-artifact.jar").toURI().toURL(); Artifact artifact = resolver.resolve(url); System.out.println(artifact.getArtifactId()); // Outputs: "my-artifact" System.out.println(artifact.getVersion()); // Outputs: null
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
AbstractArtifactResourceResolver
,ArtifactResourceResolver
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PRIORITY
-
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 ArchiveFileArtifactResourceResolver()
ArchiveFileArtifactResourceResolver(int priority)
ArchiveFileArtifactResourceResolver(java.lang.ClassLoader classLoader, int priority)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Artifact
resolve(java.net.URL resourceURL)
Resolve an instanceArtifact
fromthe resource
of artifact.-
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_PRIORITY
public static final int DEFAULT_PRIORITY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ArchiveFileArtifactResourceResolver
public ArchiveFileArtifactResourceResolver()
-
ArchiveFileArtifactResourceResolver
public ArchiveFileArtifactResourceResolver(int priority)
-
ArchiveFileArtifactResourceResolver
public ArchiveFileArtifactResourceResolver(java.lang.ClassLoader classLoader, int priority)
-
-
Method Detail
-
resolve
public Artifact resolve(java.net.URL resourceURL)
Description copied from interface:ArtifactResourceResolver
Resolve an instanceArtifact
fromthe resource
of artifact.- Parameters:
resourceURL
-the resource
of artifact, it may the archive file or the directory- Returns:
- an instance
Artifact
if found, otherwisenull
-
-