restore display of two build properties (as in 2.x) :

- svn rev 
- build timestamp

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@784274 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2009-06-12 21:09:06 +00:00
parent 8a43011d41
commit d5eae80ab1
3 changed files with 101 additions and 7 deletions

View File

@ -86,6 +86,12 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
@ -112,4 +118,35 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>svn-buildnumber</id>
<activation>
<file>
<exists>.svn</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,3 @@
buildNumber=${buildNumber}
timestamp=${timestamp}
version=${project.version}

View File

@ -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 : "<version unknown>" );
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", "<unknown java version>" ) );
System.out.println( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) );
System.out.println( "Default locale: " + Locale.getDefault() + ", platform encoding: "
+ System.getProperty( "file.encoding", "<unknown encoding>" ) );
+ System.getProperty( "file.encoding", "<unknown 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 @@ private static String getFormattedTime( long time )
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;
}
}