Skip to content
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

[MNG-8334] Returns redirect to log #1824

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -320,15 +322,36 @@ protected void configureLogging(C context) throws Exception {
}

protected Terminal createTerminal(C context) {
return new FastTerminal(
() -> TerminalBuilder.builder()
.name("Maven")
.streams(
context.invokerRequest.in().orElse(null),
context.invokerRequest.out().orElse(null))
.dumb(true)
.build(),
terminal -> doConfigureWithTerminal(context, terminal));
if (context.invokerRequest.options().logFile().isPresent()) {
Path logFile = context.cwdResolver.apply(
context.invokerRequest.options().logFile().get());
try {
OutputStream stdout = Files.newOutputStream(logFile);
PrintStream ps = new PrintStream(stdout);
System.setOut(ps);
System.setErr(ps);

return new FastTerminal(
() -> TerminalBuilder.builder()
.name("Maven")
.streams(context.invokerRequest.in().orElse(null), stdout)
.dumb(true)
.build(),
terminal -> doConfigureWithTerminal(context, terminal));
} catch (IOException e) {
throw new MavenException("Unable to redirect logging to " + logFile, e);
}
} else {
return new FastTerminal(
() -> TerminalBuilder.builder()
.name("Maven")
.streams(
context.invokerRequest.in().orElse(null),
context.invokerRequest.out().orElse(null))
.dumb(true)
.build(),
terminal -> doConfigureWithTerminal(context, terminal));
}
}

protected void doConfigureWithTerminal(C context, Terminal terminal) {
Expand Down Expand Up @@ -357,26 +380,13 @@ protected BuildEventListener determineBuildEventListener(C context) {
}

protected BuildEventListener doDetermineBuildEventListener(C context) {
BuildEventListener bel;
O options = context.invokerRequest.options();
if (options.logFile().isPresent()) {
Path logFile = context.cwdResolver.apply(options.logFile().get());
try {
PrintWriter printWriter = new PrintWriter(Files.newBufferedWriter(logFile));
bel = new SimpleBuildEventListener(printWriter::println);
} catch (IOException e) {
throw new MavenException("Unable to redirect logging to " + logFile, e);
}
} else {
// Given the terminal creation has been offloaded to a different thread,
// do not pass directory the terminal writer
bel = new SimpleBuildEventListener(msg -> {
PrintWriter pw = context.terminal.writer();
pw.println(msg);
pw.flush();
});
}
return bel;
// Given the terminal creation has been offloaded to a different thread,
// do not pass directory the terminal writer
return new SimpleBuildEventListener(msg -> {
PrintWriter pw = context.terminal.writer();
pw.println(msg);
pw.flush();
});
}

protected void activateLogging(C context) throws Exception {
Expand Down