This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push: new 69c6a3f95b [MNG-8342] Add command line and terminal information when verbose (#1840) 69c6a3f95b is described below commit 69c6a3f95b51537194e2514d7025efe2e09508da Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Thu Oct 24 13:50:30 2024 +0200 [MNG-8342] Add command line and terminal information when verbose (#1840) --- .../apache/maven/cling/invoker/LookupInvoker.java | 49 ++++++++++++++++++---- .../org/apache/maven/cli/CLIReportingUtils.java | 11 +++++ 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java b/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java index 6f18d0b365..e645ca9989 100644 --- a/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java +++ b/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java @@ -72,6 +72,7 @@ import org.apache.maven.cli.transfer.Slf4jMavenTransferListener; import org.apache.maven.cling.invoker.mvn.ProtoSession; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.internal.impl.SettingsUtilsV4; +import org.apache.maven.jline.FastTerminal; import org.apache.maven.jline.MessageUtils; import org.apache.maven.logging.LoggingOutputStream; import org.apache.maven.logging.api.LogLevelRecorder; @@ -79,6 +80,8 @@ import org.apache.maven.slf4j.MavenSimpleLogger; import org.eclipse.aether.transfer.TransferListener; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; +import org.jline.terminal.impl.AbstractPosixTerminal; +import org.jline.terminal.spi.TerminalExt; import org.slf4j.ILoggerFactory; import org.slf4j.LoggerFactory; import org.slf4j.spi.LocationAwareLogger; @@ -409,26 +412,56 @@ public abstract class LookupInvoker< } protected void helpOrVersionAndMayExit(C context) throws Exception { - Consumer<String> writer = determineWriter(context); R invokerRequest = context.invokerRequest; if (invokerRequest.options().help().isPresent()) { + Consumer<String> writer = determineWriter(context); invokerRequest.options().displayHelp(context.invokerRequest.parserRequest(), writer); throw new ExitException(0); } if (invokerRequest.options().showVersionAndExit().isPresent()) { - if (invokerRequest.options().quiet().orElse(false)) { - writer.accept(CLIReportingUtils.showVersionMinimal()); - } else { - writer.accept(CLIReportingUtils.showVersion()); - } + showVersion(context); throw new ExitException(0); } } + protected void showVersion(C context) { + Consumer<String> writer = determineWriter(context); + R invokerRequest = context.invokerRequest; + if (invokerRequest.options().quiet().orElse(false)) { + writer.accept(CLIReportingUtils.showVersionMinimal()); + } else if (invokerRequest.options().verbose().orElse(false)) { + writer.accept(CLIReportingUtils.showVersion( + ProcessHandle.current().info().commandLine().orElse(null), describe(context.terminal))); + + } else { + writer.accept(CLIReportingUtils.showVersion()); + } + } + + protected String describe(Terminal terminal) { + if (terminal == null) { + return null; + } + if (terminal instanceof FastTerminal ft) { + terminal = ft.getTerminal(); + } + List<String> subs = new ArrayList<>(); + subs.add("type=" + terminal.getType()); + if (terminal instanceof TerminalExt te) { + subs.add("provider=" + te.getProvider().name()); + } + if (terminal instanceof AbstractPosixTerminal pt) { + subs.add("pty=" + pt.getPty().getClass().getName()); + } + return terminal.getClass().getSimpleName() + " (" + String.join(", ", subs) + ")"; + } + protected void preCommands(C context) throws Exception { Options mavenOptions = context.invokerRequest.options(); - if (mavenOptions.verbose().orElse(false) || mavenOptions.showVersion().orElse(false)) { - determineWriter(context).accept(CLIReportingUtils.showVersion()); + boolean verbose = mavenOptions.verbose().orElse(false); + boolean version = mavenOptions.showVersion().orElse(false); + if (verbose || version) { + showVersion(context); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index 897fc7c5ec..21d2c63d3d 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -49,6 +49,10 @@ public final class CLIReportingUtils { public static final String BUILD_VERSION_PROPERTY = "version"; public static String showVersion() { + return showVersion(null, null); + } + + public static String showVersion(String commandLine, String terminal) { final String ls = System.lineSeparator(); Properties properties = getBuildProperties(); StringBuilder version = new StringBuilder(256); @@ -78,6 +82,13 @@ public final class CLIReportingUtils { .append("\", family: \"") .append(Os.OS_FAMILY) .append('\"'); + // Add process information using modern Java API + if (commandLine != null) { + version.append(ls).append("Command line: ").append(commandLine); + } + if (terminal != null) { + version.append(ls).append("Terminal: ").append(terminal); + } return version.toString(); }