From 7627a8617624743a6e21f681ec372f1e357ce3be Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 2 Dec 2020 21:19:04 -0500 Subject: [PATCH] Improve version logging (#2213) * Improve version logging * Add changelog * Test fixes --- .../java/ca/uhn/fhir/util/VersionUtil.java | 20 +++++++++++++++++-- .../5_3_0/2213-improve-version-logging.yaml | 6 ++++++ .../uhn/fhir/rest/server/RestfulServer.java | 6 +++++- .../MetadataConformanceDstu2_1Test.java | 5 +++-- .../MetadataCapabilityStatementDstu3Test.java | 4 ++-- .../server/MetadataConformanceDstu3Test.java | 6 ++++-- 6 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_3_0/2213-improve-version-logging.yaml diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionUtil.java index 9972023ad21..a6a8d37214d 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionUtil.java @@ -37,11 +37,16 @@ public class VersionUtil { private static String ourVersion; private static String ourBuildNumber; private static String ourBuildTime; + private static boolean ourSnapshot; static { initialize(); } + public static boolean isSnapshot() { + return ourSnapshot; + } + public static String getBuildNumber() { return ourBuildNumber; } @@ -65,11 +70,18 @@ public class VersionUtil { ourVersion = p.getProperty("hapifhir.version"); ourVersion = defaultIfBlank(ourVersion, "(unknown)"); - ourBuildNumber = p.getProperty("hapifhir.buildnumber"); + ourSnapshot = ourVersion.contains("SNAPSHOT"); + + ourBuildNumber = StringUtils.left(p.getProperty("hapifhir.buildnumber"), 10); ourBuildTime = p.getProperty("hapifhir.timestamp"); if (System.getProperty("suppress_hapi_fhir_version_log") == null) { - ourLog.info("HAPI FHIR version {} - Rev {}", ourVersion, StringUtils.right(ourBuildNumber, 10)); + String buildNumber = ourBuildNumber; + if (isSnapshot()) { + buildNumber = buildNumber + "/" + getBuildDate(); + } + + ourLog.info("HAPI FHIR version {} - Rev {}", ourVersion, buildNumber); } } catch (Exception e) { @@ -77,4 +89,8 @@ public class VersionUtil { } } + public static String getBuildDate() { + return ourBuildTime.substring(0, 10); + } + } diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_3_0/2213-improve-version-logging.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_3_0/2213-improve-version-logging.yaml new file mode 100644 index 00000000000..bdafe4265ae --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_3_0/2213-improve-version-logging.yaml @@ -0,0 +1,6 @@ +--- +type: add +issue: 2213 +title: "Non release (i.e. SNAPSHOT) builds of HAPI FHIR will now include the Git revision hash as well as the build date in the + version string that is logged on initialization, and included in the default server X-Powered-By string. Release builds are + not affected by this change." diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 1ca9bd36573..c7f3c398163 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -299,7 +299,11 @@ public class RestfulServer extends HttpServlet implements IRestfulServer", output); + assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("REST Server (FHIR Server; FHIR " + ourCtx.getVersion().getVersion().getFhirVersionString() + "/" + ourCtx.getVersion().getVersion().name() + ")")); } finally { IOUtils.closeQuietly(status.getEntity().getContent()); } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataCapabilityStatementDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataCapabilityStatementDstu3Test.java index 3c7923caf9b..5bc1aba18e1 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataCapabilityStatementDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataCapabilityStatementDstu3Test.java @@ -86,8 +86,8 @@ public class MetadataCapabilityStatementDstu3Test { output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); assertEquals(200, status.getStatusLine().getStatusCode()); assertThat(output, containsString("