Class DependencyNode


  • public class DependencyNode
    extends java.lang.Object
    Represents 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 int INCLUDED
      State that represents an included dependency node.
      static int OMITTED_FOR_CONFLICT
      State that represents a dependency node that has been omitted for conflicting with another dependency node.
      static int OMITTED_FOR_CYCLE
      State that represents a dependency node that has been omitted for introducing a cycle into the dependency tree.
      static int OMITTED_FOR_DUPLICATE
      State 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
      boolean accept​(DependencyNodeVisitor visitor)
      Applies the specified dependency node visitor to this dependency node and its children.
      void addChild​(DependencyNode child)
      Adds the specified dependency node to this dependency node's children.
      boolean equals​(java.lang.Object object)  
      org.apache.maven.artifact.Artifact getArtifact()
      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.
      int getDepth()
      Deprecated.
      As of 1.1, depth is computed by node hierarchy.
      java.lang.String getFailedUpdateScope()
      Gets the scope that this node's artifact was attempted to be updated to due to conflicts.
      java.lang.String getOriginalScope()
      Gets the scope of this node's artifact before it was updated due to conflicts.
      DependencyNode getParent()
      Gets the parent dependency node of this dependency node.
      java.lang.String getPremanagedScope()
      Gets the scope of this node's artifact before it was updated by dependency management.
      java.lang.String getPremanagedVersion()
      Gets the version of this node's artifact before it was updated by dependency management.
      org.apache.maven.artifact.Artifact getRelatedArtifact()
      Gets the artifact related to the state of this dependency node.
      int getState()
      Gets the state of this dependency node.
      org.apache.maven.artifact.versioning.VersionRange getVersionSelectedFromRange()
      If the version was selected from a range this method will return the range.
      boolean hasChildren()  
      int hashCode()
      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.
      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.
      void omitForCycle()
      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.
      void removeChild​(DependencyNode child)
      Removes the specified dependency node from this dependency node's children.
      void setAvailableVersions​(java.util.List<org.apache.maven.artifact.versioning.ArtifactVersion> availableVersions)  
      void setFailedUpdateScope​(java.lang.String failedUpdateScope)
      Sets the scope that this node's artifact was attempted to be updated to due to conflicts.
      void setOriginalScope​(java.lang.String originalScope)
      Sets the scope of this node's artifact before it was updated due to conflicts.
      void setPremanagedScope​(java.lang.String premanagedScope)
      Sets the scope of this node's artifact before it was updated by dependency management.
      void setPremanagedVersion​(java.lang.String premanagedVersion)
      Sets the version of this node's artifact before it was updated by dependency management.
      void setVersionSelectedFromRange​(org.apache.maven.artifact.versioning.VersionRange versionSelectedFromRange)  
      java.lang.String toNodeString()
      Returns a string representation of this dependency node.
      java.lang.String toString()
      Returns a string representation of this dependency node and its children.
      java.lang.String toString​(int indentDepth)
      Deprecated.
      As of 1.1, replaced by toString()
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 node
        state - the state of the new dependency node. This can be either INCLUDED or OMITTED_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 node
        state - the state of the new dependency node. This can be either INCLUDED, OMITTED_FOR_DUPLICATE, OMITTED_FOR_CONFLICT or OMITTED_FOR_CYCLE.
        relatedArtifact - the artifact related to the state of this dependency node. For dependency nodes with a state of OMITTED_FOR_DUPLICATE or OMITTED_FOR_CONFLICT, this represents the artifact that was conflicted with. For dependency nodes of other states, this should always be null.
        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_CONFLICT or OMITTED_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 of OMITTED_FOR_CONFLICT, this represents the artifact that was conflicted with. For dependency nodes of other states, this is always null.
        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 null if 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, or null if 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 null if 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, or null if 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 null if 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, or null if 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 null if 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, or null if 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 null if 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, or null if 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 to OMITTED_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 not INCLUDED
        java.lang.IllegalArgumentException - if the related artifact was null or 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_CYCLE and removes all of its children.

        Throws:
        java.lang.IllegalStateException - if this dependency node's state is not INCLUDED
        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 by toString()
        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:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a string representation of this dependency node and its children.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
        See Also:
        toNodeString(), Object.toString()