Class ArtifactDetector


  • public class ArtifactDetector
    extends java.lang.Object
    The ArtifactDetector class is responsible for detecting and resolving artifacts from the classpath. It uses a list of registered ArtifactResourceResolver implementations to resolve each URL in the classpath into an appropriate Artifact instance.

    ArtifactDetector supports filtering out JDK internal libraries based on the configuration flag provided during detection. It also allows customization through different ArtifactResourceResolver implementations 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 ArtifactResourceResolver implementation 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
    • 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArtifactDetector

        public ArtifactDetector()
      • ArtifactDetector

        public ArtifactDetector​(@Nullable
                                java.lang.ClassLoader classLoader)