-
Notifications
You must be signed in to change notification settings - Fork 181
Fix [MDEP-931] Replace PrintWriter with Writer in AbstractSerializing Visitor and subclasses #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
package org.apache.maven.plugins.dependency.tree; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.List; | ||
|
||
|
@@ -47,29 +48,38 @@ public DOTDependencyNodeVisitor(Writer writer) { | |
*/ | ||
@Override | ||
public boolean visit(DependencyNode node) { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
writer.write("digraph \"" + node.toNodeString() + "\" { " + System.lineSeparator()); | ||
} | ||
|
||
// Generate "currentNode -> Child" lines | ||
try { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
writer.write("digraph \"" + node.toNodeString() + "\" { " + System.lineSeparator()); | ||
} | ||
|
||
List<DependencyNode> children = node.getChildren(); | ||
// Generate "currentNode -> Child" lines | ||
|
||
for (DependencyNode child : children) { | ||
writer.println("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ; "); | ||
List<DependencyNode> children = node.getChildren(); | ||
for (DependencyNode child : children) { | ||
writer.write("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ; " | ||
+ System.lineSeparator()); | ||
} | ||
writer.flush(); | ||
return true; | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write to DOT output", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UncheckedIOException but really we need to figure out how to not thrown an exception at all here, or perhaps change the method signature. Possibly we need to put everything in a StringWriter first and then write the string later. |
||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@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(" } "); | ||
writer.flush(); | ||
} | ||
return true; | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write to DOT output", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
package org.apache.maven.plugins.dependency.tree; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
import org.apache.maven.shared.dependency.graph.DependencyNode; | ||
|
@@ -63,37 +64,48 @@ public GraphmlDependencyNodeVisitor(Writer writer) { | |
* {@inheritDoc} | ||
*/ | ||
@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>"); | ||
public boolean visit(DependencyNode node) { | ||
try { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
writer.write(GRAPHML_HEADER); | ||
} | ||
writer.println("</edge>"); | ||
// 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>" + System.lineSeparator()); | ||
writer.flush(); | ||
return true; | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write GraphML node", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean visit(DependencyNode node) { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
writer.write(GRAPHML_HEADER); | ||
public boolean endVisit(DependencyNode node) { | ||
try { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
writer.write(GRAPHML_FOOTER); | ||
writer.flush(); | ||
} 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>" + System.lineSeparator()); | ||
writer.flush(); | ||
} | ||
return true; | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write GraphML edge or footer", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
// 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; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
package org.apache.maven.plugins.dependency.tree; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
@@ -56,13 +57,18 @@ public boolean visit(DependencyNode node) { | |
* @param node the node to write | ||
*/ | ||
private void writeRootNode(DependencyNode node) { | ||
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()); | ||
try { | ||
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(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write JSON output", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
} | ||
/** | ||
* Appends the node and its children to the string builder. | ||
|
@@ -110,7 +116,14 @@ private void writeChildren(int indent, DependencyNode node, StringBuilder sb, Se | |
|
||
@Override | ||
public boolean endVisit(DependencyNode node) { | ||
return true; | ||
try { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
writer.flush(); | ||
} | ||
return true; | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to flush JSON output", e); | ||
} | ||
} | ||
/** | ||
* Appends the artifact values to the string builder. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
package org.apache.maven.plugins.dependency.tree; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
@@ -101,31 +102,43 @@ public TGFDependencyNodeVisitor(Writer writer) { | |
* {@inheritDoc} | ||
*/ | ||
@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()); | ||
} | ||
} else { | ||
DependencyNode p = node.getParent(); | ||
// using scope as edge label. | ||
edges.add(new EdgeAppender(p, node, node.getArtifact().getScope())); | ||
public boolean visit(DependencyNode node) { | ||
try { | ||
// write node | ||
writer.write(generateId(node)); | ||
writer.write(" "); | ||
writer.write(node.toNodeString()); | ||
writer.write(System.lineSeparator()); | ||
writer.flush(); | ||
return true; | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write TGF node", e); | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean visit(DependencyNode node) { | ||
// write node | ||
writer.write(generateId(node)); | ||
writer.write(" "); | ||
writer.println(node.toNodeString()); | ||
return true; | ||
public boolean endVisit(DependencyNode node) { | ||
try { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
// dump edges on last node endVisit | ||
writer.write("#" + System.lineSeparator()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. \n |
||
for (EdgeAppender edge : edges) { | ||
writer.write(edge.toString()); | ||
writer.write(System.lineSeparator()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. \n |
||
} | ||
writer.flush(); | ||
} else { | ||
DependencyNode p = node.getParent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p --> parent |
||
// using scope as edge label. | ||
edges.add(new EdgeAppender(p, node, node.getArtifact().getScope())); | ||
} | ||
return true; | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write TGF edges or footer", e); | ||
} | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output should be platform independent. That is, use \n