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.StringindentChar-
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 voidappendKeyValue(java.lang.StringBuilder sb, int indent, java.lang.String key, java.lang.String value)Appends a key value pair to the string builder.private voidappendKeyWithoutComma(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 voidappendNodeValues(java.lang.StringBuilder sb, int indent, org.apache.maven.artifact.Artifact artifact, boolean hasChildren)Appends the artifact values to the string builder.booleanendVisit(org.apache.maven.shared.dependency.graph.DependencyNode node)private java.lang.Stringindent(int indent)Returns a string ofindentCharfor the indent level.booleanvisit(org.apache.maven.shared.dependency.graph.DependencyNode node)private voidwriteChildren(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 voidwriteNode(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 voidwriteRootNode(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:
visitin interfaceorg.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor
-
writeRootNode
private void writeRootNode(org.apache.maven.shared.dependency.graph.DependencyNode node) throws java.io.IOExceptionWrites the node to the writer. This method is recursive and will write all children nodes.- Parameters:
node- the node to write- Throws:
java.io.IOException- if an I/O error occurs while writing
-
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. Each child 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:
endVisitin 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 ofindentCharfor the indent level.- Parameters:
indent- the number of indent levels- Returns:
- the string of indent characters
-
-