diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index ba10ddba9a5..ef254920256 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -18,25 +18,6 @@ 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.HttpField; 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.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. * 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. 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) { LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!"); diff --git a/jetty-util/pom.xml b/jetty-util/pom.xml index 01247b15a96..4dfc616eb0b 100644 --- a/jetty-util/pom.xml +++ b/jetty-util/pom.xml @@ -13,6 +13,12 @@ ${project.groupId}.util + + + src/main/resources + true + + org.codehaus.mojo @@ -21,6 +27,23 @@ org.eclipse.jetty.util.* + + org.codehaus.mojo + buildnumber-maven-plugin + + + create-buildnumber + + create + + + false + false + ${nonCanonicalRevision} + + + + diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java index 8b0f739163b..13e7d50b5bd 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java @@ -18,14 +18,50 @@ 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 { + private static final Logger LOG = Log.getLogger( Jetty.class); + public static final String VERSION; public static final String POWERED_BY; 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 { + 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(); if (pkg != null && "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && @@ -43,5 +79,20 @@ public class Jetty private 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"; + } + } } diff --git a/jetty-util/src/main/resources/org/eclipse/jetty/version/build.properties b/jetty-util/src/main/resources/org/eclipse/jetty/version/build.properties new file mode 100644 index 00000000000..c9d20227f6c --- /dev/null +++ b/jetty-util/src/main/resources/org/eclipse/jetty/version/build.properties @@ -0,0 +1,4 @@ +buildNumber=${buildNumber} +timestamp=${timestamp} +version=${project.version} +scmUrl=${project.scm.connection} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1be55c3da85..ff277f9c4fc 100644 --- a/pom.xml +++ b/pom.xml @@ -842,6 +842,11 @@ + + org.codehaus.mojo + buildnumber-maven-plugin + 1.4 +