-
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?
Conversation
…Visitor and subclasses
src/main/java/org/apache/maven/plugins/dependency/tree/DOTDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/DOTDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/DOTDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/GraphmlDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/GraphmlDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/JsonDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/TGFDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/TGFDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/tree/TGFDependencyNodeVisitor.java
Outdated
Show resolved
Hide resolved
writer.flush(); | ||
return true; | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Failed to write to DOT output", 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.
probably better than what we had before, but really we need a complete rethink of this API that separates I/O from string buliding and lets it throw exceptions
for (DependencyNode child : children) { | ||
writer.println("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ; "); | ||
// Write the accumulated output to the provided writer | ||
writer.write(stringWriter.toString()); |
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.
This shouldn't be happening in the visit method. The visitor should be building the report in memory that is only later written to a stream. Alternately the API should change so that visit can throw an IOException.
if (node.getParent() == null || node.getParent() == node) { | ||
writer.write(" } "); | ||
try { | ||
StringWriter stringWriter = new StringWriter(); |
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.
you don't need the stringwriter here. Just use the writer directly
writer.flush(); | ||
return true; | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Failed to write GraphML node", 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.
I'm starting to see how this should work. Either drop all the stringwiters and write straight onto the writer, or use stringwriters to build up a report that is written after the visitor is finished.
writer.write(sb.toString()); | ||
writer.flush(); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Failed to write JSON output", 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.
not needed; this method can and should throw the IOException directly since it's private
return true; | ||
try { | ||
if (node.getParent() == null || node.getParent() == node) { | ||
writer.flush(); |
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.
possibly here and only here content should be written to the stream; I'm not sure
CI failing on a known flaky test:
|
Following this checklist to help us incorporate your
contribution quickly and easily:
Fixes https://issues.apache.org/jira/browse/MDEP-931
cc @elharo
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verify
to make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
mvn -Prun-its verify
).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.