-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#734: Improve Process Result Model #773
base: main
Are you sure you want to change the base?
Changes from 6 commits
e25575f
8e66739
5c3cccb
4d5a556
daf4b45
05879d1
292aa5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,14 +167,15 @@ public ProcessResult run(ProcessMode processMode) { | |
|
||
this.processBuilder.command(args); | ||
|
||
List<LogEvent> logs = new ArrayList<>(); | ||
List<String> out = null; | ||
List<String> err = null; | ||
|
||
Process process = this.processBuilder.start(); | ||
|
||
if (processMode == ProcessMode.DEFAULT_CAPTURE) { | ||
CompletableFuture<List<String>> outFut = readInputStream(process.getInputStream()); | ||
CompletableFuture<List<String>> errFut = readInputStream(process.getErrorStream()); | ||
CompletableFuture<List<String>> outFut = readInputStream(process.getInputStream(), false, logs); | ||
CompletableFuture<List<String>> errFut = readInputStream(process.getErrorStream(), true, logs); | ||
out = outFut.get(); | ||
err = errFut.get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove |
||
} | ||
|
@@ -187,10 +188,9 @@ public ProcessResult run(ProcessMode processMode) { | |
exitCode = process.waitFor(); | ||
} | ||
|
||
ProcessResult result = new ProcessResultImpl(exitCode, out, err); | ||
ProcessResult result = new ProcessResultImpl(exitCode, out, err, logs); | ||
|
||
performLogging(result, exitCode, interpreter); | ||
|
||
return result; | ||
|
||
} catch (CliProcessException | IllegalStateException e) { | ||
|
@@ -214,11 +214,19 @@ public ProcessResult run(ProcessMode processMode) { | |
* @param is {@link InputStream}. | ||
* @return {@link CompletableFuture}. | ||
*/ | ||
private static CompletableFuture<List<String>> readInputStream(InputStream is) { | ||
private static CompletableFuture<List<String>> readInputStream(InputStream is, boolean errorStream, List<LogEvent> logs) { | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
try (InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) { | ||
|
||
String line; | ||
while ((line = br.readLine()) != null) { | ||
synchronized (logs) { | ||
LogEvent logEvent = new LogEvent(errorStream, line); | ||
logs.add(logEvent); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, if I am using |
||
} | ||
return br.lines().toList(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException("There was a problem while executing the program", e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be located in the process or log package or elsewhere?