Nova Ordis Utilities Version Metadata Handling: Difference between revisions
Line 18: | Line 18: | ||
=Build Infrastructure Configuration= | =Build Infrastructure Configuration= | ||
==VERSION File== | |||
Place a <tt>VERSION</tt> file in the <tt>src/main/resources</tt> directory of the project. It should have the following content: | |||
<pre> | |||
version=${version} | |||
release_date=${release_date} | |||
</pre> | |||
If the project was initialized with [[novaordis-release-tools]], this should have been done automatically already. For more details see "[[Nova_Ordis_Release_Tools_User_Manual_-_Concepts#New_Project_Initialization|New Project Initialization with NORT]]". | |||
==${version} and ${release_date} in the In-Line Documentation of the Project== | |||
Since we are going to use the Maven resource plugin to filter resources and replace variables, you can also use ${version} and ${release_date} in the in-line documentation, for example the main USAGE file. Example: | |||
<pre> | |||
myApp version ${version} released on ${release_date} | |||
... | |||
</pre> | |||
==Define maven.build.timestamp.format and release_date== | |||
Make sure your POM file contains the definition of the build timestamp format and <tt>release_date</tt>, as follows: | |||
<pre> | |||
... | |||
<properties> | |||
<maven.build.timestamp.format>MM/dd/yy</maven.build.timestamp.format> | |||
<release_date>${maven.build.timestamp}</release_date> | |||
</properties> | |||
... | |||
</pre> | |||
The "version" property is available by default. | |||
==Configure the Maven Resources Plugin== | |||
Make sure the Maven Resources Plugin is available and configured as described here: [[Maven Resources Plugin#Variable_Substitution_in_Resource_Files|variable substitution in resource files]]. | |||
Essentially, we want: | |||
<pre> | |||
<filtering>true</filtering> | |||
</pre> | |||
==Usage== | |||
When all of the above are completed, the final artifact should contain correctly resolved <tt>${version}</tt> and <tt>${release_date}</tt> in all resources that have been filtered. | |||
To get the version and release date programmatically, use the following code: | |||
<blockquote style="background-color: AliceBlue; border: solid thin LightSteelBlue;"> | |||
:<br>https://github.com/NovaOrdis/novaordis-utilities/blob/master/src/main/java/io/novaordis/utilities/VersionUtilities.java<br><br> | |||
</blockquote> | |||
The utility code can be used as part of [[clad]] or directly. | |||
Revision as of 18:24, 16 November 2016
Internal
Overview
The mechanism relies on a project build pattern and a set of APIs to expose the version and release data of application in a standard manner. The mechanism is used by most of the Nova Ordis projects. clad builds upon it and exposes the version and release metadata as result of the "version" command, which is available by default to all clad-based applications.
The mechanism relies on the presence of a "VERSION" metadata file in the application's classpath. VersionUtilities.getVersion() and VersionUtilities.getReleaseDate() can be used as top-level API to locate, process and display the metadata. In case the metadata file is not found, the both methods log the condition using SLF4J warn() and return null.
In order to insure that the artifacts are built to contain version metadata, follow the instructions provided in the "Build Infrastructure Configuration" section, below.
Code
Build Infrastructure Configuration
VERSION File
Place a VERSION file in the src/main/resources directory of the project. It should have the following content:
version=${version} release_date=${release_date}
If the project was initialized with novaordis-release-tools, this should have been done automatically already. For more details see "New Project Initialization with NORT".
${version} and ${release_date} in the In-Line Documentation of the Project
Since we are going to use the Maven resource plugin to filter resources and replace variables, you can also use ${version} and ${release_date} in the in-line documentation, for example the main USAGE file. Example:
myApp version ${version} released on ${release_date} ...
Define maven.build.timestamp.format and release_date
Make sure your POM file contains the definition of the build timestamp format and release_date, as follows:
... <properties> <maven.build.timestamp.format>MM/dd/yy</maven.build.timestamp.format> <release_date>${maven.build.timestamp}</release_date> </properties> ...
The "version" property is available by default.
Configure the Maven Resources Plugin
Make sure the Maven Resources Plugin is available and configured as described here: variable substitution in resource files.
Essentially, we want:
<filtering>true</filtering>
Usage
When all of the above are completed, the final artifact should contain correctly resolved ${version} and ${release_date} in all resources that have been filtered.
To get the version and release date programmatically, use the following code:
The utility code can be used as part of clad or directly.
- Verify that the POM file contains the definition of maven.build.timestamp.format and release_date, as required by project Version and Release Date#Define_maven.build.timestamp.format_and_release_date. If it does not, inject it.