add a build.properties file containing git hash, build timestamp scm url (#1957)

* add a build.properties file containing git hash, build timestamp and scm url #1956

Signed-off-by: olivier lamy <olamy@webtide.com>

* move build infos to Jetty class so it's available for server and client

Signed-off-by: olivier lamy <olamy@webtide.com>

* apply changes by Greg review

Signed-off-by: olivier lamy <olamy@webtide.com>
This commit is contained in:
Olivier Lamy 2017-11-11 04:39:28 +11:00 committed by Greg Wilkins
parent 7ba4428e9f
commit 9fab69ea02
5 changed files with 105 additions and 20 deletions

View File

@ -18,25 +18,6 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.DateGenerator; import org.eclipse.jetty.http.DateGenerator;
import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpGenerator; import org.eclipse.jetty.http.HttpGenerator;
@ -67,6 +48,24 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ShutdownThread; import org.eclipse.jetty.util.thread.ShutdownThread;
import org.eclipse.jetty.util.thread.ThreadPool; import org.eclipse.jetty.util.thread.ThreadPool;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** Jetty HTTP Servlet Server. /** Jetty HTTP Servlet Server.
* This class is the main class for the Jetty HTTP Servlet server. * This class is the main class for the Jetty HTTP Servlet server.
@ -368,7 +367,10 @@ public class Server extends HandlerWrapper implements Attributes
//Start a thread waiting to receive "stop" commands. //Start a thread waiting to receive "stop" commands.
ShutdownMonitor.getInstance().start(); // initialize ShutdownMonitor.getInstance().start(); // initialize
LOG.info("jetty-" + getVersion()); String gitHash = Jetty.GIT_HASH;
String timestamp = Jetty.BUILD_TIMESTAMP;
LOG.info("jetty-{}, build timestamp: {}, git hash: {}", getVersion(), timestamp, gitHash);
if (!Jetty.STABLE) if (!Jetty.STABLE)
{ {
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!"); LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");

View File

@ -13,6 +13,12 @@
<bundle-symbolic-name>${project.groupId}.util</bundle-symbolic-name> <bundle-symbolic-name>${project.groupId}.util</bundle-symbolic-name>
</properties> </properties>
<build> <build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
@ -21,6 +27,23 @@
<onlyAnalyze>org.eclipse.jetty.util.*</onlyAnalyze> <onlyAnalyze>org.eclipse.jetty.util.*</onlyAnalyze>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
<id>create-buildnumber</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>${nonCanonicalRevision}</revisionOnScmFailure>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
<pluginManagement> <pluginManagement>
<plugins> <plugins>

View File

@ -18,14 +18,50 @@
package org.eclipse.jetty.util; package org.eclipse.jetty.util;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
public class Jetty public class Jetty
{ {
private static final Logger LOG = Log.getLogger( Jetty.class);
public static final String VERSION; public static final String VERSION;
public static final String POWERED_BY; public static final String POWERED_BY;
public static final boolean STABLE; public static final boolean STABLE;
public static final String GIT_HASH;
/**
* a formatted build timestamp with pattern yyyy-MM-dd'T'HH:mm:ssXXX
*/
public static final String BUILD_TIMESTAMP;
private static final Properties __buildProperties = new Properties( );
static static
{ {
try
{
try (InputStream inputStream = //
Jetty.class.getResourceAsStream( "/org/eclipse/jetty/version/build.properties" ))
{
__buildProperties.load( inputStream );
}
}
catch ( Exception e )
{
LOG.ignore( e );
}
GIT_HASH = __buildProperties.getProperty( "buildNumber", "unknown" );
System.setProperty( "jetty.git.hash" , GIT_HASH );
BUILD_TIMESTAMP = formatTimestamp( __buildProperties.getProperty( "timestamp", "unknown" ));
// using __buildProperties.getProperty("version") will contain version from the pom
Package pkg = Jetty.class.getPackage(); Package pkg = Jetty.class.getPackage();
if (pkg != null && if (pkg != null &&
"Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) &&
@ -44,4 +80,19 @@ public class Jetty
{ {
} }
private static String formatTimestamp( String timestamp )
{
try
{
return new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssXXX" )
.format( new Date( Long.valueOf( timestamp ) ) );
}
catch ( NumberFormatException e )
{
LOG.debug( e );
return "unknown";
}
}
} }

View File

@ -0,0 +1,4 @@
buildNumber=${buildNumber}
timestamp=${timestamp}
version=${project.version}
scmUrl=${project.scm.connection}

View File

@ -841,6 +841,11 @@
</lifecycleMappingMetadata> </lifecycleMappingMetadata>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>