Class 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.
    • 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 of indentChar 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • indentChar

        private java.lang.String indentChar
    • Constructor Detail

      • JsonDependencyNodeVisitor

        public JsonDependencyNodeVisitor​(java.io.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 Detail

      • 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,
                               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 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,
                                   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 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​(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 to
        indent - the current indent level
        artifact - the artifact to write
        hasChildren - 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 to
        indent - the current indent level
        key - the key used as json key
        value - 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 to
        indent - the current indent level
        key - the key used as json key
        value - the value used as json value
      • indent

        private java.lang.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