Skip to content

Commit d1b3880

Browse files
committed
Reword it
1 parent 150db79 commit d1b3880

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

impl/maven-executor/src/main/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutor.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import java.io.ByteArrayOutputStream;
2222
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.io.OutputStream;
2325
import java.io.UncheckedIOException;
2426
import java.nio.file.Files;
2527
import java.nio.file.Path;
@@ -107,9 +109,9 @@ protected Consumer<Process> wrapRequestStandardStreams(ExecutorRequest executorR
107109
String suffix = "-pump-" + p.pid();
108110
executorRequest.stdOut().ifPresent(stdout -> {
109111
Thread pump = new Thread(() -> {
110-
try {
112+
try (InputStream out = p.getInputStream()) {
111113
int c;
112-
while ((c = p.getInputStream().read()) != -1) {
114+
while ((c = out.read()) != -1) {
113115
stdout.write(c);
114116
}
115117
stdout.flush();
@@ -123,9 +125,9 @@ protected Consumer<Process> wrapRequestStandardStreams(ExecutorRequest executorR
123125
});
124126
executorRequest.stdErr().ifPresent(stderr -> {
125127
Thread pump = new Thread(() -> {
126-
try {
128+
try (InputStream err = p.getErrorStream()) {
127129
int c;
128-
while ((c = p.getErrorStream().read()) != -1) {
130+
while ((c = err.read()) != -1) {
129131
stderr.write(c);
130132
}
131133
stderr.flush();
@@ -139,12 +141,12 @@ protected Consumer<Process> wrapRequestStandardStreams(ExecutorRequest executorR
139141
});
140142
executorRequest.stdIn().ifPresent(stdin -> {
141143
Thread pump = new Thread(() -> {
142-
try {
144+
try (OutputStream in = p.getOutputStream()) {
143145
int c;
144146
while ((c = stdin.read()) != -1) {
145-
p.getOutputStream().write(c);
147+
in.write(c);
146148
}
147-
p.getOutputStream().flush();
149+
in.flush();
148150
} catch (IOException e) {
149151
throw new UncheckedIOException(e);
150152
}
@@ -205,6 +207,7 @@ protected int doExecute(ExecutorRequest executorRequest, Consumer<Process> proce
205207
try {
206208
ProcessBuilder pb = new ProcessBuilder()
207209
.directory(executorRequest.cwd().toFile())
210+
.inheritIO()
208211
.command(cmdAndArguments);
209212
if (!env.isEmpty()) {
210213
pb.environment().putAll(env);

0 commit comments

Comments
 (0)