org.jvnet.maven.plugin.antrun
Class DependencyGraph

java.lang.Object
  extended by org.jvnet.maven.plugin.antrun.DependencyGraph

public final class DependencyGraph
extends Object

Graph of dependencies among Maven artifacts.

This graph, which consists of interconnected DependencyGraph.Nodes and DependencyGraph.Edges, represents a complete dependency graph rooted at the given Maven module. The constructor recursively parses all POMs for the dependency and builds this information.

For example, if you have 4 modules A,B,C, and D that has the dependencies among them as follows:

 A->B,C
 B->D
 C->D
 

Then if you construct a graph from 'A', you'll get a graph of four nodes (each representing maven module A,B,C, and D) and four edges (each representing dependencies among them.)

Once constructed, a graph is accessible in several ways:

Author:
Kohsuke Kawaguchi

Nested Class Summary
static class DependencyGraph.Edge
           
static class DependencyGraph.Node
          Node, which represents an artifact.
 
Constructor Summary
DependencyGraph(org.apache.maven.artifact.Artifact root, boolean tolerateBrokenPOMs)
          Creates a full dependency graph with the given artifact at the top.
DependencyGraph(org.apache.maven.project.MavenProject root, boolean tolerateBrokenPOMs)
          Creates a full dependency graph with the given project at the top.
 
Method Summary
 void accept(GraphVisitor visitor)
          Accepts the visitor.
 boolean contains(DependencyGraph.Node node)
          Checks if the graph contains the given node.
 DependencyGraph createSubGraph(DependencyGraph.Node root)
          Creates a full subgraph rooted at the given node.
 DependencyGraph createSubGraph(DependencyGraph.Node root, Collection<DependencyGraph.Node> nodes)
          Creates a sub-graph from the given set of nodes (which must be subset of nodes in the current graph) with all edges { (u,v) | u \in nodes, v \in nodes }
 DependencyGraph createSubGraph(DependencyGraph.Node node, GraphVisitor visitor)
          Visits the graph started at the given node, and creates a sub-graph from visited nodes and edges.
 DependencyGraph createSubGraph(GraphVisitor visitor)
          Accepts the visitor and invoke its visitor methods to create a sub-graph.
 Collection<DependencyGraph.Node> getAllNodes()
          Returns all nodes in this graph.
 DependencyGraph.Node getRoot()
          Gets the root node.
 boolean isEmpty()
          Returns true if the graph contains nothing at all.
 DependencyGraph.Node toNode(org.apache.maven.artifact.Artifact a)
          Gets the associated DependencyGraph.Node, or null if none exists.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DependencyGraph

public DependencyGraph(org.apache.maven.artifact.Artifact root,
                       boolean tolerateBrokenPOMs)
                throws org.apache.maven.project.ProjectBuildingException,
                       org.apache.maven.artifact.resolver.ArtifactResolutionException,
                       org.apache.maven.artifact.resolver.ArtifactNotFoundException
Creates a full dependency graph with the given artifact at the top.

Throws:
org.apache.maven.project.ProjectBuildingException
org.apache.maven.artifact.resolver.ArtifactResolutionException
org.apache.maven.artifact.resolver.ArtifactNotFoundException

DependencyGraph

public DependencyGraph(org.apache.maven.project.MavenProject root,
                       boolean tolerateBrokenPOMs)
                throws org.apache.maven.project.ProjectBuildingException,
                       org.apache.maven.artifact.resolver.ArtifactResolutionException,
                       org.apache.maven.artifact.resolver.ArtifactNotFoundException
Creates a full dependency graph with the given project at the top.

Throws:
org.apache.maven.project.ProjectBuildingException
org.apache.maven.artifact.resolver.ArtifactResolutionException
org.apache.maven.artifact.resolver.ArtifactNotFoundException
Method Detail

getRoot

public DependencyGraph.Node getRoot()
Gets the root node.

This is non-null unless this graph is empty.


isEmpty

public boolean isEmpty()
Returns true if the graph contains nothing at all.


getAllNodes

public Collection<DependencyGraph.Node> getAllNodes()
Returns all nodes in this graph.


contains

public boolean contains(DependencyGraph.Node node)
Checks if the graph contains the given node.


toNode

public DependencyGraph.Node toNode(org.apache.maven.artifact.Artifact a)
                            throws org.apache.maven.project.ProjectBuildingException,
                                   org.apache.maven.artifact.resolver.ArtifactResolutionException,
                                   org.apache.maven.artifact.resolver.ArtifactNotFoundException
Gets the associated DependencyGraph.Node, or null if none exists.

Throws:
org.apache.maven.project.ProjectBuildingException
org.apache.maven.artifact.resolver.ArtifactResolutionException
org.apache.maven.artifact.resolver.ArtifactNotFoundException

createSubGraph

public DependencyGraph createSubGraph(GraphVisitor visitor)
Accepts the visitor and invoke its visitor methods to create a sub-graph.

This method is convenient for obtaining a sub-graph of dependencies by filtering out nodes/edges. For example, to obtain all the transitive dependencies that exclude provided/test dependencies, you can do:

 createSubgraph(new ScopeFilter("compile","runtime"))
 

Returns:
A sub-graph of this graph that consists of nodes and edges for which the visitor returns true. Can be an empty graph, but never null.

accept

public void accept(GraphVisitor visitor)
Accepts the visitor. Simply an alias for createSubGraph(GraphVisitor).


createSubGraph

public DependencyGraph createSubGraph(DependencyGraph.Node root)
Creates a full subgraph rooted at the given node.


createSubGraph

public DependencyGraph createSubGraph(DependencyGraph.Node node,
                                      GraphVisitor visitor)
Visits the graph started at the given node, and creates a sub-graph from visited nodes and edges.

This is the slightly generalized version of createSubGraph(GraphVisitor)


createSubGraph

public DependencyGraph createSubGraph(DependencyGraph.Node root,
                                      Collection<DependencyGraph.Node> nodes)
Creates a sub-graph from the given set of nodes (which must be subset of nodes in the current graph) with all edges { (u,v) | u \in nodes, v \in nodes }


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.