Class MavenDependencyResolverService

  • All Implemented Interfaces:
    IDependencyService

    public class MavenDependencyResolverService
    extends java.lang.Object
    implements IDependencyService
    Handler for retrieving dependency information from maven artifacts.
    • Field Detail

      • component

        protected IInternalAccess component
        The service providing component.
      • logger

        protected java.util.logging.Logger logger
        The logger.
      • cid

        protected IComponentIdentifier cid
        The component identifier to use for creating local resource IDs. The assumption is that URLs are only valid on the local platform.
      • system

        protected org.sonatype.aether.RepositorySystem system
        Access to the aether repository system.
      • session

        protected org.apache.maven.repository.internal.MavenRepositorySystemSession session
        The shared repository system session.
      • repositories

        protected java.util.List<org.sonatype.aether.repository.RemoteRepository> repositories
        Remote repositories as specified in settings.
    • Constructor Detail

      • MavenDependencyResolverService

        public MavenDependencyResolverService()
        Bean constructor for service creation.
      • MavenDependencyResolverService

        public MavenDependencyResolverService​(IComponentIdentifier cid)
                                       throws java.lang.Exception
        Constructor for testing
        Throws:
        java.lang.Exception
    • Method Detail

      • startService

        public IFuture<java.lang.Void> startService()
        Start the service.
      • init

        protected void init()
                     throws java.lang.Exception
        Initialize maven and aether repository system.
        Throws:
        java.lang.Exception
      • loadDependencies

        public IFuture<Tuple2<IResourceIdentifier,​java.util.Map<IResourceIdentifier,​java.util.List<IResourceIdentifier>>>> loadDependencies​(IResourceIdentifier rid,
                                                                                                                                                        boolean workspace)
        Load dependencies from a resource identifier.
        Specified by:
        loadDependencies in interface IDependencyService
        Parameters:
        rid - A local or global resource identifier. If both local and global ids are present, local takes precedence, e.g. resolving to workspace urls before fetching an older snapshot from a repository.
        Returns:
        A map containing the dependencies as mapping (parent RID -> list of children RIDs).
      • getResourceIdentifier

        public IFuture<IResourceIdentifier> getResourceIdentifier​(java.net.URL url)
        Get the resource identifier for a url.
        Specified by:
        getResourceIdentifier in interface IDependencyService
        Parameters:
        url - The url.
        Returns:
        The resource identifier including local RID and potentially global RID if available.
      • loadDependencies

        protected IResourceIdentifier loadDependencies​(IResourceIdentifier rid,
                                                       java.util.Map<IResourceIdentifier,​java.util.List<IResourceIdentifier>> rids,
                                                       boolean workspace)
                                                throws java.lang.Exception
        Load dependencies from a resource identifier.
        Parameters:
        rid - A local or global resource identifier. If both local and global ids are present, local takes precedence, e.g. resolving to workspace urls before fetching an older snapshot from a repository.
        rids - A map for inserting the dependencies as mapping (parent RID -> list of children RIDs).
        Throws:
        java.lang.Exception
      • loadDependenciesWithAether

        protected IResourceIdentifier loadDependenciesWithAether​(IResourceIdentifier rid,
                                                                 java.util.Map<IResourceIdentifier,​java.util.List<IResourceIdentifier>> rids)
                                                          throws java.lang.Exception
        Load dependencies using aether repository access only, because no other context information (e.g. workspace) is available.
        Parameters:
        rid - The resource identifier containing only a global resource id.
        rids - A map for inserting the dependencies as mapping (parent RID -> list of children RIDs).
        Throws:
        java.lang.Exception
      • processAetherDependencies

        protected void processAetherDependencies​(IResourceIdentifier rid,
                                                 java.util.Map<IResourceIdentifier,​java.util.List<IResourceIdentifier>> rids,
                                                 org.sonatype.aether.graph.DependencyNode node)
                                          throws java.lang.Exception
        Recursively process the dependency graph produced by aether.
        Parameters:
        rid - The resource identifier containing only a global resource id.
        rids - A map for inserting the dependencies as mapping (parent RID -> list of children RIDs).
        node - The dependency node.
        Throws:
        java.lang.Exception
      • loadPom

        protected org.apache.maven.model.Model loadPom​(org.apache.maven.model.building.ModelSource pom)
        Load a POM from a source.
        Parameters:
        pom - The source.
        Returns:
        The loaded model.
      • loadModelSource

        protected org.apache.maven.model.Model loadModelSource​(java.net.URL url)
        Find the model source (i.e. POM location) for a URL.
        Parameters:
        url - The url to a maven artifact (e.g. jar or classes directory).
      • findBasedir

        protected static java.io.File findBasedir​(java.io.File dir)
        Find the base directory
        Parameters:
        uri -
        Returns:
      • getUrl

        public static java.net.URL getUrl​(java.io.File file)
        Get the URL for a file.
        Parameters:
        file - The file.
        Returns:
        The file
      • getCoordinates

        public static java.lang.String getCoordinates​(java.lang.String groupid,
                                                      java.lang.String id,
                                                      java.lang.String version)
        Get the coordinates (global identifier) for an artifact.
        Parameters:
        groupid - The group identifier.
        id - The artifact id.
        version - The artifact version.
        Returns:
        The coordinates as string ('groupid:id:version').