diff --git a/maven-core/pom.xml b/maven-core/pom.xml index f7d14ea479..385cfbb450 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -86,6 +86,12 @@ + + + src/main/resources + true + + org.codehaus.plexus @@ -112,4 +118,35 @@ + + + svn-buildnumber + + + .svn + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.0-beta-1 + + + generate-resources + + create + + + + + false + false + + + + + + diff --git a/maven-core/src/main/resources/org/apache/maven/messages/build.properties b/maven-core/src/main/resources/org/apache/maven/messages/build.properties new file mode 100644 index 0000000000..a5fd160b61 --- /dev/null +++ b/maven-core/src/main/resources/org/apache/maven/messages/build.properties @@ -0,0 +1,3 @@ +buildNumber=${buildNumber} +timestamp=${timestamp} +version=${project.version} 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 3ea25183f4..5a9da1f651 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 @@ -1,14 +1,18 @@ package org.apache.maven.cli; +import java.io.IOException; +import java.io.InputStream; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.Properties; import java.util.TimeZone; import org.apache.maven.embedder.MavenEmbedderLogger; import org.apache.maven.execution.ApplicationInformation; import org.apache.maven.execution.DefaultRuntimeInformation; +import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.Os; /** @@ -28,24 +32,48 @@ public final class CLIReportingUtils private static final String NEWLINE = System.getProperty( "line.separator" ); - static void showVersion() + public static void showVersion() { - ApplicationInformation ai = - DefaultRuntimeInformation.getVersion( MavenCli.class.getClassLoader(), "org.apache.maven", "maven-core" ); + Properties properties = getBuildProperties(); - System.out.println( "Maven version: " + ai.getVersion() + " built on " + ai.getBuiltOn() ); + String timestamp = reduce( properties.getProperty( "timestamp" ) ); + String version = reduce( properties.getProperty( "version" ) ); + String rev = reduce( properties.getProperty( "buildNumber" ) ); + + String msg = "Apache Maven "; + msg += ( version != null ? version : "" ); + if ( rev != null || timestamp != null ) + { + msg += " ("; + msg += ( rev != null ? "r" + rev : "" ); + if ( timestamp != null ) + { + SimpleDateFormat fmt = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ssZ" ); + String ts = fmt.format( new Date( Long.valueOf( timestamp ).longValue() ) ); + msg += ( rev != null ? "; " : "" ) + ts; + } + msg += ")"; + } + + System.out.println( msg ); System.out.println( "Java version: " + System.getProperty( "java.version", "" ) ); System.out.println( "Java home: " + System.getProperty( "java.home", "" ) ); System.out.println( "Default locale: " + Locale.getDefault() + ", platform encoding: " - + System.getProperty( "file.encoding", "" ) ); + + System.getProperty( "file.encoding", "" ) ); - System.out.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION + "\" arch: \"" + Os.OS_ARCH - + "\" family: \"" + Os.OS_FAMILY + "\"" ); + System.out.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION + + "\" arch: \"" + Os.OS_ARCH + "\" Family: \"" + Os.OS_FAMILY + "\"" ); } + private static String reduce( String s ) + { + return ( s != null ? ( s.startsWith( "${" ) && s.endsWith( "}" ) ? null : s ) : null ); + } + + private static void stats( Date start, MavenEmbedderLogger logger ) { Date finish = new Date(); @@ -113,4 +141,30 @@ public final class CLIReportingUtils fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); return fmt.format( new Date( time ) ); } + + static Properties getBuildProperties() + { + Properties properties = new Properties(); + InputStream resourceAsStream = null; + try + { + resourceAsStream = MavenCli.class.getClassLoader().getResourceAsStream( "org/apache/maven/messages/build.properties" ); + + if ( resourceAsStream != null ) + { + properties.load( resourceAsStream ); + } + } + catch ( IOException e ) + { + System.err.println( "Unable determine version from JAR file: " + e.getMessage() ); + } + finally + { + IOUtil.close( resourceAsStream ); + } + + return properties; + } + }