Class ConflictResolver
- java.lang.Object
-
- org.eclipse.aether.util.graph.transformer.ConflictResolver
-
- All Implemented Interfaces:
DependencyGraphTransformer
public final class ConflictResolver extends java.lang.Object implements DependencyGraphTransformer
A dependency graph transformer that resolves version and scope conflicts among dependencies. For a given set of conflicting nodes, one node will be chosen as the winner and the other nodes are removed from the dependency graph. The exact rules by which a winning node and its effective scope are determined are controlled by user-supplied implementations ofConflictResolver.VersionSelector,ConflictResolver.ScopeSelector,ConflictResolver.OptionalitySelectorandConflictResolver.ScopeDeriver.By default, this graph transformer will turn the dependency graph into a tree without duplicate artifacts. Using the configuration property
CONFIG_PROP_VERBOSE, a verbose mode can be enabled where the graph is still turned into a tree but all nodes participating in a conflict are retained. The nodes that were rejected during conflict resolution have no children and link back to the winner node via theNODE_DATA_WINNERkey in their custom data. Additionally, the keysNODE_DATA_ORIGINAL_SCOPEandNODE_DATA_ORIGINAL_OPTIONALITYare used to store the original scope and optionality of each node. Obviously, the resulting dependency tree is not suitable for artifact resolution unless a filter is employed to exclude the duplicate dependencies.This transformer will query the keys
TransformationContextKeys.CONFLICT_IDS,TransformationContextKeys.SORTED_CONFLICT_IDS,TransformationContextKeys.CYCLIC_CONFLICT_IDSfor existing information about conflict ids. In absence of this information, it will automatically invoke theConflictIdSorterto calculate it.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConflictResolver.ConflictContextA context used to hold information that is relevant for resolving version and scope conflicts.static classConflictResolver.ConflictItemA conflicting dependency.(package private) static classConflictResolver.NodeInfostatic classConflictResolver.OptionalitySelectorAn extension point ofConflictResolverthat determines the effective optional flag of a dependency from a potentially conflicting set of derived optionalities.static classConflictResolver.ScopeContextA context used to hold information that is relevant for deriving the scope of a child dependency.static classConflictResolver.ScopeDeriverAn extension point ofConflictResolverthat determines the scope of a dependency in relation to the scope of its parent.static classConflictResolver.ScopeSelectorAn extension point ofConflictResolverthat determines the effective scope of a dependency from a potentially conflicting set ofderived scopes.(package private) classConflictResolver.Statestatic classConflictResolver.VersionSelectorAn extension point ofConflictResolverthat determines the winner among conflicting dependencies.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONFIG_PROP_VERBOSEThe key in the repository session'sconfiguration propertiesused to store aBooleanflag controlling the transformer's verbose mode.static java.lang.StringNODE_DATA_ORIGINAL_OPTIONALITYThe key in the dependency node'scustom dataunder which the optional flag of the dependency before derivation and conflict resolution is stored.static java.lang.StringNODE_DATA_ORIGINAL_SCOPEThe key in the dependency node'scustom dataunder which the scope of the dependency before scope derivation and conflict resolution is stored.static java.lang.StringNODE_DATA_WINNERThe key in the dependency node'scustom dataunder which a reference to theDependencyNodewhich has won the conflict is stored.private ConflictResolver.OptionalitySelectoroptionalitySelectorprivate ConflictResolver.ScopeDeriverscopeDeriverprivate ConflictResolver.ScopeSelectorscopeSelectorprivate ConflictResolver.VersionSelectorversionSelector
-
Constructor Summary
Constructors Constructor Description ConflictResolver(ConflictResolver.VersionSelector versionSelector, ConflictResolver.ScopeSelector scopeSelector, ConflictResolver.OptionalitySelector optionalitySelector, ConflictResolver.ScopeDeriver scopeDeriver)Creates a new conflict resolver instance with the specified hooks.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleangatherConflictItems(DependencyNode node, ConflictResolver.State state)private voidremoveLosers(ConflictResolver.State state)DependencyNodetransformGraph(DependencyNode node, DependencyGraphTransformationContext context)Transforms the dependency graph denoted by the specified root node.
-
-
-
Field Detail
-
CONFIG_PROP_VERBOSE
public static final java.lang.String CONFIG_PROP_VERBOSE
The key in the repository session'sconfiguration propertiesused to store aBooleanflag controlling the transformer's verbose mode.- See Also:
- Constant Field Values
-
NODE_DATA_WINNER
public static final java.lang.String NODE_DATA_WINNER
The key in the dependency node'scustom dataunder which a reference to theDependencyNodewhich has won the conflict is stored.- See Also:
- Constant Field Values
-
NODE_DATA_ORIGINAL_SCOPE
public static final java.lang.String NODE_DATA_ORIGINAL_SCOPE
The key in the dependency node'scustom dataunder which the scope of the dependency before scope derivation and conflict resolution is stored.- See Also:
- Constant Field Values
-
NODE_DATA_ORIGINAL_OPTIONALITY
public static final java.lang.String NODE_DATA_ORIGINAL_OPTIONALITY
The key in the dependency node'scustom dataunder which the optional flag of the dependency before derivation and conflict resolution is stored.- See Also:
- Constant Field Values
-
versionSelector
private final ConflictResolver.VersionSelector versionSelector
-
scopeSelector
private final ConflictResolver.ScopeSelector scopeSelector
-
scopeDeriver
private final ConflictResolver.ScopeDeriver scopeDeriver
-
optionalitySelector
private final ConflictResolver.OptionalitySelector optionalitySelector
-
-
Constructor Detail
-
ConflictResolver
public ConflictResolver(ConflictResolver.VersionSelector versionSelector, ConflictResolver.ScopeSelector scopeSelector, ConflictResolver.OptionalitySelector optionalitySelector, ConflictResolver.ScopeDeriver scopeDeriver)
Creates a new conflict resolver instance with the specified hooks.- Parameters:
versionSelector- The version selector to use, must not benull.scopeSelector- The scope selector to use, must not benull.optionalitySelector- The optionality selector ot use, must not benull.scopeDeriver- The scope deriver to use, must not benull.
-
-
Method Detail
-
transformGraph
public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException
Description copied from interface:DependencyGraphTransformerTransforms the dependency graph denoted by the specified root node. The transformer may directly change the provided input graph or create a new graph, the former is recommended for performance reasons.- Specified by:
transformGraphin interfaceDependencyGraphTransformer- Parameters:
node- The root node of the (possibly cyclic!) graph to transform, must not benull.context- The graph transformation context, must not benull.- Returns:
- The result graph of the transformation, never
null. - Throws:
RepositoryException- If the transformation failed.
-
gatherConflictItems
private boolean gatherConflictItems(DependencyNode node, ConflictResolver.State state) throws RepositoryException
- Throws:
RepositoryException
-
removeLosers
private void removeLosers(ConflictResolver.State state)
-
-