From 1fc605dd69f99e91e0685a4f4ba279d2fd2eed21 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 496be2eac6..45fe047001 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 @@ -439,7 +439,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 ); } }