Skip to content

Commit

Permalink
Fix IT related to raw streams
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 15, 2024
1 parent 6602046 commit 92dd40c
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
package org.apache.maven.cli;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Optional;

import org.apache.maven.api.cli.InvokerException;
import org.apache.maven.api.cli.InvokerRequest;
import org.apache.maven.api.cli.Options;
Expand All @@ -40,11 +45,17 @@ public DaemonMavenInvoker(ProtoLookup protoLookup) {

@Override
protected Terminal createTerminal(ResidentMavenContext context) {
InputStream in = context.invokerRequest.in().orElseThrow();
OutputStream out = context.invokerRequest.out().orElseThrow();
OutputStream err = context.invokerRequest.err().orElseThrow();
Optional<Boolean> rawStreams = context.invokerRequest.options().rawStreams();
if (rawStreams.isPresent() && rawStreams.get()) {
System.setOut(printStream(out));
System.setErr(printStream(err));
}
MessageUtils.systemInstall(
builder -> {
builder.streams(
context.invokerRequest.in().get(),
context.invokerRequest.out().get());
builder.streams(in, out);
builder.systemOutput(TerminalBuilder.SystemOutput.ForcedSysOut);
builder.provider(TerminalBuilder.PROP_PROVIDER_EXEC);
if (context.coloredOutput != null) {
Expand All @@ -55,6 +66,16 @@ protected Terminal createTerminal(ResidentMavenContext context) {
return MessageUtils.getTerminal();
}

private PrintStream printStream(OutputStream outputStream) {
if (outputStream instanceof LoggingOutputStream los) {
return los.printStream();
} else if (outputStream instanceof PrintStream ps) {
return ps;
} else {
return new PrintStream(outputStream);
}
}

@Override
protected org.apache.maven.logging.BuildEventListener doDetermineBuildEventListener(ResidentMavenContext context) {
return context.invokerRequest.lookup().lookup(BuildEventListener.class);
Expand Down

0 comments on commit 92dd40c

Please sign in to comment.