Class ResolveEngine
- java.lang.Object
-
- org.apache.ivy.core.resolve.ResolveEngine
-
public class ResolveEngine extends java.lang.ObjectThe resolve engine which is the core of the dependency resolution mechanism used in Ivy. It features several resolve methods, some very simple, likeresolve(File)andresolve(URL)which allow to simply resolve dependencies of a single module descriptor, or more complete one, like theresolve(ModuleDescriptor, ResolveOptions)which allows to provide options to the resolution engine.- See Also:
ResolveOptions
-
-
Field Summary
Fields Modifier and Type Field Description private DependencyResolverdictatorResolverprivate EventManagereventManagerprivate ResolveEngineSettingssettingsprivate SortEnginesortEngine
-
Constructor Summary
Constructors Constructor Description ResolveEngine(ResolveEngineSettings settings, EventManager eventManager, SortEngine sortEngine)Constructs a ResolveEngine.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancheckConflictSolvedEvicted(VisitNode node, VisitNode ancestor)private booleancheckConflictSolvedSelected(VisitNode node, VisitNode ancestor)private voidcheckInterrupted()private java.util.Collection<IvyNode>computeConflicts(VisitNode node, VisitNode ancestor, java.lang.String conf, java.util.Collection<IvyNode> toevict, java.util.Collection<IvyNode> selectedNodes)Compute possible conflicts for a node, in the context of an ancestor (a node which has a dependency - direct or indirect - on the node for which conflicts should be computed.private voiddoFetchDependencies(VisitNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet)ArtifactDownloadReportdownload(ArtifactOrigin origin, DownloadOptions options)Materialize an artifact already located.ArtifactDownloadReportdownload(Artifact artifact, DownloadOptions options)Download an artifact to the cache.voiddownloadArtifacts(ResolveReport report, Filter<Artifact> artifactFilter, DownloadOptions options)private voidfetchDependencies(VisitNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet, boolean shouldBePublic)ResolvedModuleRevisionfindModule(ModuleRevisionId id, ResolveOptions options)IvyNode[]getDependencies(java.net.URL ivySource, ResolveOptions options)Resolve the dependencies of a module without downloading corresponding artifacts.IvyNode[]getDependencies(ModuleDescriptor md, ResolveOptions options, ResolveReport report)Resolve the dependencies of a module without downloading corresponding artifacts.private java.lang.StringgetDependenciesFetchedKey(IvyNode node, java.lang.String conf)DependencyResolvergetDictatorResolver()Returns the currently configured dictator resolver, which when non null is used in place of any specified resolver in theIvySettingsEventManagergetEventManager()ResolveEngineSettingsgetSettings()SortEnginegetSortEngine()private voidhandleTransitiveEviction(ModuleDescriptor md, java.lang.String[] confs, ResolveData data, java.util.List<IvyNode> sortedDependencies)private booleanisDependenciesFetched(IvyNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet)Returns true if we've already fetched the dependencies for this node and configurationArtifactOriginlocate(Artifact artifact)Locates an artifact in dependency resolvers, and return its location if it can be located and actually exists, or an unknownArtifactOriginin other cases.private voidmarkDependenciesFetched(IvyNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet)DependencyDescriptormediate(DependencyDescriptor dd, ResolveOptions options)Mediates the given dependency descriptor according to given options.voidoutputReport(ResolveReport report, ResolutionCacheManager cacheMgr, ResolveOptions options)ResolveReportresolve(java.io.File ivySource)ResolveReportresolve(java.net.URL ivySource)ResolveReportresolve(java.net.URL ivySource, ResolveOptions options)Resolve dependencies of a module described by an ivy file.ResolveReportresolve(ModuleDescriptor md, ResolveOptions options)Resolve dependencies of a module described by a module descriptor.ResolveReportresolve(ModuleRevisionId mrid, ResolveOptions options, boolean changing)Resolves the module identified by the given mrid with its dependencies if transitive is set to true.private voidresolveConflict(VisitNode node, java.lang.String conf)private booleanresolveConflict(VisitNode node, VisitNode ancestor, java.lang.String conf, java.util.Collection<IvyNode> toevict)Resolves conflict for the given node in the given ancestor.private java.util.Collection<IvyNode>resolveConflicts(VisitNode node, VisitNode ancestor, java.util.Collection<IvyNode> conflicts, ConflictManager conflictManager)voidsetDictatorResolver(DependencyResolver dictatorResolver)Sets a dictator resolver, which is used in place of regular dependency resolver for subsequent dependency resolution by this engine.
-
-
-
Field Detail
-
settings
private ResolveEngineSettings settings
-
eventManager
private EventManager eventManager
-
sortEngine
private SortEngine sortEngine
-
dictatorResolver
private DependencyResolver dictatorResolver
-
-
Constructor Detail
-
ResolveEngine
public ResolveEngine(ResolveEngineSettings settings, EventManager eventManager, SortEngine sortEngine)
Constructs a ResolveEngine.- Parameters:
settings- the settings to use to configure the engine. Must not be null.eventManager- the event manager to use to send events about the resolution process. Must not be null.sortEngine- the sort engine to use to sort modules before producing the dependency resolution report. Must not be null.
-
-
Method Detail
-
getDictatorResolver
public DependencyResolver getDictatorResolver()
Returns the currently configured dictator resolver, which when non null is used in place of any specified resolver in theIvySettings- Returns:
- the currently configured dictator resolver, may be null.
-
setDictatorResolver
public void setDictatorResolver(DependencyResolver dictatorResolver)
Sets a dictator resolver, which is used in place of regular dependency resolver for subsequent dependency resolution by this engine.- Parameters:
dictatorResolver- the dictator resolver to use in this engine, null if regular settings should used
-
resolve
public ResolveReport resolve(java.io.File ivySource) throws java.text.ParseException, java.io.IOException
- Throws:
java.text.ParseExceptionjava.io.IOException
-
resolve
public ResolveReport resolve(java.net.URL ivySource) throws java.text.ParseException, java.io.IOException
- Throws:
java.text.ParseExceptionjava.io.IOException
-
resolve
public ResolveReport resolve(ModuleRevisionId mrid, ResolveOptions options, boolean changing) throws java.text.ParseException, java.io.IOException
Resolves the module identified by the given mrid with its dependencies if transitive is set to true.- Parameters:
mrid- ModuleRevisionIdoptions- ResolveOptionschanging- boolean- Returns:
- ResolveReport
- Throws:
java.text.ParseException- if something goes wrongjava.io.IOException- if something goes wrong
-
resolve
public ResolveReport resolve(java.net.URL ivySource, ResolveOptions options) throws java.text.ParseException, java.io.IOException
Resolve dependencies of a module described by an ivy file.- Parameters:
ivySource- URLoptions- ResolveOptions- Returns:
- ResolveReport
- Throws:
java.text.ParseException- if something goes wrongjava.io.IOException- if something goes wrong
-
resolve
public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options) throws java.text.ParseException, java.io.IOException
Resolve dependencies of a module described by a module descriptor.- Parameters:
md- ModuleDescriptoroptions- ResolveOptions- Returns:
- ResolveReport
- Throws:
java.text.ParseException- if something goes wrongjava.io.IOException- if something goes wrong
-
outputReport
public void outputReport(ResolveReport report, ResolutionCacheManager cacheMgr, ResolveOptions options) throws java.io.IOException
- Throws:
java.io.IOException
-
downloadArtifacts
public void downloadArtifacts(ResolveReport report, Filter<Artifact> artifactFilter, DownloadOptions options)
-
download
public ArtifactDownloadReport download(Artifact artifact, DownloadOptions options)
Download an artifact to the cache. Not used internally, useful especially for IDE plugins needing to download artifact one by one (for source or javadoc artifact, for instance).Downloaded artifact file can be accessed using
ArtifactDownloadReport.getLocalFile().It is possible to track the progression of the download using classical ivy progress monitoring feature (see addTransferListener).
- Parameters:
artifact- the artifact to downloadoptions- DownloadOptions- Returns:
- a report concerning the download
- See Also:
download(ArtifactOrigin, DownloadOptions)
-
locate
public ArtifactOrigin locate(Artifact artifact)
Locates an artifact in dependency resolvers, and return its location if it can be located and actually exists, or an unknownArtifactOriginin other cases.- Parameters:
artifact- the artifact to locate.- Returns:
- the artifact location, should be tested with
ArtifactOrigin.isUnknown(ArtifactOrigin)to check if the artifact has actually been located.
-
download
public ArtifactDownloadReport download(ArtifactOrigin origin, DownloadOptions options)
Materialize an artifact already located.Not used internally, useful especially for IDE plugins needing to download artifact one by one (for source or javadoc artifact, for instance).
Materialized artifact file can be accessed using
ArtifactDownloadReport.getLocalFile().It is possible to track the progression of the download using classical ivy progress monitoring feature (see addTransferListener).
- Parameters:
origin- the artifact origin to materializeoptions- DownloadOptions- Returns:
- a report concerning the download
- See Also:
download(Artifact, DownloadOptions),locate(Artifact)
-
getDependencies
public IvyNode[] getDependencies(java.net.URL ivySource, ResolveOptions options) throws java.text.ParseException, java.io.IOException
Resolve the dependencies of a module without downloading corresponding artifacts. The module to resolve is given by its ivy file URL. This method requires appropriate configuration of the ivy instance, especially resolvers.- Parameters:
ivySource- url of the ivy file to use for dependency resolvingoptions- ditto- Returns:
- an array of the resolved dependencies
- Throws:
java.text.ParseException- if a parsing problem occurred in the ivy filejava.io.IOException- if an IO problem was raised during ivy file parsing
-
getDependencies
public IvyNode[] getDependencies(ModuleDescriptor md, ResolveOptions options, ResolveReport report)
Resolve the dependencies of a module without downloading corresponding artifacts. The module to resolve is given by its module descriptor. This method requires appropriate configuration of the ivy instance, especially resolvers.The
IvyNodes are ordered from the most dependent to the less dependent, so that an IvyNode is always found in the list after all IvyNode depending directly on it.- Parameters:
md- the descriptor of the module for which we want to get dependencies - must not be nulloptions- the resolve options to use to resolve the dependenciesreport- a resolve report to fill during resolution - may be null- Returns:
- an array of the resolved Dependencies
-
handleTransitiveEviction
private void handleTransitiveEviction(ModuleDescriptor md, java.lang.String[] confs, ResolveData data, java.util.List<IvyNode> sortedDependencies)
-
fetchDependencies
private void fetchDependencies(VisitNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet, boolean shouldBePublic)
-
doFetchDependencies
private void doFetchDependencies(VisitNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet)
-
isDependenciesFetched
private boolean isDependenciesFetched(IvyNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet)
Returns true if we've already fetched the dependencies for this node and configuration- Parameters:
node- node to checkconf- configuration to check- Returns:
- true if we've already fetched this dependency
-
markDependenciesFetched
private void markDependenciesFetched(IvyNode node, java.lang.String conf, java.util.Set<java.lang.String> fetchedSet)
-
getDependenciesFetchedKey
private java.lang.String getDependenciesFetchedKey(IvyNode node, java.lang.String conf)
-
resolveConflict
private void resolveConflict(VisitNode node, java.lang.String conf)
-
resolveConflict
private boolean resolveConflict(VisitNode node, VisitNode ancestor, java.lang.String conf, java.util.Collection<IvyNode> toevict)
Resolves conflict for the given node in the given ancestor. This method do conflict resolution in ancestor parents recursively, unless not necessary.- Parameters:
node- the node for which conflict resolution should be doneancestor- the ancestor in which the conflict resolution should be doneconf- Stringtoevict- a collection of IvyNode to evict (as computed by conflict resolution in descendants of ancestor)- Returns:
- true if conflict resolution has been done, false it can't be done yet
-
resolveConflicts
private java.util.Collection<IvyNode> resolveConflicts(VisitNode node, VisitNode ancestor, java.util.Collection<IvyNode> conflicts, ConflictManager conflictManager)
-
computeConflicts
private java.util.Collection<IvyNode> computeConflicts(VisitNode node, VisitNode ancestor, java.lang.String conf, java.util.Collection<IvyNode> toevict, java.util.Collection<IvyNode> selectedNodes)
Compute possible conflicts for a node, in the context of an ancestor (a node which has a dependency - direct or indirect - on the node for which conflicts should be computed.- Parameters:
node- the node for which conflicts should be computedancestor- the ancestor in which conflicts should be computedconf- the configuration of the node in which conflicts should be computedtoevict- a collection of nodes which have been evicted during conflict resolution at lower level. It may be empty if no conflict resolution has occurred for this node yet, or if no node has been evicted.selectedNodes- a collection of nodes selected during previous conflict resolution for the given node and ancestor. This collection is updated by this call, removing nodes which should be evicted.- Returns:
- a collection of IvyNode which may be in conflict with the given node in the given ancestor. This collection always contain at least the given node.
-
checkConflictSolvedSelected
private boolean checkConflictSolvedSelected(VisitNode node, VisitNode ancestor)
-
checkConflictSolvedEvicted
private boolean checkConflictSolvedEvicted(VisitNode node, VisitNode ancestor)
-
findModule
public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options)
-
mediate
public DependencyDescriptor mediate(DependencyDescriptor dd, ResolveOptions options)
Mediates the given dependency descriptor according to given options.The mediated dependency descriptor must return the actually requested module revision id when the method
DependencyDescriptor.getDependencyRevisionId()is called.- Parameters:
dd- the dependency descriptor for which the requested module revision id should be returnedoptions- the resolve options to use- Returns:
- the mediated
DependencyDescriptor.
-
getEventManager
public EventManager getEventManager()
-
getSettings
public ResolveEngineSettings getSettings()
-
getSortEngine
public SortEngine getSortEngine()
-
checkInterrupted
private void checkInterrupted()
-
-