Log the version number and commit on startup

This commit is contained in:
James Agnew 2019-01-17 16:05:54 -05:00
parent 584179ba39
commit 4367e340ae
5 changed files with 87 additions and 6 deletions

View File

@ -162,12 +162,45 @@
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>standard</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
<execution>
<id>downstream</id>
<phase>validate</phase>
<goals>
<goal>create-metadata</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/properties</outputDirectory>
<outputName>ca/uhn/fhir/hapi-fhir-base-build.properties</outputName>
<revisionPropertyName>hapifhir.buildnumber</revisionPropertyName>
<timestampPropertyName>hapifhir.timestamp</timestampPropertyName>
<timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SXXX</timestampFormat>
<versionPropertyName>hapifhir.version</versionPropertyName>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
<resources> <resources>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
<resource>
<directory>${project.build.directory}/generated-sources/properties</directory>
<filtering>false</filtering>
</resource>
</resources> </resources>
</build> </build>

View File

@ -20,9 +20,13 @@ package ca.uhn.fhir.util;
* #L% * #L%
*/ */
import org.apache.commons.lang3.StringUtils;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
/** /**
* Used internally by HAPI to log the version of the HAPI FHIR framework * Used internally by HAPI to log the version of the HAPI FHIR framework
* once, when the framework is first loaded by the classloader. * once, when the framework is first loaded by the classloader.
@ -31,21 +35,37 @@ public class VersionUtil {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(VersionUtil.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(VersionUtil.class);
private static String ourVersion; private static String ourVersion;
private static String ourBuildNumber;
private static String ourBuildTime;
static { static {
initialize(); initialize();
} }
public static String getBuildNumber() {
return ourBuildNumber;
}
public static String getBuildTime() {
return ourBuildTime;
}
public static String getVersion() { public static String getVersion() {
return ourVersion; return ourVersion;
} }
private static void initialize() { private static void initialize() {
try (InputStream is = VersionUtil.class.getResourceAsStream("/ca/uhn/fhir/hapi-version.properties")) { try (InputStream is = VersionUtil.class.getResourceAsStream("/ca/uhn/fhir/hapi-fhir-base-build.properties")) {
Properties p = new Properties(); Properties p = new Properties();
p.load(is); p.load(is);
ourVersion = p.getProperty("version");
ourLog.info("HAPI FHIR version is: " + ourVersion); ourVersion = p.getProperty("hapifhir.version");
ourVersion = defaultIfBlank(ourVersion, "(unknown)");
ourBuildNumber = p.getProperty("hapifhir.buildnumber");
ourBuildTime = p.getProperty("hapifhir.timestamp");
ourLog.info("HAPI FHIR version {} - Rev {}", ourVersion, StringUtils.right(ourBuildNumber, 10));
} catch (Exception e) { } catch (Exception e) {
ourLog.warn("Unable to determine HAPI version information", e); ourLog.warn("Unable to determine HAPI version information", e);
} }

View File

@ -0,0 +1,19 @@
package ca.uhn.fhir.util;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.blankOrNullString;
import static org.junit.Assert.*;
public class VersionUtilTest {
@Test
public void testProperties() {
assertThat(VersionUtil.getVersion(), not(blankOrNullString()));
assertThat(VersionUtil.getBuildNumber(), not(blankOrNullString()));
assertThat(VersionUtil.getBuildTime(), not(blankOrNullString()));
}
}

View File

@ -1485,6 +1485,11 @@
<artifactId>build-helper-maven-plugin</artifactId> <artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
</plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId> <artifactId>animal-sniffer-maven-plugin</artifactId>

View File

@ -303,6 +303,10 @@
AuthorizationInterceptor can now allow a user to perform a search that is scoped to a particular AuthorizationInterceptor can now allow a user to perform a search that is scoped to a particular
resource (e.g. Patient?_id=123) if the user has read access for that specific instance. resource (e.g. Patient?_id=123) if the user has read access for that specific instance.
</action> </action>
<action type="add">
HAPI FHIR will now log the Git revision when it first starts up (on the ame line as the version number
that it already logs).
</action>
</release> </release>
<release version="3.6.0" date="2018-11-12" description="Food"> <release version="3.6.0" date="2018-11-12" description="Food">
<action type="add"> <action type="add">