From e25575f462847a164e6f9b53f97fe514a0ff4a16 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 19 Nov 2024 08:42:18 +0100 Subject: [PATCH 01/15] Add single log list --- .../tools/ide/process/ProcessContextImpl.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) 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 24cec551a..07f360065 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 @@ -129,6 +129,9 @@ public ProcessContext withPathEntry(Path path) { @Override public ProcessResult run(ProcessMode processMode) { + final String ERROR_PREFIX = "ERROR: "; + final String OUTPUT_PREFIX = "OUTPUT: "; + if (processMode == ProcessMode.DEFAULT) { this.processBuilder.redirectOutput(Redirect.INHERIT).redirectError(Redirect.INHERIT); } @@ -167,16 +170,16 @@ public ProcessResult run(ProcessMode processMode) { this.processBuilder.command(args); - List out = null; + List logs = new ArrayList<>(); List err = null; Process process = this.processBuilder.start(); if (processMode == ProcessMode.DEFAULT_CAPTURE) { - CompletableFuture> outFut = readInputStream(process.getInputStream()); - CompletableFuture> errFut = readInputStream(process.getErrorStream()); - out = outFut.get(); - err = errFut.get(); + CompletableFuture> outFut = readInputStream(process.getInputStream(), false, logs); + CompletableFuture> errFut = readInputStream(process.getErrorStream(), true, logs); + outFut.get(); + errFut.get(); } int exitCode; @@ -187,10 +190,9 @@ public ProcessResult run(ProcessMode processMode) { exitCode = process.waitFor(); } - ProcessResult result = new ProcessResultImpl(exitCode, out, err); + ProcessResult result = new ProcessResultImpl(exitCode, logs, null); performLogging(result, exitCode, interpreter); - return result; } catch (CliProcessException | IllegalStateException e) { @@ -214,11 +216,19 @@ public ProcessResult run(ProcessMode processMode) { * @param is {@link InputStream}. * @return {@link CompletableFuture}. */ - private static CompletableFuture> readInputStream(InputStream is) { + private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List logs) { return CompletableFuture.supplyAsync(() -> { try (InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) { + + String prefix = errorStream ? "- " : "+ "; + String line; + while ((line = br.readLine()) != null) { + synchronized (logs) { + logs.add(prefix + line); + } + } return br.lines().toList(); } catch (Throwable e) { throw new RuntimeException("There was a problem while executing the program", e); From 4d5a55676bc3c2311529bf3e6fbc6933ee4093f3 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:14:00 +0100 Subject: [PATCH 02/15] Add LogEvent Record --- .../java/com/devonfw/tools/ide/process/LogEvent.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 cli/src/main/java/com/devonfw/tools/ide/process/LogEvent.java diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/LogEvent.java b/cli/src/main/java/com/devonfw/tools/ide/process/LogEvent.java new file mode 100644 index 000000000..055f81c68 --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/process/LogEvent.java @@ -0,0 +1,11 @@ +package com.devonfw.tools.ide.process; + +/** + * Represent a log event. + * + * @param error A boolean flag that indicates whether the log event represents and error or standard output + * @param message A string containing the log message + */ +public record LogEvent(boolean error, String message) { + +} From daf4b45d569d811edbc6a2f02ae871191051a531 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:15:14 +0100 Subject: [PATCH 03/15] Add LogEvent List to capture Logs --- .../tools/ide/process/ProcessContextImpl.java | 18 ++++++++---------- .../tools/ide/process/ProcessResultImpl.java | 11 ++++++++++- 2 files changed, 18 insertions(+), 11 deletions(-) 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 07f360065..ed6a7c90f 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 @@ -129,9 +129,6 @@ public ProcessContext withPathEntry(Path path) { @Override public ProcessResult run(ProcessMode processMode) { - final String ERROR_PREFIX = "ERROR: "; - final String OUTPUT_PREFIX = "OUTPUT: "; - if (processMode == ProcessMode.DEFAULT) { this.processBuilder.redirectOutput(Redirect.INHERIT).redirectError(Redirect.INHERIT); } @@ -170,7 +167,8 @@ public ProcessResult run(ProcessMode processMode) { this.processBuilder.command(args); - List logs = new ArrayList<>(); + List logs = new ArrayList<>(); + List out = null; List err = null; Process process = this.processBuilder.start(); @@ -178,8 +176,8 @@ public ProcessResult run(ProcessMode processMode) { if (processMode == ProcessMode.DEFAULT_CAPTURE) { CompletableFuture> outFut = readInputStream(process.getInputStream(), false, logs); CompletableFuture> errFut = readInputStream(process.getErrorStream(), true, logs); - outFut.get(); - errFut.get(); + out = outFut.get(); + err = errFut.get(); } int exitCode; @@ -190,7 +188,7 @@ public ProcessResult run(ProcessMode processMode) { exitCode = process.waitFor(); } - ProcessResult result = new ProcessResultImpl(exitCode, logs, null); + ProcessResult result = new ProcessResultImpl(exitCode, out, err, logs); performLogging(result, exitCode, interpreter); return result; @@ -216,17 +214,17 @@ public ProcessResult run(ProcessMode processMode) { * @param is {@link InputStream}. * @return {@link CompletableFuture}. */ - private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List logs) { + private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List logs) { return CompletableFuture.supplyAsync(() -> { try (InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) { - String prefix = errorStream ? "- " : "+ "; String line; while ((line = br.readLine()) != null) { synchronized (logs) { - logs.add(prefix + line); + LogEvent logEvent = new LogEvent(errorStream, line); + logs.add(logEvent); } } return br.lines().toList(); diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index c4786d54b..980ce6ae2 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -18,19 +18,23 @@ public class ProcessResultImpl implements ProcessResult { private final List err; + private final List logEvents; + /** * The constructor. * * @param exitCode the {@link #getExitCode() exit code}. * @param out the {@link #getOut() out}. * @param err the {@link #getErr() err}. + * @param logEvents the {@link #getLogEvents()} () logEvents}. */ - public ProcessResultImpl(int exitCode, List out, List err) { + public ProcessResultImpl(int exitCode, List out, List err, List logEvents) { super(); this.exitCode = exitCode; this.out = Objects.requireNonNullElse(out, Collections.emptyList()); this.err = Objects.requireNonNullElse(err, Collections.emptyList()); + this.logEvents = Objects.requireNonNullElse(logEvents, Collections.emptyList()); } @Override @@ -51,6 +55,11 @@ public List getErr() { return this.err; } + public List getLogEvents() { + + return this.logEvents; + } + @Override public void log(IdeLogLevel level, IdeContext context) { log(level, context, level); From 3da75c79e9d914782417dffd2092cfe32b71647b Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:11:20 +0100 Subject: [PATCH 04/15] add general List of output messages and rename logevent to outputmessage and refactor ProcessContextGitMock --- .../{LogEvent.java => OutputMessage.java} | 2 +- .../tools/ide/process/ProcessContextImpl.java | 20 ++++++++-------- .../tools/ide/process/ProcessResultImpl.java | 23 +++++++++---------- .../ide/context/ProcessContextGitMock.java | 20 ++++++++-------- 4 files changed, 32 insertions(+), 33 deletions(-) rename cli/src/main/java/com/devonfw/tools/ide/process/{LogEvent.java => OutputMessage.java} (79%) diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/LogEvent.java b/cli/src/main/java/com/devonfw/tools/ide/process/OutputMessage.java similarity index 79% rename from cli/src/main/java/com/devonfw/tools/ide/process/LogEvent.java rename to cli/src/main/java/com/devonfw/tools/ide/process/OutputMessage.java index 055f81c68..7683427bb 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/LogEvent.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/OutputMessage.java @@ -6,6 +6,6 @@ * @param error A boolean flag that indicates whether the log event represents and error or standard output * @param message A string containing the log message */ -public record LogEvent(boolean error, String message) { +public record OutputMessage(boolean error, String message) { } 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 488491ce0..13e113827 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 @@ -168,18 +168,16 @@ public ProcessResult run(ProcessMode processMode) { this.processBuilder.command(args); - List logs = new ArrayList<>(); - List out = null; - List err = null; + List output = new ArrayList<>(); Process process = this.processBuilder.start(); try { if (processMode == ProcessMode.DEFAULT_CAPTURE) { - CompletableFuture> outFut = readInputStream(process.getInputStream()); - CompletableFuture> errFut = readInputStream(process.getErrorStream()); - out = outFut.get(); - err = errFut.get(); + CompletableFuture> outFut = readInputStream(process.getInputStream(), false, output); + CompletableFuture> errFut = readInputStream(process.getErrorStream(), true, output); + outFut.get(); + errFut.get(); } int exitCode; @@ -190,7 +188,7 @@ public ProcessResult run(ProcessMode processMode) { exitCode = process.waitFor(); } - ProcessResult result = new ProcessResultImpl(this.executable.getFileName().toString(), command, exitCode, out, err); + ProcessResult result = new ProcessResultImpl(this.executable.getFileName().toString(), command, exitCode, output); performLogging(result, exitCode, interpreter); @@ -221,7 +219,7 @@ public ProcessResult run(ProcessMode processMode) { * @param is {@link InputStream}. * @return {@link CompletableFuture}. */ - private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List logs) { + private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List logs) { return CompletableFuture.supplyAsync(() -> { @@ -230,8 +228,8 @@ private static CompletableFuture> readInputStream(InputStream is, b String line; while ((line = br.readLine()) != null) { synchronized (logs) { - LogEvent logEvent = new LogEvent(errorStream, line); - logs.add(logEvent); + OutputMessage outputMessage = new OutputMessage(errorStream, line); + logs.add(outputMessage); } } return br.lines().toList(); diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index 84420d2be..99b49e0f7 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import com.devonfw.tools.ide.cli.CliProcessException; import com.devonfw.tools.ide.context.IdeContext; @@ -23,7 +24,7 @@ public class ProcessResultImpl implements ProcessResult { private final List err; - private final List logEvents; + private final List outputMessages; /** * The constructor. @@ -31,19 +32,17 @@ public class ProcessResultImpl implements ProcessResult { * @param executable the {@link #getExecutable() executable}. * @param command the {@link #getCommand() command}. * @param exitCode the {@link #getExitCode() exit code}. - * @param out the {@link #getOut() out}. - * @param err the {@link #getErr() err}. - * @param logEvents the {@link #getLogEvents()} () logEvents}. + * @param output {@link #getOutputMessages() output Messages}. */ - public ProcessResultImpl(String executable, String command, int exitCode, List out, List err) { + public ProcessResultImpl(String executable, String command, int exitCode, List output) { super(); this.executable = executable; this.command = command; this.exitCode = exitCode; - this.out = Objects.requireNonNullElse(out, Collections.emptyList()); - this.err = Objects.requireNonNullElse(err, Collections.emptyList()); - this.logEvents = Objects.requireNonNullElse(logEvents, Collections.emptyList()); + this.outputMessages = Objects.requireNonNullElse(output, Collections.emptyList()); + this.out = this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).collect(Collectors.toList()); + this.err = this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); } @Override @@ -67,18 +66,18 @@ public int getExitCode() { @Override public List getOut() { - return this.out; + return outputMessages.stream().filter(output -> !output.error()).map(OutputMessage::message).collect(Collectors.toList()); } @Override public List getErr() { - return this.err; + return outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); } - public List getLogEvents() { + public List getOutputMessages() { - return this.logEvents; + return this.outputMessages; } @Override diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java index 5c891d257..1ea375e22 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java @@ -7,7 +7,9 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import com.devonfw.tools.ide.process.OutputMessage; import com.devonfw.tools.ide.process.ProcessContext; import com.devonfw.tools.ide.process.ProcessErrorHandling; import com.devonfw.tools.ide.process.ProcessMode; @@ -21,9 +23,7 @@ public class ProcessContextGitMock implements ProcessContext { private final List arguments; - private final List errors; - - private final List outs; + private final List outputMessages; private final LocalDateTime now; @@ -37,8 +37,7 @@ public class ProcessContextGitMock implements ProcessContext { public ProcessContextGitMock(Path directory) { this.arguments = new ArrayList<>(); - this.errors = new ArrayList<>(); - this.outs = new ArrayList<>(); + this.outputMessages = new ArrayList<>(); this.exitCode = ProcessResult.SUCCESS; this.directory = directory; this.now = LocalDateTime.now(); @@ -65,7 +64,8 @@ public void setExitCode(int exitCode) { */ public List getErrors() { - return errors; + return this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); + } /** @@ -73,7 +73,8 @@ public List getErrors() { */ public List getOuts() { - return outs; + return this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).collect(Collectors.toList()); + } @Override @@ -139,7 +140,8 @@ public ProcessResult run(ProcessMode processMode) { // part of git cleanup checks if a new directory 'new-folder' exists if (this.arguments.contains("ls-files")) { if (Files.exists(this.directory.resolve("new-folder"))) { - this.outs.add("new-folder"); + OutputMessage outputMessage = new OutputMessage(false, "new-folder"); + this.outputMessages.add(outputMessage); this.exitCode = 0; } } @@ -181,7 +183,7 @@ public ProcessResult run(ProcessMode processMode) { } } this.arguments.clear(); - return new ProcessResultImpl("git", command.toString(), this.exitCode, this.outs, this.errors); + return new ProcessResultImpl("git", command.toString(), this.exitCode, this.outputMessages); } } From c2b702110eeee14515cf58c5c417eed5aff0cd95 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:17:50 +0100 Subject: [PATCH 05/15] refactor --- .../java/com/devonfw/tools/ide/process/OutputMessage.java | 6 +++--- .../com/devonfw/tools/ide/process/ProcessContextImpl.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/OutputMessage.java b/cli/src/main/java/com/devonfw/tools/ide/process/OutputMessage.java index 7683427bb..022baf69b 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/OutputMessage.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/OutputMessage.java @@ -1,10 +1,10 @@ package com.devonfw.tools.ide.process; /** - * Represent a log event. + * Represent an output message that can be either from stdout or stderr. * - * @param error A boolean flag that indicates whether the log event represents and error or standard output - * @param message A string containing the log message + * @param error A boolean flag that indicates whether the output message is from stdout or stderr + * @param message A string containing the outout message */ public record OutputMessage(boolean error, String message) { 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 13e113827..4dbf8daf5 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 @@ -219,7 +219,7 @@ public ProcessResult run(ProcessMode processMode) { * @param is {@link InputStream}. * @return {@link CompletableFuture}. */ - private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List logs) { + private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List outputs) { return CompletableFuture.supplyAsync(() -> { @@ -227,9 +227,9 @@ private static CompletableFuture> readInputStream(InputStream is, b String line; while ((line = br.readLine()) != null) { - synchronized (logs) { + synchronized (outputs) { OutputMessage outputMessage = new OutputMessage(errorStream, line); - logs.add(outputMessage); + outputs.add(outputMessage); } } return br.lines().toList(); From 4530860ed02eb584612bc37776cbadda847d044d Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:18:46 +0100 Subject: [PATCH 06/15] refactor processResultImpl in tooldummy --- .../devonfw/tools/ide/tool/ide/IdeToolDummyCommandletTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/ide/IdeToolDummyCommandletTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/ide/IdeToolDummyCommandletTest.java index 1bf582688..48beb6c99 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/tool/ide/IdeToolDummyCommandletTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/ide/IdeToolDummyCommandletTest.java @@ -75,7 +75,7 @@ public ProcessResult runTool(ProcessMode processMode, GenericVersionRange toolVe // skip installation but trigger postInstall to test mocked plugin installation postInstall(true); - return new ProcessResultImpl(this.tool, this.tool, 0, List.of(), List.of()); + return new ProcessResultImpl(this.tool, this.tool, 0, List.of()); } @Override From 88c8ef1941fda18a6c5d6b0184a3b9de55771304 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:12:15 +0100 Subject: [PATCH 07/15] change List of Strings for getOutputMessages --- .../devonfw/tools/ide/process/ProcessResultImpl.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index 99b49e0f7..2fd71b95c 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -75,9 +75,10 @@ public List getErr() { return outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); } - public List getOutputMessages() { + public List getOutputMessages() { + + return outputMessages.stream().map(OutputMessage::message).collect(Collectors.toList()); - return this.outputMessages; } @Override @@ -88,11 +89,8 @@ public void log(IdeLogLevel level, IdeContext context) { @Override public void log(IdeLogLevel outLevel, IdeContext context, IdeLogLevel errorLevel) { - if (!this.out.isEmpty()) { - doLog(outLevel, this.out, context); - } - if (!this.err.isEmpty()) { - doLog(errorLevel, this.err, context); + if (!this.outputMessages.isEmpty()) { + doLog(outLevel, getOutputMessages(), context); } } From 4700583ca31b7c1a1fb39cab681e1169ab0dabce Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:38:53 +0100 Subject: [PATCH 08/15] update Test with output message list --- .../tools/ide/process/ProcessContextImpl.java | 6 +++--- .../tools/ide/process/ProcessResultImpl.java | 10 +++++----- .../ide/context/ProcessContextGitMock.java | 18 +++++++++++++++--- .../devonfw/tools/ide/git/GitContextTest.java | 4 +++- 4 files changed, 26 insertions(+), 12 deletions(-) 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 4dbf8daf5..03ca7bcb1 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 @@ -219,7 +219,7 @@ public ProcessResult run(ProcessMode processMode) { * @param is {@link InputStream}. * @return {@link CompletableFuture}. */ - private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List outputs) { + private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List outputMessages) { return CompletableFuture.supplyAsync(() -> { @@ -227,9 +227,9 @@ private static CompletableFuture> readInputStream(InputStream is, b String line; while ((line = br.readLine()) != null) { - synchronized (outputs) { + synchronized (outputMessages) { OutputMessage outputMessage = new OutputMessage(errorStream, line); - outputs.add(outputMessage); + outputMessages.add(outputMessage); } } return br.lines().toList(); diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index 2fd71b95c..e7af1a2fe 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -34,13 +34,13 @@ public class ProcessResultImpl implements ProcessResult { * @param exitCode the {@link #getExitCode() exit code}. * @param output {@link #getOutputMessages() output Messages}. */ - public ProcessResultImpl(String executable, String command, int exitCode, List output) { + public ProcessResultImpl(String executable, String command, int exitCode, List outputMessages) { super(); this.executable = executable; this.command = command; this.exitCode = exitCode; - this.outputMessages = Objects.requireNonNullElse(output, Collections.emptyList()); + this.outputMessages = Objects.requireNonNullElse(outputMessages, Collections.emptyList()); this.out = this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).collect(Collectors.toList()); this.err = this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); } @@ -75,9 +75,9 @@ public List getErr() { return outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); } - public List getOutputMessages() { + public List getOutputMessages() { - return outputMessages.stream().map(OutputMessage::message).collect(Collectors.toList()); + return outputMessages; } @@ -90,7 +90,7 @@ public void log(IdeLogLevel level, IdeContext context) { public void log(IdeLogLevel outLevel, IdeContext context, IdeLogLevel errorLevel) { if (!this.outputMessages.isEmpty()) { - doLog(outLevel, getOutputMessages(), context); + doLog(outLevel, getOutputMessages().stream().map(OutputMessage::message).collect(Collectors.toList()), context); } } diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java index 1ea375e22..c584c4ec2 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java @@ -31,6 +31,8 @@ public class ProcessContextGitMock implements ProcessContext { private final Path directory; + private final List outs; + /** * @param directory the {@link Path} to the git repository. */ @@ -40,6 +42,7 @@ public ProcessContextGitMock(Path directory) { this.outputMessages = new ArrayList<>(); this.exitCode = ProcessResult.SUCCESS; this.directory = directory; + this.outs = new ArrayList<>(); this.now = LocalDateTime.now(); } @@ -60,7 +63,7 @@ public void setExitCode(int exitCode) { } /** - * @return the {@link List} of mocked error messages. + * @return the {@link List} of mocked stderr messages. */ public List getErrors() { @@ -69,11 +72,20 @@ public List getErrors() { } /** - * @return the {@link List} of mocked out messages. + * @return the {@link List} of mocked stdout messages. */ public List getOuts() { - return this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).collect(Collectors.toList()); + return this.outputMessages.stream().filter(output -> !output.error()).map(OutputMessage::message).collect(Collectors.toList()); + + } + + /** + * @return the {@link List} of mocked {@link OutputMessage}. + */ + public List getOutputMessages() { + + return this.outputMessages; } diff --git a/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java b/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java index 9d56664a1..e82e8789c 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java @@ -19,6 +19,7 @@ import com.devonfw.tools.ide.context.ProcessContextGitMock; import com.devonfw.tools.ide.io.FileAccess; import com.devonfw.tools.ide.io.FileAccessImpl; +import com.devonfw.tools.ide.process.OutputMessage; /** * Test of {@link GitContext}. @@ -89,7 +90,8 @@ public void testRunGitPullWithoutForce(@TempDir Path tempDir) { // arrange String gitRepoUrl = "https://github.com/test"; IdeTestContext context = newGitContext(tempDir); - this.processContext.getOuts().add("test-remote"); + OutputMessage outputMessage = new OutputMessage(false, "test-remote"); + this.processContext.getOutputMessages().add(outputMessage); FileAccess fileAccess = new FileAccessImpl(context); Path gitFolderPath = tempDir.resolve(".git"); fileAccess.mkdirs(gitFolderPath); From f0c5b9e6c391e68c228ecc3b25903cc404a03240 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:00:53 +0100 Subject: [PATCH 09/15] add test --- .../com/devonfw/tools/ide/process/ProcessResult.java | 6 ++++++ .../devonfw/tools/ide/process/ProcessResultImpl.java | 7 ++++--- .../tools/ide/process/ProcessContextImplTest.java | 12 ++++++++++++ cli/src/test/resources/process-context/log-order.sh | 6 ++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 cli/src/test/resources/process-context/log-order.sh diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java index 85a6d6bbb..e97348b77 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java @@ -76,6 +76,12 @@ default boolean isSuccessful() { */ List getErr(); + /** + * @return the {@link List} with {@link OutputMessage} that captured on standard out and standard error lines. Will be {@code null} if not captured but + * redirected. + */ + List getOutputMessages(); + /** * Logs output and error messages on the provided log level. * diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index e7af1a2fe..868b408f8 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -32,7 +32,7 @@ public class ProcessResultImpl implements ProcessResult { * @param executable the {@link #getExecutable() executable}. * @param command the {@link #getCommand() command}. * @param exitCode the {@link #getExitCode() exit code}. - * @param output {@link #getOutputMessages() output Messages}. + * @param outputMessages {@link #getOutputMessages() output Messages}. */ public ProcessResultImpl(String executable, String command, int exitCode, List outputMessages) { @@ -66,15 +66,16 @@ public int getExitCode() { @Override public List getOut() { - return outputMessages.stream().filter(output -> !output.error()).map(OutputMessage::message).collect(Collectors.toList()); + return this.out; } @Override public List getErr() { - return outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); + return this.err; } + @Override public List getOutputMessages() { return outputMessages; diff --git a/cli/src/test/java/com/devonfw/tools/ide/process/ProcessContextImplTest.java b/cli/src/test/java/com/devonfw/tools/ide/process/ProcessContextImplTest.java index cc44398b8..251c318b7 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/process/ProcessContextImplTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/process/ProcessContextImplTest.java @@ -221,6 +221,18 @@ public void enablingCaptureShouldRedirectAndCaptureStreamsWithErrorsCorrectly() assertThat(context).log(IdeLogLevel.ERROR).hasMessageContaining("another error message to stderr"); } + @Test + public void defaultCaptureShouldCaptureStreamsWithCorrectOrder() { + // arrange + IdeTestContext context = newContext(PROJECT_BASIC, null, false); + + // act + context.newProcess().executable(TEST_RESOURCES.resolve("process-context").resolve("log-order.sh")).run(); + + // assert + assertThat(context).log(IdeLogLevel.INFO).hasEntries("out1", "err1", "out2", "err2"); + } + private IdeLogLevel convertToIdeLogLevel(ProcessErrorHandling processErrorHandling) { return switch (processErrorHandling) { diff --git a/cli/src/test/resources/process-context/log-order.sh b/cli/src/test/resources/process-context/log-order.sh new file mode 100644 index 000000000..25ab60f7b --- /dev/null +++ b/cli/src/test/resources/process-context/log-order.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "out1" +echo "err1" >&2 +sleep 5 +echo "out2" +echo "err2" >&2 From 4daec097ad2d9f0ee90eb34d1142ebe8966b0563 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:09:37 +0100 Subject: [PATCH 10/15] remove forgotten outs in ProcessContextGitMock --- .../com/devonfw/tools/ide/context/ProcessContextGitMock.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java index c584c4ec2..7caa5caea 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java @@ -31,8 +31,6 @@ public class ProcessContextGitMock implements ProcessContext { private final Path directory; - private final List outs; - /** * @param directory the {@link Path} to the git repository. */ @@ -42,7 +40,6 @@ public ProcessContextGitMock(Path directory) { this.outputMessages = new ArrayList<>(); this.exitCode = ProcessResult.SUCCESS; this.directory = directory; - this.outs = new ArrayList<>(); this.now = LocalDateTime.now(); } From 4bbb603d77af057611dda4736bd0554867204b11 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:59:09 +0100 Subject: [PATCH 11/15] add CHANGELOG.adoc --- CHANGELOG.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index b2a80209f..df12b8305 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -10,6 +10,7 @@ Then run the `setup` and all should work fine. Release with new features and bugfixes: +* https://github.com/devonfw/IDEasy/issues/734[#734]: Improve ProcessResult: get out and err in order * https://github.com/devonfw/IDEasy/issues/774[#774]: HTTP proxy support not working properly * https://github.com/devonfw/IDEasy/issues/792[#792]: Honor new variable IDE_OPTIONS in ide command wrapper * https://github.com/devonfw/IDEasy/issues/589[#589]: Fix NLS Bundles for Linux and MacOS From d7e176e80035e1b2ae7cb8761b7a6b6f04c784f9 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:26:53 +0100 Subject: [PATCH 12/15] refactor to lazy getter and remove err and out attributes --- .../devonfw/tools/ide/process/ProcessResultImpl.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index 868b408f8..686c4bd18 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -20,10 +20,6 @@ public class ProcessResultImpl implements ProcessResult { private final int exitCode; - private final List out; - - private final List err; - private final List outputMessages; /** @@ -41,8 +37,6 @@ public ProcessResultImpl(String executable, String command, int exitCode, List !outputMessage.error()).map(OutputMessage::message).collect(Collectors.toList()); - this.err = this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); } @Override @@ -66,13 +60,13 @@ public int getExitCode() { @Override public List getOut() { - return this.out; + return this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).toList(); } @Override public List getErr() { - return this.err; + return this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).toList(); } @Override From ffd6ced1b72f294707fab9b9f215151e5a4db763 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:27:42 +0100 Subject: [PATCH 13/15] change from synchronized approach to ConcurrentLinkedQueue --- .../tools/ide/process/ProcessContextImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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); From 4c5f98a84465b54a0972622dbacc1a3a24c92714 Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:05:43 +0100 Subject: [PATCH 14/15] refactor doLog function to output level based stdout and stderr --- .../tools/ide/process/ProcessResultImpl.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index 686c4bd18..fbb489667 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import com.devonfw.tools.ide.cli.CliProcessException; import com.devonfw.tools.ide.context.IdeContext; @@ -72,7 +71,7 @@ public List getErr() { @Override public List getOutputMessages() { - return outputMessages; + return this.outputMessages; } @@ -85,18 +84,22 @@ public void log(IdeLogLevel level, IdeContext context) { public void log(IdeLogLevel outLevel, IdeContext context, IdeLogLevel errorLevel) { if (!this.outputMessages.isEmpty()) { - doLog(outLevel, getOutputMessages().stream().map(OutputMessage::message).collect(Collectors.toList()), context); + for (OutputMessage outputMessage : this.outputMessages) { + if (outputMessage.error()) { + doLog(errorLevel, outputMessage.message(), context); + } else { + doLog(outLevel, outputMessage.message(), context); + } + } } } - private void doLog(IdeLogLevel level, List lines, IdeContext context) { - for (String line : lines) { - // remove !MESSAGE from log message - if (line.startsWith("!MESSAGE ")) { - line = line.substring(9); - } - context.level(level).log(line); + private void doLog(IdeLogLevel level, String message, IdeContext context) { + // remove !MESSAGE from log message + if (message.startsWith("!MESSAGE ")) { + message = message.substring(9); } + context.level(level).log(message); } @Override From dce5d5af4a7eda008f56135b0ddbc97fe24698aa Mon Sep 17 00:00:00 2001 From: alfeilex <101652401+alfeilex@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:49:55 +0100 Subject: [PATCH 15/15] add ProcessResult to ProcessContextGitMock and remove redundant --- .../tools/ide/process/ProcessContextImpl.java | 1 + .../ide/context/ProcessContextGitMock.java | 47 ++++++++----------- .../devonfw/tools/ide/git/GitContextTest.java | 13 +++-- 3 files changed, 29 insertions(+), 32 deletions(-) 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 5556236fd..6b31213de 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 @@ -219,6 +219,7 @@ public ProcessResult run(ProcessMode processMode) { * "https://stackoverflow.com/questions/14165517/processbuilder-forwarding-stdout-and-stderr-of-started-processes-without-blocki/57483714#57483714">StackOverflow * * @param is {@link InputStream}. + * @param errorStream to identify if the output came from stdout or stderr * @return {@link CompletableFuture}. */ private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, ConcurrentLinkedQueue outputMessages) { diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java index 7caa5caea..405e834cf 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/ProcessContextGitMock.java @@ -7,7 +7,6 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import com.devonfw.tools.ide.process.OutputMessage; import com.devonfw.tools.ide.process.ProcessContext; @@ -23,67 +22,58 @@ public class ProcessContextGitMock implements ProcessContext { private final List arguments; - private final List outputMessages; - private final LocalDateTime now; private int exitCode; private final Path directory; + private ProcessResult processResult; + /** * @param directory the {@link Path} to the git repository. */ public ProcessContextGitMock(Path directory) { this.arguments = new ArrayList<>(); - this.outputMessages = new ArrayList<>(); + this.processResult = new ProcessResultImpl("git", "", 0, new ArrayList<>()); this.exitCode = ProcessResult.SUCCESS; this.directory = directory; this.now = LocalDateTime.now(); } /** - * @return the mocked {@link ProcessResult#getExitCode() exit code}. + * @return the mocked {@link ProcessResult} */ - public int getExitCode() { + public ProcessResult getProcessResult() { - return this.exitCode; + return this.processResult; } /** * @param exitCode the {@link #getExitCode() exit code}. + * @param output the list of {@link OutputMessage}} + * @return the mocked {@link ProcessResult} */ - public void setExitCode(int exitCode) { + public void setProcessResult(int exitCode, List output) { - this.exitCode = exitCode; + this.processResult = new ProcessResultImpl("git", "", exitCode, output); } /** - * @return the {@link List} of mocked stderr messages. - */ - public List getErrors() { - - return this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).collect(Collectors.toList()); - - } - - /** - * @return the {@link List} of mocked stdout messages. + * @return the mocked {@link ProcessResult#getExitCode() exit code}. */ - public List getOuts() { - - return this.outputMessages.stream().filter(output -> !output.error()).map(OutputMessage::message).collect(Collectors.toList()); + public int getExitCode() { + return this.exitCode; } /** - * @return the {@link List} of mocked {@link OutputMessage}. + * @param exitCode the {@link #getExitCode() exit code}. */ - public List getOutputMessages() { - - return this.outputMessages; + public void setExitCode(int exitCode) { + this.exitCode = exitCode; } @Override @@ -150,7 +140,7 @@ public ProcessResult run(ProcessMode processMode) { if (this.arguments.contains("ls-files")) { if (Files.exists(this.directory.resolve("new-folder"))) { OutputMessage outputMessage = new OutputMessage(false, "new-folder"); - this.outputMessages.add(outputMessage); + processResult.getOutputMessages().add(outputMessage); this.exitCode = 0; } } @@ -192,7 +182,8 @@ public ProcessResult run(ProcessMode processMode) { } } this.arguments.clear(); - return new ProcessResultImpl("git", command.toString(), this.exitCode, this.outputMessages); + setProcessResult(getExitCode(), this.processResult.getOutputMessages()); + return this.processResult; } } diff --git a/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java b/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java index e82e8789c..2ab98427d 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/git/GitContextTest.java @@ -35,6 +35,8 @@ private IdeTestContext newGitContext(Path dir) { this.processContext = new ProcessContextGitMock(dir); context.setProcessContext(processContext); context.setGitContext(new GitContextImpl(context)); + // reset ProcessResult instance + this.processContext.setProcessResult(0, new ArrayList<>()); return context; } @@ -72,7 +74,8 @@ public void testRunGitClone(@TempDir Path tempDir) { // arrange String gitRepoUrl = "https://github.com/test"; IdeTestContext context = newGitContext(tempDir); - this.processContext.getOuts().add("test-remote"); + OutputMessage outputMessage = new OutputMessage(false, "test-remote"); + this.processContext.getProcessResult().getOutputMessages().add(outputMessage); // act context.getGitContext().pullOrClone(GitUrl.of(gitRepoUrl), tempDir); // assert @@ -91,7 +94,7 @@ public void testRunGitPullWithoutForce(@TempDir Path tempDir) { String gitRepoUrl = "https://github.com/test"; IdeTestContext context = newGitContext(tempDir); OutputMessage outputMessage = new OutputMessage(false, "test-remote"); - this.processContext.getOutputMessages().add(outputMessage); + this.processContext.getProcessResult().getOutputMessages().add(outputMessage); FileAccess fileAccess = new FileAccessImpl(context); Path gitFolderPath = tempDir.resolve(".git"); fileAccess.mkdirs(gitFolderPath); @@ -131,7 +134,8 @@ public void testRunGitPullWithForceStartsReset(@TempDir Path tempDir) { throw new RuntimeException(e); } IdeTestContext context = newGitContext(tempDir); - this.processContext.getOuts().add("test-remote"); + OutputMessage outputMessage = new OutputMessage(false, "test-remote"); + this.processContext.getProcessResult().getOutputMessages().add(outputMessage); // act context.getGitContext().pullOrCloneAndResetIfNeeded(new GitUrl(gitRepoUrl, "master"), tempDir, "origin"); // assert @@ -149,7 +153,8 @@ public void testRunGitPullWithForceStartsCleanup(@TempDir Path tempDir) { // arrange String gitRepoUrl = "https://github.com/test"; IdeTestContext context = newGitContext(tempDir); - this.processContext.getOuts().add("test-remote"); + OutputMessage outputMessage = new OutputMessage(false, "test-remote"); + this.processContext.getProcessResult().getOutputMessages().add(outputMessage); GitContext gitContext = context.getGitContext(); FileAccess fileAccess = context.getFileAccess(); Path gitFolderPath = tempDir.resolve(".git");