public final class DependencyGraph extends Object
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:
the root node and traverse through edges like
DependencyGraph.Node.getForwardEdges(DependencyGraph).
createSubGraph(GraphVisitor) and obtain a sub-graph that matches the given
criteria.
| Modifier and Type | Class and Description |
|---|---|
static class |
DependencyGraph.Edge |
static class |
DependencyGraph.Node
Node, which represents an artifact.
|
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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() |
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
org.apache.maven.project.ProjectBuildingExceptionorg.apache.maven.artifact.resolver.ArtifactResolutionExceptionorg.apache.maven.artifact.resolver.ArtifactNotFoundExceptionpublic 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
org.apache.maven.project.ProjectBuildingExceptionorg.apache.maven.artifact.resolver.ArtifactResolutionExceptionorg.apache.maven.artifact.resolver.ArtifactNotFoundExceptionpublic DependencyGraph.Node getRoot()
This is non-null unless this graph is empty.
public boolean isEmpty()
public Collection<DependencyGraph.Node> getAllNodes()
public boolean contains(DependencyGraph.Node node)
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
DependencyGraph.Node, or null if none exists.org.apache.maven.project.ProjectBuildingExceptionorg.apache.maven.artifact.resolver.ArtifactResolutionExceptionorg.apache.maven.artifact.resolver.ArtifactNotFoundExceptionpublic DependencyGraph createSubGraph(GraphVisitor visitor)
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"))
public void accept(GraphVisitor visitor)
createSubGraph(GraphVisitor).public DependencyGraph createSubGraph(DependencyGraph.Node root)
public DependencyGraph createSubGraph(DependencyGraph.Node node, GraphVisitor visitor)
This is the slightly generalized version of createSubGraph(GraphVisitor)
public DependencyGraph createSubGraph(DependencyGraph.Node root, Collection<DependencyGraph.Node> nodes)
Copyright © 2014. All rights reserved.