Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.maven.plugins.dependency.tree;

import java.io.PrintWriter;
import java.io.Writer;

/**
Expand All @@ -31,7 +30,7 @@ public abstract class AbstractSerializingVisitor {
/**
* The writer to serialize to.
*/
protected final PrintWriter writer;
protected final Writer writer;

/**
* Constructor.
Expand All @@ -42,10 +41,6 @@ public abstract class AbstractSerializingVisitor {
* @param writer the writer to serialize to.
*/
public AbstractSerializingVisitor(Writer writer) {
if (writer instanceof PrintWriter) {
this.writer = (PrintWriter) writer;
} else {
this.writer = new PrintWriter(writer, true);
}
this.writer = writer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.dependency.tree;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.util.List;

Expand Down Expand Up @@ -47,16 +49,22 @@ public DOTDependencyNodeVisitor(Writer writer) {
*/
@Override
public boolean visit(DependencyNode node) {
if (node.getParent() == null || node.getParent() == node) {
writer.write("digraph \"" + node.toNodeString() + "\" { " + System.lineSeparator());
}
try {
if (node.getParent() == null || node.getParent() == node) {
writer.write("digraph \"" + node.toNodeString() + "\" { " + System.lineSeparator());
writer.flush();
}

// Generate "currentNode -> Child" lines
// Generate "currentNode -> Child" lines

List<DependencyNode> children = node.getChildren();
List<DependencyNode> children = node.getChildren();

for (DependencyNode child : children) {
writer.println("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ; ");
for (DependencyNode child : children) {
writer.write("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ; " + "\n");
}
writer.flush();
} catch (IOException e) {
throw new UncheckedIOException("Failed to write DOT format output", e);
}

return true;
Expand All @@ -67,8 +75,13 @@ public boolean visit(DependencyNode node) {
*/
@Override
public boolean endVisit(DependencyNode node) {
if (node.getParent() == null || node.getParent() == node) {
writer.write(" } ");
try {
if (node.getParent() == null || node.getParent() == node) {
writer.write(" } " + "\n");
writer.flush();
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to write DOT format output", e);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.dependency.tree;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;

import org.apache.maven.shared.dependency.graph.DependencyNode;
Expand Down Expand Up @@ -64,36 +66,47 @@ public GraphmlDependencyNodeVisitor(Writer writer) {
*/
@Override
public boolean endVisit(DependencyNode node) {
if (node.getParent() == null || node.getParent() == node) {
writer.write(GRAPHML_FOOTER);
} else {
DependencyNode p = node.getParent();
writer.print("<edge source=\"" + generateId(p) + "\" target=\"" + generateId(node) + "\">");
if (node.getArtifact().getScope() != null) {
// add Edge label
writer.print("<data key=\"d1\"><y:PolyLineEdge><y:EdgeLabel>"
+ node.getArtifact().getScope() + "</y:EdgeLabel></y:PolyLineEdge></data>");
try {
if (node.getParent() == null || node.getParent() == node) {
writer.write(GRAPHML_FOOTER);
} else {
DependencyNode p = node.getParent();
writer.write("<edge source=\"" + generateId(p) + "\" target=\"" + generateId(node) + "\">");
if (node.getArtifact().getScope() != null) {
// add Edge label
writer.write("<data key=\"d1\"><y:PolyLineEdge><y:EdgeLabel>"
+ node.getArtifact().getScope() + "</y:EdgeLabel></y:PolyLineEdge></data>");
}
writer.write("</edge>" + "\n");
}
writer.println("</edge>");
writer.flush();
return true;
} catch (IOException e) {
throw new UncheckedIOException("Failed to write GraphML format output", e);
}
return true;
}

/**
* {@inheritDoc}
*/
@Override
public boolean visit(DependencyNode node) {
if (node.getParent() == null || node.getParent() == node) {
writer.write(GRAPHML_HEADER);
try {
if (node.getParent() == null || node.getParent() == node) {
writer.write(GRAPHML_HEADER);
writer.flush();
}
// write node
writer.write("<node id=\"" + generateId(node) + "\">");
// add node label
writer.write("<data key=\"d0\"><y:ShapeNode><y:NodeLabel>" + node.toNodeString()
+ "</y:NodeLabel></y:ShapeNode></data>");
writer.write("</node>" + "\n");
writer.flush();
return true;
} catch (IOException e) {
throw new UncheckedIOException("Failed to write GraphML format output", e);
}
// write node
writer.print("<node id=\"" + generateId(node) + "\">");
// add node label
writer.print("<data key=\"d0\"><y:ShapeNode><y:NodeLabel>" + node.toNodeString()
+ "</y:NodeLabel></y:ShapeNode></data>");
writer.println("</node>");
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.dependency.tree;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -44,25 +46,31 @@ public JsonDependencyNodeVisitor(Writer writer) {

@Override
public boolean visit(DependencyNode node) {
if (node.getParent() == null || node.getParent() == node) {
writeRootNode(node);
try {
if (node.getParent() == null || node.getParent() == node) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird. Nodes can be their own parent?

writeRootNode(node);
}
return true;
} catch (IOException e) {
throw new UncheckedIOException("Failed to write JSON format output", e);
}
return true;
}

/**
* Writes the node to the writer. This method is recursive and will write all children nodes.
*
* @param node the node to write
* @throws IOException if an I/O error occurs while writing
*/
private void writeRootNode(DependencyNode node) {
private void writeRootNode(DependencyNode node) throws IOException {
Set<DependencyNode> visited = new HashSet<>();
int indent = 2;
StringBuilder sb = new StringBuilder();
sb.append("{").append("\n");
writeNode(indent, node, sb, visited);
sb.append("}").append("\n");
writer.write(sb.toString());
writer.flush();
}
/**
* Appends the node and its children to the string builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.dependency.tree;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -35,7 +37,7 @@
public class TGFDependencyNodeVisitor extends AbstractSerializingVisitor implements DependencyNodeVisitor {

/**
* Utiity class to write an Edge.
* Utility class to write an Edge.
*
* @author <a href="mailto:[email protected]">Jerome Creignou</a>
*/
Expand Down Expand Up @@ -102,30 +104,41 @@ public TGFDependencyNodeVisitor(Writer writer) {
*/
@Override
public boolean endVisit(DependencyNode node) {
if (node.getParent() == null || node.getParent() == node) {
// dump edges on last node endVisit
writer.println("#");
for (EdgeAppender edge : edges) {
writer.println(edge.toString());
try {
if (node.getParent() == null || node.getParent() == node) {
// dump edges on last node endVisit
writer.write("#\n");
for (EdgeAppender edge : edges) {
writer.write(edge.toString() + "\n");
}
writer.flush();
} else {
DependencyNode parent = node.getParent();
// using scope as edge label.
edges.add(new EdgeAppender(parent, node, node.getArtifact().getScope()));
}
} else {
DependencyNode p = node.getParent();
// using scope as edge label.
edges.add(new EdgeAppender(p, node, node.getArtifact().getScope()));
return true;
} catch (IOException e) {
throw new UncheckedIOException("Failed to write TGF format output", e);
}
return true;
}

/**
* {@inheritDoc}
*/
@Override
public boolean visit(DependencyNode node) {
// write node
writer.write(generateId(node));
writer.write(" ");
writer.println(node.toNodeString());
return true;
try {
// Write node
writer.write(generateId(node));
writer.write(" ");
writer.write(node.toNodeString());
writer.write("\n");
writer.flush();
return true;
} catch (IOException e) {
throw new UncheckedIOException("Failed to write TGF format output", e);
}
}

/**
Expand Down