From 6499baa3a20bd8c4a0353e99bd3a026df8b844b7 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 11 Nov 2017 04:39:28 +1100 Subject: [PATCH] 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 * move build infos to Jetty class so it's available for server and client Signed-off-by: olivier lamy * apply changes by Greg review Signed-off-by: olivier lamy --- .../java/org/eclipse/jetty/server/Server.java | 7 +- jetty-util/pom.xml | 23 +++ .../java/org/eclipse/jetty/util/Jetty.java | 51 +++++ .../eclipse/jetty/version/build.properties | 4 + pom.xml | 174 ++++++++++++++++++ 5 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 jetty-util/src/main/resources/org/eclipse/jetty/version/build.properties 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 6ff8e40ebca..7fc41dfb428 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,6 +18,7 @@ package org.eclipse.jetty.server; + import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -68,6 +69,7 @@ import org.eclipse.jetty.util.thread.ShutdownThread; import org.eclipse.jetty.util.thread.ThreadPool; import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool; + /* ------------------------------------------------------------ */ /** Jetty HTTP Servlet Server. * This class is the main class for the Jetty HTTP Servlet server. @@ -343,7 +345,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 5ed9f480b7e..8b3a3d6387e 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 e1c6779d886..fb86392d7f8 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 c0971e98978..87caa1976d7 100644 --- a/pom.xml +++ b/pom.xml @@ -531,6 +531,180 @@ org.eclipse.jetty.* + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.eclipse.jetty.toolchain + jetty-version-maven-plugin + [1.0.3,) + + attach-version-text + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + [2.1,) + + unpack + unpack-dependencies + copy-dependencies + copy + + + + + + + + + org.ops4j.pax.exam + maven-paxexam-plugin + + [1.2.0,) + + + + generate-depends-file + + generate-config + + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + [1.4,) + + run + + + + + + + + + org.sonatype.maven.plugin + emma-maven-plugin + [1.1,) + + instrument + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + [2.5,) + + default-descriptor + descriptor + xdoc + helpmojo + + + + + + + + + org.codehaus.mojo + native-maven-plugin + [1.0-alpha-7,) + + initialize + javah + compile + unzipinc + link + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + [2.8,) + + jar + + + + + + + + + org.apache.maven.plugins + maven-pmd-plugin + [2.5,) + + check + + + + + + + + + org.apache.maven.plugins + maven-remote-resources-plugin + [1.0,) + + process + + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + [1.0,) + + enforce + + + + + + + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.4 +