From 7a8acdd8e66de81b4f7f918905976191837bf147 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 3 Jul 2021 19:17:19 +0200 Subject: [PATCH] [MNG-7181] Make --version support -q --- .../java/org/apache/maven/cli/CLIReportingUtils.java | 7 +++++++ .../src/main/java/org/apache/maven/cli/MavenCli.java | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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 97a2db65bd..57be196329 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 @@ -75,6 +75,13 @@ public final class CLIReportingUtils return version.toString(); } + public static String showVersionMinimal() + { + Properties properties = getBuildProperties(); + String version = reduce( properties.getProperty( BUILD_VERSION_PROPERTY ) ); + return ( version != null ? version : "" ); + } + /** * Create a human readable string containing the Maven version, buildnumber, and time of build * diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index feed90561d..fbcb05f913 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -433,7 +433,14 @@ public class MavenCli if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) ) { - System.out.println( CLIReportingUtils.showVersion() ); + if ( cliRequest.commandLine.hasOption( CLIManager.QUIET ) ) + { + System.out.println( CLIReportingUtils.showVersionMinimal() ); + } + else + { + System.out.println( CLIReportingUtils.showVersion() ); + } throw new ExitException( 0 ); } }