Package io.microsphere.classloading
Class ArtifactDetector
- java.lang.Object
-
- io.microsphere.classloading.ArtifactDetector
-
public class ArtifactDetector extends java.lang.ObjectTheArtifactDetectorclass is responsible for detecting and resolving artifacts from the classpath. It uses a list of registeredArtifactResourceResolverimplementations to resolve each URL in the classpath into an appropriateArtifactinstance.ArtifactDetectorsupports filtering out JDK internal libraries based on the configuration flag provided during detection. It also allows customization through differentArtifactResourceResolverimplementations that can be loaded via service loading mechanism.Example Usage
// Create an instance using the default ClassLoader ArtifactDetector detector = new ArtifactDetector(); // Detect all artifacts including JDK libraries List<Artifact> artifactsIncludingJDK = detector.detect(true); // Detect artifacts excluding JDK libraries List<Artifact> artifactsExcludingJDK = detector.detect(false);You can also provide a custom
ArtifactResourceResolverimplementation like below:public class CustomArtifactResolver implements ArtifactResourceResolver { public Artifact resolve(URL resourceURL) { if (resourceURL.getProtocol().equals("file")) { return new FileArtifact(resourceURL); // hypothetical custom artifact } return null; } public int getPriority() { return Prioritized.MAX_PRIORITY; // highest priority } }Once registered via service loader or manually added, it will be used by the detector accordingly.
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
Artifact,ArtifactResourceResolver,Prioritized
-
-
Constructor Summary
Constructors Constructor Description ArtifactDetector()ArtifactDetector(java.lang.ClassLoader classLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Artifact>detect()java.util.List<Artifact>detect(boolean includedJdkLibraries)protected java.util.List<Artifact>detect(java.util.Set<java.net.URL> classPathURLs)protected java.util.Set<java.net.URL>getClassPathURLs(boolean includedJdkLibraries)
-
-
-
Constructor Detail
-
ArtifactDetector
public ArtifactDetector()
-
ArtifactDetector
public ArtifactDetector(@Nullable java.lang.ClassLoader classLoader)
-
-
Method Detail
-
detect
@Nonnull @Immutable public java.util.List<Artifact> detect()
-
detect
@Nonnull @Immutable public java.util.List<Artifact> detect(boolean includedJdkLibraries)
-
detect
@Nonnull @Immutable protected java.util.List<Artifact> detect(java.util.Set<java.net.URL> classPathURLs)
-
getClassPathURLs
protected java.util.Set<java.net.URL> getClassPathURLs(boolean includedJdkLibraries)
-
-