diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java index b3c201c10..5556236fd 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java @@ -13,6 +13,7 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.stream.Collectors; import com.devonfw.tools.ide.cli.CliProcessException; @@ -168,7 +169,7 @@ public ProcessResult run(ProcessMode processMode) { this.processBuilder.command(args); - List output = new ArrayList<>(); + ConcurrentLinkedQueue output = new ConcurrentLinkedQueue<>(); Process process = this.processBuilder.start(); @@ -188,7 +189,8 @@ public ProcessResult run(ProcessMode processMode) { exitCode = process.waitFor(); } - ProcessResult result = new ProcessResultImpl(this.executable.getFileName().toString(), command, exitCode, output); + List finalOutput = new ArrayList<>(output); + ProcessResult result = new ProcessResultImpl(this.executable.getFileName().toString(), command, exitCode, finalOutput); performLogging(result, exitCode, interpreter); @@ -219,7 +221,7 @@ public ProcessResult run(ProcessMode processMode) { * @param is {@link InputStream}. * @return {@link CompletableFuture}. */ - private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List outputMessages) { + private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, ConcurrentLinkedQueue outputMessages) { return CompletableFuture.supplyAsync(() -> { @@ -227,11 +229,10 @@ private static CompletableFuture> readInputStream(InputStream is, b String line; while ((line = br.readLine()) != null) { - synchronized (outputMessages) { - OutputMessage outputMessage = new OutputMessage(errorStream, line); - outputMessages.add(outputMessage); - } + OutputMessage outputMessage = new OutputMessage(errorStream, line); + outputMessages.add(outputMessage); } + return br.lines().toList(); } catch (Throwable e) { throw new RuntimeException("There was a problem while executing the program", e);