Class ClassLoaderResolver

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ClassLoaderResolver
    extends java.lang.Object
    implements java.io.Closeable
    A resolver that transforms a Maven coordinate into a class loader that can view the dependencies implied by this coordinate.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<MavenCoordinate,​java.lang.ClassLoader> classLoaders
      A mapping of Maven coordinates to already existing class loaders.
      private org.apache.maven.plugin.logging.Log log
      The Maven log dispatcher.
      private java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories
      A list of remote repositories available.
      private org.eclipse.aether.RepositorySystem repositorySystem
      The repository system to use.
      private org.eclipse.aether.RepositorySystemSession repositorySystemSession
      The repository system session to use.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassLoaderResolver​(org.apache.maven.plugin.logging.Log log, org.eclipse.aether.RepositorySystem repositorySystem, org.eclipse.aether.RepositorySystemSession repositorySystemSession, java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories)
      Creates a new class loader resolver.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      private java.lang.ClassLoader doResolve​(MavenCoordinate mavenCoordinate)
      Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
      java.lang.ClassLoader resolve​(MavenCoordinate mavenCoordinate)
      Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
      • Methods inherited from class java.lang.Object

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

      • log

        private final org.apache.maven.plugin.logging.Log log
        The Maven log dispatcher.
      • repositorySystem

        private final org.eclipse.aether.RepositorySystem repositorySystem
        The repository system to use.
      • repositorySystemSession

        private final org.eclipse.aether.RepositorySystemSession repositorySystemSession
        The repository system session to use.
      • remoteRepositories

        private final java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories
        A list of remote repositories available.
      • classLoaders

        private final java.util.Map<MavenCoordinate,​java.lang.ClassLoader> classLoaders
        A mapping of Maven coordinates to already existing class loaders.
    • Constructor Detail

      • ClassLoaderResolver

        public ClassLoaderResolver​(org.apache.maven.plugin.logging.Log log,
                                   org.eclipse.aether.RepositorySystem repositorySystem,
                                   org.eclipse.aether.RepositorySystemSession repositorySystemSession,
                                   java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories)
        Creates a new class loader resolver.
        Parameters:
        log - The Maven log dispatcher.
        repositorySystem - The repository system to use.
        repositorySystemSession - The repository system session to use.
        remoteRepositories - A list of remote repositories available.
    • Method Detail

      • resolve

        public java.lang.ClassLoader resolve​(MavenCoordinate mavenCoordinate)
                                      throws org.apache.maven.plugin.MojoFailureException,
                                             org.apache.maven.plugin.MojoExecutionException
        Resolves a Maven coordinate to a class loader that can load all of the coordinates classes. If a Maven coordinate was resolved previously, the previously created class loader is returned.
        Parameters:
        mavenCoordinate - The Maven coordinate to resolve.
        Returns:
        A class loader that references all of the class loader's dependencies and which is a child of this class's class loader.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If the user configuration results in an error.
        org.apache.maven.plugin.MojoFailureException - If the plugin application raises an error.
      • doResolve

        private java.lang.ClassLoader doResolve​(MavenCoordinate mavenCoordinate)
                                         throws org.apache.maven.plugin.MojoExecutionException,
                                                org.apache.maven.plugin.MojoFailureException
        Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
        Parameters:
        mavenCoordinate - The Maven coordinate to resolve.
        Returns:
        A class loader that references all of the class loader's dependencies and which is a child of this class's class loader.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If the user configuration results in an error.
        org.apache.maven.plugin.MojoFailureException - If the plugin application raises an error.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException