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 Details

    • indentChar

      private String indentChar
  • Constructor Details

    • JsonDependencyNodeVisitor

      public JsonDependencyNodeVisitor(Writer writer)
      Creates a new instance of JsonDependencyNodeVisitor. The writer will be used to write the output.
      Parameters:
      writer - the writer to write to
  • Method Details

    • visit

      public boolean visit(org.apache.maven.shared.dependency.graph.DependencyNode node)
      Specified by:
      visit in interface org.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, StringBuilder sb, Set<org.apache.maven.shared.dependency.graph.DependencyNode> visited)
      Appends the node and its children to the string builder.
      Parameters:
      indent - the current indent level
      node - the node to write
      sb - the string builder to append to
    • writeChildren

      private void writeChildren(int indent, org.apache.maven.shared.dependency.graph.DependencyNode node, StringBuilder sb, 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 level
      node - the node to write
      sb - the string builder to append to
    • endVisit

      public boolean endVisit(org.apache.maven.shared.dependency.graph.DependencyNode node)
      Specified by:
      endVisit in interface org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor
    • appendNodeValues

      private void appendNodeValues(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 to
      indent - the current indent level
      artifact - the artifact to write
      hasChildren - true if the artifact has children
    • appendKeyValue

      private void appendKeyValue(StringBuilder sb, int indent, String key, String value)
      Appends a key value pair to the string builder.
      Parameters:
      sb - the string builder to append to
      indent - the current indent level
      key - the key used as json key
      value - the value used as json value
    • appendKeyWithoutComma

      private void appendKeyWithoutComma(StringBuilder sb, int indent, String key, 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 to
      indent - the current indent level
      key - the key used as json key
      value - the value used as json value
    • indent

      private String indent(int indent)
      Returns a string of indentChar for the indent level.
      Parameters:
      indent - the number of indent levels
      Returns:
      the string of indent characters