mirror of https://github.com/apache/maven.git
[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
This commit is contained in:
parent
3c3b778d03
commit
2e1d7433ff
|
@ -47,14 +47,39 @@ public final class CLIReportingUtils
|
||||||
public static final int MS_PER_SEC = 1000;
|
public static final int MS_PER_SEC = 1000;
|
||||||
|
|
||||||
public static final int SEC_PER_MIN = 60;
|
public static final int SEC_PER_MIN = 60;
|
||||||
|
|
||||||
|
public static final String BUILD_VERSION_PROPERTY = "version";
|
||||||
|
|
||||||
public static void showVersion( PrintStream stdout )
|
public static void showVersion( PrintStream stdout )
|
||||||
{
|
{
|
||||||
Properties properties = getBuildProperties();
|
Properties properties = getBuildProperties();
|
||||||
|
stdout.println( createMavenVersionString( properties ) );
|
||||||
|
|
||||||
String timestamp = reduce( properties.getProperty( "timestamp" ) );
|
stdout.println( "Maven home: " + System.getProperty( "maven.home", "<unknown maven home>" ) );
|
||||||
String version = reduce( properties.getProperty( "version" ) );
|
|
||||||
String rev = reduce( properties.getProperty( "buildNumber" ) );
|
stdout.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" )
|
||||||
|
+ ", vendor: " + System.getProperty( "java.vendor", "<unknown vendor>" ) );
|
||||||
|
|
||||||
|
stdout.println( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) );
|
||||||
|
|
||||||
|
stdout.println( "Default locale: " + Locale.getDefault() + ", platform encoding: "
|
||||||
|
+ System.getProperty( "file.encoding", "<unknown 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 ";
|
String msg = "Apache Maven ";
|
||||||
msg += ( version != null ? version : "<version unknown>" );
|
msg += ( version != null ? version : "<version unknown>" );
|
||||||
|
@ -70,21 +95,7 @@ public final class CLIReportingUtils
|
||||||
}
|
}
|
||||||
msg += ")";
|
msg += ")";
|
||||||
}
|
}
|
||||||
|
return msg;
|
||||||
stdout.println( msg );
|
|
||||||
|
|
||||||
stdout.println( "Maven home: " + System.getProperty( "maven.home", "<unknown maven home>" ) );
|
|
||||||
|
|
||||||
stdout.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" )
|
|
||||||
+ ", vendor: " + System.getProperty( "java.vendor", "<unknown vendor>" ) );
|
|
||||||
|
|
||||||
stdout.println( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) );
|
|
||||||
|
|
||||||
stdout.println( "Default locale: " + Locale.getDefault() + ", platform encoding: "
|
|
||||||
+ System.getProperty( "file.encoding", "<unknown encoding>" ) );
|
|
||||||
|
|
||||||
stdout.println( "OS name: \"" + Os.OS_NAME + "\", version: \"" + Os.OS_VERSION + "\", arch: \"" + Os.OS_ARCH
|
|
||||||
+ "\", family: \"" + Os.OS_FAMILY + "\"" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String reduce( String s )
|
private static String reduce( String s )
|
||||||
|
|
|
@ -1064,6 +1064,19 @@ public class MavenCli
|
||||||
}
|
}
|
||||||
|
|
||||||
systemProperties.putAll( System.getProperties() );
|
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 )
|
private static void setCliProperty( String property, Properties properties )
|
||||||
|
|
Loading…
Reference in New Issue