reta commented on code in PR #405:
URL: https://github.com/apache/cxf-xjc-utils/pull/405#discussion_r4320632369
##########
cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XJCBuildContext.java:
##########
@@ -60,41 +90,108 @@ public Object getValue(String key) {
return null;
}
public void addWarning(File file, int line, int column, String message,
Throwable cause) {
- System.out.println("WARNING: " + file.getAbsolutePath());
- System.out.println("Line: " + line);
- System.out.println("Col: " + column);
- System.out.println(message);
- if (cause != null) {
- cause.printStackTrace(System.out);
- }
- System.out.println();
- System.out.println("DONE");
+ System.out.println(formatMessage(SEVERITY_WARNING, file, line, column,
message, cause));
}
@Override
public void addError(File file, int line, int column, String message,
Throwable cause) {
- System.err.println("ERROR: " + file.getAbsolutePath());
- System.err.println("Line: " + line);
- System.err.println("Col: " + column);
- System.err.println(message);
- if (cause != null) {
- cause.printStackTrace(System.err);
- }
- System.err.println();
- System.err.println("DONE");
+ System.err.println(formatMessage(SEVERITY_ERROR, file, line, column,
message, cause));
}
+
public void addMessage(File file, int line, int column, String message,
int severity, Throwable cause) {
- System.out.println("MSG: " + file.getAbsolutePath());
- System.out.println("Severity: " + severity);
- System.out.println("Line: " + line);
- System.out.println("Col: " + column);
- System.out.println(message);
+ PrintStream out = severity == SEVERITY_ERROR ? System.err : System.out;
+ out.println(formatMessage(severity, file, line, column, message,
cause));
+ }
+
+ static String formatMessage(int severity, File file, int line, int column,
String message, Throwable cause) {
+ StringBuilder text = new StringBuilder();
+ if (message != null) {
+ text.append(message);
+ }
if (cause != null) {
- cause.printStackTrace(System.out);
+ StringWriter trace = new StringWriter();
+ cause.printStackTrace(new PrintWriter(trace));
Review Comment:
`PrintWriter` seems to be worth closing (StringWriter is noop):
```
try (PrintWriter pw = new PrintWriter(trace)) {
cause.printStackTrace(pw);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]