|
9 | 9 |
|
10 | 10 | import java.io.File; |
11 | 11 | import java.io.IOException; |
| 12 | +import java.io.UncheckedIOException; |
12 | 13 | import java.nio.charset.StandardCharsets; |
13 | 14 | import java.nio.file.Files; |
14 | 15 | import java.util.ArrayList; |
15 | 16 | import java.util.Arrays; |
16 | 17 | import java.util.List; |
| 18 | +import java.util.concurrent.CompletableFuture; |
17 | 19 |
|
18 | 20 | @SuppressWarnings({"unused", "MismatchedReadAndWriteOfArray"}) |
19 | 21 | @Mojo(name = "sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true, requiresOnline = true) |
@@ -215,9 +217,25 @@ public void execute() throws MojoFailureException { |
215 | 217 | try (var stdout = new LoggingOutputStream(getLog()::info, StandardCharsets.UTF_8); |
216 | 218 | var stderr = new LoggingOutputStream(getLog()::warn, StandardCharsets.UTF_8)) { |
217 | 219 | Process process = command.start(); |
218 | | - process.getInputStream().transferTo(stdout); |
219 | | - process.getErrorStream().transferTo(stderr); |
| 220 | + |
| 221 | + final var stdoutFuture = CompletableFuture.runAsync(() -> { |
| 222 | + try { |
| 223 | + process.getInputStream().transferTo(stdout); |
| 224 | + } catch (IOException e) { |
| 225 | + throw new UncheckedIOException("Error while writing jextract stdout to logs", e); |
| 226 | + } |
| 227 | + }); |
| 228 | + |
| 229 | + final var stderrFuture = CompletableFuture.runAsync(() -> { |
| 230 | + try { |
| 231 | + process.getErrorStream().transferTo(stderr); |
| 232 | + } catch (IOException e) { |
| 233 | + throw new UncheckedIOException("Error while writing jextract stderr to logs", e); |
| 234 | + } |
| 235 | + }); |
| 236 | + |
220 | 237 | int result = process.waitFor(); |
| 238 | + CompletableFuture.allOf(stdoutFuture, stderrFuture).join(); |
221 | 239 | if (result != 0) { |
222 | 240 | throw new MojoFailureException("jextract returned error code " + result); |
223 | 241 | } |
|
0 commit comments