Skip to content

Commit 7e7552d

Browse files
author
Vincent Potucek
committed
use try-with-resources statement in impl/maven-cli/src/main/java/org/apache/maven/cling/invoker
1 parent ecfb7c7 commit 7e7552d

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CommonsCliOptions.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -473,18 +473,18 @@ public void displayHelp(String command, Consumer<String> pw) {
473473
pw.accept("");
474474

475475
StringWriter sw = new StringWriter();
476-
PrintWriter pw2 = new PrintWriter(sw);
477-
formatter.printHelp(
478-
pw2,
479-
width,
480-
commandLineSyntax(command),
481-
System.lineSeparator() + "Options:",
482-
options,
483-
HelpFormatter.DEFAULT_LEFT_PAD,
484-
HelpFormatter.DEFAULT_DESC_PAD,
485-
System.lineSeparator(),
486-
false);
487-
pw2.flush();
476+
try (PrintWriter writer = new PrintWriter(sw)) {
477+
formatter.printHelp(
478+
writer,
479+
width,
480+
commandLineSyntax(command),
481+
System.lineSeparator() + "Options:",
482+
options,
483+
HelpFormatter.DEFAULT_LEFT_PAD,
484+
HelpFormatter.DEFAULT_DESC_PAD,
485+
System.lineSeparator(),
486+
false);
487+
}
488488
for (String s : sw.toString().split(System.lineSeparator())) {
489489
pw.accept(s);
490490
}

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,7 @@ protected Consumer<String> doDetermineWriter(C context) {
407407
} else {
408408
// Given the terminal creation has been offloaded to a different thread,
409409
// do not pass directly the terminal writer
410-
return msg -> {
411-
PrintWriter pw = context.terminal.writer();
412-
pw.println(msg);
413-
pw.flush();
414-
};
410+
return msg -> context.terminal.writer().println(msg);
415411
}
416412
}
417413

0 commit comments

Comments
 (0)