Class DependencyNode
- java.lang.Object
-
- org.apache.maven.shared.dependency.tree.DependencyNode
-
public class DependencyNode extends java.lang.ObjectRepresents an artifact node within a Maven project's dependency tree.- Version:
- $Id: DependencyNode.java 1595871 2014-05-19 12:38:45Z jvanzyl $
- Author:
- Edwin Punzalan, Mark Hobson
-
-
Field Summary
Fields Modifier and Type Field Description static intINCLUDEDState that represents an included dependency node.static intOMITTED_FOR_CONFLICTState that represents a dependency node that has been omitted for conflicting with another dependency node.static intOMITTED_FOR_CYCLEState that represents a dependency node that has been omitted for introducing a cycle into the dependency tree.static intOMITTED_FOR_DUPLICATEState that represents a dependency node that has been omitted for duplicating another dependency node.
-
Constructor Summary
Constructors Constructor Description DependencyNode(org.apache.maven.artifact.Artifact artifact)Creates a new dependency node for the specified artifact with an included state.DependencyNode(org.apache.maven.artifact.Artifact artifact, int state)Creates a new dependency node for the specified artifact with the specified state.DependencyNode(org.apache.maven.artifact.Artifact artifact, int state, org.apache.maven.artifact.Artifact relatedArtifact)Creates a new dependency node for the specified artifact with the specified state and related artifact.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaccept(DependencyNodeVisitor visitor)Applies the specified dependency node visitor to this dependency node and its children.voidaddChild(DependencyNode child)Adds the specified dependency node to this dependency node's children.booleanequals(java.lang.Object object)org.apache.maven.artifact.ArtifactgetArtifact()Gets the artifact attached to this dependency node.java.util.List<org.apache.maven.artifact.versioning.ArtifactVersion>getAvailableVersions()If the version was selected from a range this method will return the available versions when making the decision.java.util.List<DependencyNode>getChildren()Gets the list of child dependency nodes of this dependency node.intgetDepth()Deprecated.As of 1.1, depth is computed by node hierarchy.java.lang.StringgetFailedUpdateScope()Gets the scope that this node's artifact was attempted to be updated to due to conflicts.java.lang.StringgetOriginalScope()Gets the scope of this node's artifact before it was updated due to conflicts.DependencyNodegetParent()Gets the parent dependency node of this dependency node.java.lang.StringgetPremanagedScope()Gets the scope of this node's artifact before it was updated by dependency management.java.lang.StringgetPremanagedVersion()Gets the version of this node's artifact before it was updated by dependency management.org.apache.maven.artifact.ArtifactgetRelatedArtifact()Gets the artifact related to the state of this dependency node.intgetState()Gets the state of this dependency node.org.apache.maven.artifact.versioning.VersionRangegetVersionSelectedFromRange()If the version was selected from a range this method will return the range.booleanhasChildren()inthashCode()java.util.Iterator<DependencyNode>inverseIterator()Gets an iterator that returns this dependency node and it's children in postorder traversal.java.util.Iterator<DependencyNode>iterator()Gets an iterator that returns this dependency node and it's children in preorder traversal.voidomitForConflict(org.apache.maven.artifact.Artifact relatedArtifact)Changes the state of this dependency node to be omitted for conflict or duplication, depending on the specified related artifact.voidomitForCycle()Changes the state of this dependency node to be omitted for a cycle in the dependency tree.java.util.Iterator<DependencyNode>preorderIterator()Gets an iterator that returns this dependency node and it's children in preorder traversal.voidremoveChild(DependencyNode child)Removes the specified dependency node from this dependency node's children.voidsetAvailableVersions(java.util.List<org.apache.maven.artifact.versioning.ArtifactVersion> availableVersions)voidsetFailedUpdateScope(java.lang.String failedUpdateScope)Sets the scope that this node's artifact was attempted to be updated to due to conflicts.voidsetOriginalScope(java.lang.String originalScope)Sets the scope of this node's artifact before it was updated due to conflicts.voidsetPremanagedScope(java.lang.String premanagedScope)Sets the scope of this node's artifact before it was updated by dependency management.voidsetPremanagedVersion(java.lang.String premanagedVersion)Sets the version of this node's artifact before it was updated by dependency management.voidsetVersionSelectedFromRange(org.apache.maven.artifact.versioning.VersionRange versionSelectedFromRange)java.lang.StringtoNodeString()Returns a string representation of this dependency node.java.lang.StringtoString()Returns a string representation of this dependency node and its children.java.lang.StringtoString(int indentDepth)Deprecated.As of 1.1, replaced bytoString()
-
-
-
Field Detail
-
INCLUDED
public static final int INCLUDED
State that represents an included dependency node.- Since:
- 1.1
- See Also:
- Constant Field Values
-
OMITTED_FOR_DUPLICATE
public static final int OMITTED_FOR_DUPLICATE
State that represents a dependency node that has been omitted for duplicating another dependency node.- Since:
- 1.1
- See Also:
- Constant Field Values
-
OMITTED_FOR_CONFLICT
public static final int OMITTED_FOR_CONFLICT
State that represents a dependency node that has been omitted for conflicting with another dependency node.- Since:
- 1.1
- See Also:
- Constant Field Values
-
OMITTED_FOR_CYCLE
public static final int OMITTED_FOR_CYCLE
State that represents a dependency node that has been omitted for introducing a cycle into the dependency tree.- Since:
- 1.1
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DependencyNode
public DependencyNode(org.apache.maven.artifact.Artifact artifact)
Creates a new dependency node for the specified artifact with an included state.- Parameters:
artifact- the artifact attached to the new dependency node- Throws:
java.lang.IllegalArgumentException- if the parameter constraints were violated- Since:
- 1.1
-
DependencyNode
public DependencyNode(org.apache.maven.artifact.Artifact artifact, int state)Creates a new dependency node for the specified artifact with the specified state.- Parameters:
artifact- the artifact attached to the new dependency nodestate- the state of the new dependency node. This can be eitherINCLUDEDorOMITTED_FOR_CYCLE.- Throws:
java.lang.IllegalArgumentException- if the parameter constraints were violated- Since:
- 1.1
-
DependencyNode
public DependencyNode(org.apache.maven.artifact.Artifact artifact, int state, org.apache.maven.artifact.Artifact relatedArtifact)Creates a new dependency node for the specified artifact with the specified state and related artifact.- Parameters:
artifact- the artifact attached to the new dependency nodestate- the state of the new dependency node. This can be eitherINCLUDED,OMITTED_FOR_DUPLICATE,OMITTED_FOR_CONFLICTorOMITTED_FOR_CYCLE.relatedArtifact- the artifact related to the state of this dependency node. For dependency nodes with a state ofOMITTED_FOR_DUPLICATEorOMITTED_FOR_CONFLICT, this represents the artifact that was conflicted with. For dependency nodes of other states, this should always benull.- Throws:
java.lang.IllegalArgumentException- if the parameter constraints were violated- Since:
- 1.1
-
-
Method Detail
-
accept
public boolean accept(DependencyNodeVisitor visitor)
Applies the specified dependency node visitor to this dependency node and its children.- Parameters:
visitor- the dependency node visitor to use- Returns:
- the visitor result of ending the visit to this node
- Since:
- 1.1
-
addChild
public void addChild(DependencyNode child)
Adds the specified dependency node to this dependency node's children.- Parameters:
child- the child dependency node to add- Since:
- 1.1
-
removeChild
public void removeChild(DependencyNode child)
Removes the specified dependency node from this dependency node's children.- Parameters:
child- the child dependency node to remove- Since:
- 1.1
-
getParent
public DependencyNode getParent()
Gets the parent dependency node of this dependency node.- Returns:
- the parent dependency node
-
getArtifact
public org.apache.maven.artifact.Artifact getArtifact()
Gets the artifact attached to this dependency node.- Returns:
- the artifact
-
getDepth
public int getDepth()
Deprecated.As of 1.1, depth is computed by node hierarchy. With the introduction of node visitors and filters this method can give misleading results. For example, consider serializing a tree with a filter using a visitor: this method would return the unfiltered depth of a node, whereas the correct depth would be calculated by the visitor.Gets the depth of this dependency node within its hierarchy.- Returns:
- the depth
-
getChildren
public java.util.List<DependencyNode> getChildren()
Gets the list of child dependency nodes of this dependency node.- Returns:
- the list of child dependency nodes
-
hasChildren
public boolean hasChildren()
-
getState
public int getState()
Gets the state of this dependency node.- Returns:
- the state: either
INCLUDED,OMITTED_FOR_DUPLICATE,OMITTED_FOR_CONFLICTorOMITTED_FOR_CYCLE. - Since:
- 1.1
-
getRelatedArtifact
public org.apache.maven.artifact.Artifact getRelatedArtifact()
Gets the artifact related to the state of this dependency node. For dependency nodes with a state ofOMITTED_FOR_CONFLICT, this represents the artifact that was conflicted with. For dependency nodes of other states, this is alwaysnull.- Returns:
- the related artifact
- Since:
- 1.1
-
getOriginalScope
public java.lang.String getOriginalScope()
Gets the scope of this node's artifact before it was updated due to conflicts.- Returns:
- the original scope, or
nullif the artifact scope has not been updated - Since:
- 1.1
-
setOriginalScope
public void setOriginalScope(java.lang.String originalScope)
Sets the scope of this node's artifact before it was updated due to conflicts.- Parameters:
originalScope- the original scope, ornullif the artifact scope has not been updated- Since:
- 1.1
-
getFailedUpdateScope
public java.lang.String getFailedUpdateScope()
Gets the scope that this node's artifact was attempted to be updated to due to conflicts.- Returns:
- the failed update scope, or
nullif the artifact scope has not failed being updated - Since:
- 1.1
-
setFailedUpdateScope
public void setFailedUpdateScope(java.lang.String failedUpdateScope)
Sets the scope that this node's artifact was attempted to be updated to due to conflicts.- Parameters:
failedUpdateScope- the failed update scope, ornullif the artifact scope has not failed being updated- Since:
- 1.1
-
getPremanagedVersion
public java.lang.String getPremanagedVersion()
Gets the version of this node's artifact before it was updated by dependency management.- Returns:
- the premanaged version, or
nullif the artifact version has not been managed - Since:
- 1.1
-
setPremanagedVersion
public void setPremanagedVersion(java.lang.String premanagedVersion)
Sets the version of this node's artifact before it was updated by dependency management.- Parameters:
premanagedVersion- the premanaged version, ornullif the artifact version has not been managed- Since:
- 1.1
-
getPremanagedScope
public java.lang.String getPremanagedScope()
Gets the scope of this node's artifact before it was updated by dependency management.- Returns:
- the premanaged scope, or
nullif the artifact scope has not been managed - Since:
- 1.1
-
setPremanagedScope
public void setPremanagedScope(java.lang.String premanagedScope)
Sets the scope of this node's artifact before it was updated by dependency management.- Parameters:
premanagedScope- the premanaged scope, ornullif the artifact scope has not been managed- Since:
- 1.1
-
getVersionSelectedFromRange
public org.apache.maven.artifact.versioning.VersionRange getVersionSelectedFromRange()
If the version was selected from a range this method will return the range.- Returns:
- the version range before a version was selected, or
nullif the artifact had a explicit version. - Since:
- 1.2
-
setVersionSelectedFromRange
public void setVersionSelectedFromRange(org.apache.maven.artifact.versioning.VersionRange versionSelectedFromRange)
-
getAvailableVersions
public java.util.List<org.apache.maven.artifact.versioning.ArtifactVersion> getAvailableVersions()
If the version was selected from a range this method will return the available versions when making the decision.- Returns:
List<String> the versions available when a version was selected from a range, ornullif the artifact had a explicit version.- Since:
- 1.2
-
setAvailableVersions
public void setAvailableVersions(java.util.List<org.apache.maven.artifact.versioning.ArtifactVersion> availableVersions)
-
omitForConflict
public void omitForConflict(org.apache.maven.artifact.Artifact relatedArtifact)
Changes the state of this dependency node to be omitted for conflict or duplication, depending on the specified related artifact.If the related artifact has a version equal to this dependency node's artifact, then this dependency node's state is changed to
OMITTED_FOR_DUPLICATE, otherwise it is changed toOMITTED_FOR_CONFLICT. Omitting this dependency node also removes all of its children.- Parameters:
relatedArtifact- the artifact that this dependency node conflicted with- Throws:
java.lang.IllegalStateException- if this dependency node's state is notINCLUDEDjava.lang.IllegalArgumentException- if the related artifact wasnullor had a different dependency conflict id to this dependency node's artifact- Since:
- 1.1
- See Also:
OMITTED_FOR_DUPLICATE,OMITTED_FOR_CONFLICT
-
omitForCycle
public void omitForCycle()
Changes the state of this dependency node to be omitted for a cycle in the dependency tree.Omitting this node sets its state to
OMITTED_FOR_CYCLEand removes all of its children.- Throws:
java.lang.IllegalStateException- if this dependency node's state is notINCLUDED- Since:
- 1.1
- See Also:
OMITTED_FOR_CYCLE
-
iterator
public java.util.Iterator<DependencyNode> iterator()
Gets an iterator that returns this dependency node and it's children in preorder traversal.- Returns:
- the preorder traversal iterator
- See Also:
preorderIterator()
-
preorderIterator
public java.util.Iterator<DependencyNode> preorderIterator()
Gets an iterator that returns this dependency node and it's children in preorder traversal.- Returns:
- the preorder traversal iterator
- See Also:
DependencyTreePreorderIterator
-
inverseIterator
public java.util.Iterator<DependencyNode> inverseIterator()
Gets an iterator that returns this dependency node and it's children in postorder traversal.- Returns:
- the postorder traversal iterator
- See Also:
DependencyTreeInverseIterator
-
toNodeString
public java.lang.String toNodeString()
Returns a string representation of this dependency node.- Returns:
- the string representation
- Since:
- 1.1
- See Also:
toString()
-
toString
public java.lang.String toString(int indentDepth)
Deprecated.As of 1.1, replaced bytoString()Returns a string representation of this dependency node and its children, indented to the specified depth.As of 1.1, this method ignores the indentation depth and simply delegates to
toString().- Parameters:
indentDepth- the indentation depth- Returns:
- the string representation
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string representation of this dependency node and its children.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation
- See Also:
toNodeString(),Object.toString()
-
-