org.apache.maven.shared.dependency.tree
Class DependencyNode

java.lang.Object
  extended by org.apache.maven.shared.dependency.tree.DependencyNode

public class DependencyNode
extends Object

Represents an artifact node within a Maven project's dependency tree.

Version:
$Id: DependencyNode.java 1100703 2011-05-08 08:27:33Z hboutemy $
Author:
Edwin Punzalan, Mark Hobson

Field Summary
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
DependencyNode(Artifact artifact)
          Creates a new dependency node for the specified artifact with an included state.
DependencyNode(Artifact artifact, int state)
          Creates a new dependency node for the specified artifact with the specified state.
DependencyNode(Artifact artifact, int state, Artifact relatedArtifact)
          Creates a new dependency node for the specified artifact with the specified state and related artifact.
 
Method Summary
 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(Object object)
           
 Artifact getArtifact()
          Gets the artifact attached to this dependency node.
 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.
 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. 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.
 String getFailedUpdateScope()
          Gets the scope that this node's artifact was attempted to be updated to due to conflicts.
 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.
 String getPremanagedScope()
          Gets the scope of this node's artifact before it was updated by dependency management.
 String getPremanagedVersion()
          Gets the version of this node's artifact before it was updated by dependency management.
 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()
          
 Iterator<DependencyNode> inverseIterator()
          Gets an iterator that returns this dependency node and it's children in postorder traversal.
 Iterator<DependencyNode> iterator()
          Gets an iterator that returns this dependency node and it's children in preorder traversal.
 void omitForConflict(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.
 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(List<org.apache.maven.artifact.versioning.ArtifactVersion> availableVersions)
           
 void setFailedUpdateScope(String failedUpdateScope)
          Sets the scope that this node's artifact was attempted to be updated to due to conflicts.
 void setOriginalScope(String originalScope)
          Sets the scope of this node's artifact before it was updated due to conflicts.
 void setPremanagedScope(String premanagedScope)
          Sets the scope of this node's artifact before it was updated by dependency management.
 void setPremanagedVersion(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)
           
 String toNodeString()
          Returns a string representation of this dependency node.
 String toString()
          Returns a string representation of this dependency node and its children.
 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(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:
IllegalArgumentException - if the parameter constraints were violated
Since:
1.1

DependencyNode

public DependencyNode(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:
IllegalArgumentException - if the parameter constraints were violated
Since:
1.1

DependencyNode

public DependencyNode(Artifact artifact,
                      int state,
                      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:
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 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 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 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 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(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 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(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 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(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 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(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 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(List<org.apache.maven.artifact.versioning.ArtifactVersion> availableVersions)

omitForConflict

public void omitForConflict(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:
IllegalStateException - if this dependency node's state is not INCLUDED
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:
IllegalStateException - if this dependency node's state is not INCLUDED
Since:
1.1
See Also:
OMITTED_FOR_CYCLE

iterator

public 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 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 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 String toNodeString()
Returns a string representation of this dependency node.

Returns:
the string representation
Since:
1.1
See Also:
toString()

toString

public 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 Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object

toString

public String toString()
Returns a string representation of this dependency node and its children.

Overrides:
toString in class Object
Returns:
the string representation
See Also:
toNodeString(), Object.toString()


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.