Class JsonDependencyNodeVisitor
- java.lang.Object
-
- org.apache.maven.plugins.dependency.tree.AbstractSerializingVisitor
-
- org.apache.maven.plugins.dependency.tree.JsonDependencyNodeVisitor
-
- All Implemented Interfaces:
org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor
public class JsonDependencyNodeVisitor extends AbstractSerializingVisitor implements org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor
A dependency node visitor that serializes visited nodes to a writer using the JSON format.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
indentChar
-
Fields inherited from class org.apache.maven.plugins.dependency.tree.AbstractSerializingVisitor
writer
-
-
Constructor Summary
Constructors Constructor Description JsonDependencyNodeVisitor(java.io.Writer writer)
Creates a new instance ofJsonDependencyNodeVisitor
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendKeyValue(java.lang.StringBuilder sb, int indent, java.lang.String key, java.lang.String value)
Appends a key value pair to the string builder.private void
appendKeyWithoutComma(java.lang.StringBuilder sb, int indent, java.lang.String key, java.lang.String value)
Appends a key value pair to the string builder without a comma at the end.private void
appendNodeValues(java.lang.StringBuilder sb, int indent, org.apache.maven.artifact.Artifact artifact, boolean hasChildren)
Appends the artifact values to the string builder.boolean
endVisit(org.apache.maven.shared.dependency.graph.DependencyNode node)
private java.lang.String
indent(int indent)
Returns a string ofindentChar
for the indent level.boolean
visit(org.apache.maven.shared.dependency.graph.DependencyNode node)
private void
writeChildren(int indent, org.apache.maven.shared.dependency.graph.DependencyNode node, java.lang.StringBuilder sb, java.util.Set<org.apache.maven.shared.dependency.graph.DependencyNode> visited)
Writes the children of the node to the string builder.private void
writeNode(int indent, org.apache.maven.shared.dependency.graph.DependencyNode node, java.lang.StringBuilder sb, java.util.Set<org.apache.maven.shared.dependency.graph.DependencyNode> visited)
Appends the node and its children to the string builder.private void
writeRootNode(org.apache.maven.shared.dependency.graph.DependencyNode node)
Writes the node to the writer.
-
-
-
Constructor Detail
-
JsonDependencyNodeVisitor
public JsonDependencyNodeVisitor(java.io.Writer writer)
Creates a new instance ofJsonDependencyNodeVisitor
. The writer will be used to write the output.- Parameters:
writer
- the writer to write to
-
-
Method Detail
-
visit
public boolean visit(org.apache.maven.shared.dependency.graph.DependencyNode node)
- Specified by:
visit
in interfaceorg.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor
-
writeRootNode
private void writeRootNode(org.apache.maven.shared.dependency.graph.DependencyNode node)
Writes the node to the writer. This method is recursive and will write all children nodes.- Parameters:
node
- the node to write
-
writeNode
private void writeNode(int indent, org.apache.maven.shared.dependency.graph.DependencyNode node, java.lang.StringBuilder sb, java.util.Set<org.apache.maven.shared.dependency.graph.DependencyNode> visited)
Appends the node and its children to the string builder.- Parameters:
indent
- the current indent levelnode
- the node to writesb
- the string builder to append to
-
writeChildren
private void writeChildren(int indent, org.apache.maven.shared.dependency.graph.DependencyNode node, java.lang.StringBuilder sb, java.util.Set<org.apache.maven.shared.dependency.graph.DependencyNode> visited)
Writes the children of the node to the string builder. And each children of each node will be written recursively.- Parameters:
indent
- the current indent levelnode
- the node to writesb
- the string builder to append to
-
endVisit
public boolean endVisit(org.apache.maven.shared.dependency.graph.DependencyNode node)
- Specified by:
endVisit
in interfaceorg.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor
-
appendNodeValues
private void appendNodeValues(java.lang.StringBuilder sb, int indent, org.apache.maven.artifact.Artifact artifact, boolean hasChildren)
Appends the artifact values to the string builder.- Parameters:
sb
- the string builder to append toindent
- the current indent levelartifact
- the artifact to writehasChildren
- true if the artifact has children
-
appendKeyValue
private void appendKeyValue(java.lang.StringBuilder sb, int indent, java.lang.String key, java.lang.String value)
Appends a key value pair to the string builder.- Parameters:
sb
- the string builder to append toindent
- the current indent levelkey
- the key used as json keyvalue
- the value used as json value
-
appendKeyWithoutComma
private void appendKeyWithoutComma(java.lang.StringBuilder sb, int indent, java.lang.String key, java.lang.String value)
Appends a key value pair to the string builder without a comma at the end. This is used for the last children of a node.- Parameters:
sb
- the string builder to append toindent
- the current indent levelkey
- the key used as json keyvalue
- the value used as json value
-
indent
private java.lang.String indent(int indent)
Returns a string ofindentChar
for the indent level.- Parameters:
indent
- the number of indent levels- Returns:
- the string of indent characters
-
-