Class MavenDependencyResolverService
- java.lang.Object
-
- jadex.platform.service.dependency.maven.MavenDependencyResolverService
-
- All Implemented Interfaces:
IDependencyService
public class MavenDependencyResolverService extends java.lang.Object implements IDependencyService
Handler for retrieving dependency information from maven artifacts.
-
-
Field Summary
Fields Modifier and Type Field Description protected IComponentIdentifiercidThe component identifier to use for creating local resource IDs.protected IInternalAccesscomponentThe service providing component.protected java.util.logging.LoggerloggerThe logger.protected java.util.List<org.sonatype.aether.repository.RemoteRepository>repositoriesRemote repositories as specified in settings.protected org.apache.maven.repository.internal.MavenRepositorySystemSessionsessionThe shared repository system session.protected org.sonatype.aether.RepositorySystemsystemAccess to the aether repository system.
-
Constructor Summary
Constructors Constructor Description MavenDependencyResolverService()Bean constructor for service creation.MavenDependencyResolverService(IComponentIdentifier cid)Constructor for testing
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.io.FilefindBasedir(java.io.File dir)Find the base directorystatic java.lang.StringgetCoordinates(java.lang.String groupid, java.lang.String id, java.lang.String version)Get the coordinates (global identifier) for an artifact.IFuture<IResourceIdentifier>getResourceIdentifier(java.net.URL url)Get the resource identifier for a url.static java.net.URLgetUrl(java.io.File file)Get the URL for a file.protected voidinit()Initialize maven and aether repository system.IFuture<Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>>loadDependencies(IResourceIdentifier rid, boolean workspace)Load dependencies from a resource identifier.protected IResourceIdentifierloadDependencies(IResourceIdentifier rid, java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>> rids, boolean workspace)Load dependencies from a resource identifier.protected IResourceIdentifierloadDependenciesWithAether(IResourceIdentifier rid, java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>> rids)Load dependencies using aether repository access only, because no other context information (e.g. workspace) is available.protected org.apache.maven.model.ModelloadModelSource(java.net.URL url)Find the model source (i.e.protected org.apache.maven.model.ModelloadPom(org.apache.maven.model.building.ModelSource pom)Load a POM from a source.protected voidprocessAetherDependencies(IResourceIdentifier rid, java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>> rids, org.sonatype.aether.graph.DependencyNode node)Recursively process the dependency graph produced by aether.IFuture<java.lang.Void>startService()Start the service.
-
-
-
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.ExceptionInitialize 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:
loadDependenciesin interfaceIDependencyService- 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:
getResourceIdentifierin interfaceIDependencyService- 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').
-
-