From 2e1d7433ffb4d125b0e3501c776a571a61cdd57c Mon Sep 17 00:00:00 2001 From: Paul Gier Date: Sun, 17 Jul 2011 13:16:12 +0000 Subject: [PATCH] [MNG-4112] Add properties "maven.version" and "maven.build.version" which contain the current version of Maven git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1147597 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/cli/CLIReportingUtils.java | 47 ++++++++++++------- .../java/org/apache/maven/cli/MavenCli.java | 13 +++++ 2 files changed, 42 insertions(+), 18 deletions(-) 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 b529f0bc82..06227a18ce 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 @@ -47,14 +47,39 @@ public final class CLIReportingUtils public static final int MS_PER_SEC = 1000; public static final int SEC_PER_MIN = 60; + + public static final String BUILD_VERSION_PROPERTY = "version"; public static void showVersion( PrintStream stdout ) { Properties properties = getBuildProperties(); + stdout.println( createMavenVersionString( properties ) ); - String timestamp = reduce( properties.getProperty( "timestamp" ) ); - String version = reduce( properties.getProperty( "version" ) ); - String rev = reduce( properties.getProperty( "buildNumber" ) ); + stdout.println( "Maven home: " + System.getProperty( "maven.home", "" ) ); + + stdout.println( "Java version: " + System.getProperty( "java.version", "" ) + + ", vendor: " + System.getProperty( "java.vendor", "" ) ); + + stdout.println( "Java home: " + System.getProperty( "java.home", "" ) ); + + stdout.println( "Default locale: " + Locale.getDefault() + ", platform encoding: " + + System.getProperty( "file.encoding", "" ) ); + + stdout.println( "OS name: \"" + Os.OS_NAME + "\", version: \"" + Os.OS_VERSION + "\", arch: \"" + Os.OS_ARCH + + "\", family: \"" + Os.OS_FAMILY + "\"" ); + } + + /** + * Create a human readable string containing the Maven version, buildnumber, and time of build + * + * @param buildProperties The build properties + * @return Readable build info + */ + static String createMavenVersionString( Properties buildProperties ) + { + String timestamp = reduce( buildProperties.getProperty( "timestamp" ) ); + String version = reduce( buildProperties.getProperty( BUILD_VERSION_PROPERTY ) ); + String rev = reduce( buildProperties.getProperty( "buildNumber" ) ); String msg = "Apache Maven "; msg += ( version != null ? version : "" ); @@ -70,21 +95,7 @@ public final class CLIReportingUtils } msg += ")"; } - - stdout.println( msg ); - - stdout.println( "Maven home: " + System.getProperty( "maven.home", "" ) ); - - stdout.println( "Java version: " + System.getProperty( "java.version", "" ) - + ", vendor: " + System.getProperty( "java.vendor", "" ) ); - - stdout.println( "Java home: " + System.getProperty( "java.home", "" ) ); - - stdout.println( "Default locale: " + Locale.getDefault() + ", platform encoding: " - + System.getProperty( "file.encoding", "" ) ); - - stdout.println( "OS name: \"" + Os.OS_NAME + "\", version: \"" + Os.OS_VERSION + "\", arch: \"" + Os.OS_ARCH - + "\", family: \"" + Os.OS_FAMILY + "\"" ); + return msg; } private static String reduce( String s ) 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 b8cc4bb4f1..5acd54a115 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 @@ -1064,6 +1064,19 @@ public class MavenCli } systemProperties.putAll( System.getProperties() ); + + // ---------------------------------------------------------------------- + // Properties containing info about the currently running version of Maven + // These override any corresponding properties set on the command line + // ---------------------------------------------------------------------- + + Properties buildProperties = CLIReportingUtils.getBuildProperties(); + + String mavenVersion = buildProperties.getProperty( CLIReportingUtils.BUILD_VERSION_PROPERTY ); + systemProperties.setProperty( "maven.version", mavenVersion ); + + String mavenBuildVersion = CLIReportingUtils.createMavenVersionString( buildProperties ); + systemProperties.setProperty( "maven.build.version", mavenBuildVersion ); } private static void setCliProperty( String property, Properties properties )