From 0e9dbaf5d8f59b98361f18c7642eb82cd9e18389 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Tue, 13 Jan 2015 18:49:43 +0000 Subject: [PATCH] HCOLL-293 now reading the version from the resource file "map.version" --- pom.xml | 24 +++++++++++++++++-- .../openhft/chronicle/map/BuildVersion.java | 24 +++++++++++++++---- src/main/resources/map.version | 1 + 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/map.version diff --git a/pom.xml b/pom.xml index cc7f90f96..f1ddf6934 100644 --- a/pom.xml +++ b/pom.xml @@ -17,13 +17,15 @@ ~ limitations under the License. --> - + net.openhft java-parent-pom 1.1.2 - + 4.0.0 @@ -141,6 +143,24 @@ + + + + src/main/resources + true + + **/map.version + + + + src/main/resources + false + + **/map.version + + + + diff --git a/src/main/java/net/openhft/chronicle/map/BuildVersion.java b/src/main/java/net/openhft/chronicle/map/BuildVersion.java index f1539d072..1912296a7 100644 --- a/src/main/java/net/openhft/chronicle/map/BuildVersion.java +++ b/src/main/java/net/openhft/chronicle/map/BuildVersion.java @@ -21,16 +21,14 @@ package net.openhft.chronicle.map; import shaded.org.apache.maven.model.Model; import shaded.org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import java.io.File; -import java.io.FileReader; -import java.io.Reader; +import java.io.*; /** * gets the version of the current build */ class BuildVersion { - private static String version = null; + private static String version = null; /** * @return version of ChronicleMap being used, or NULL if its not known @@ -41,7 +39,23 @@ class BuildVersion { return version; } - // the best way to get the version is to read it from the manifest + try { + // the best way to get the version is to read the map.version file + InputStream resource = BuildVersion.class.getClassLoader().getResourceAsStream("map" + + ".version"); + BufferedReader in = new BufferedReader(new InputStreamReader(resource)); + + version = in.readLine().trim(); + if (!"${project.version}".equals(version())) + return version; + + return version; + } catch (Exception e) { + // do nothing + } + + + // another way to get the version is to read it from the manifest final String versionFromManifest = getVersionFromManifest(); if (versionFromManifest != null) { diff --git a/src/main/resources/map.version b/src/main/resources/map.version new file mode 100644 index 000000000..f2ab45c3b --- /dev/null +++ b/src/main/resources/map.version @@ -0,0 +1 @@ +${project.version} \ No newline at end of file