From 695cc4c3c8834fb54501c98ff95a519957c913d7 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Wed, 17 Dec 2014 19:09:30 +0000 Subject: [PATCH] HCOLL-184 BuildVersion now works across projects --- .../openhft/chronicle/map/BuildVersion.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/BuildVersion.java b/src/main/java/net/openhft/chronicle/map/BuildVersion.java index f069d0a3a..ae31b8b01 100644 --- a/src/main/java/net/openhft/chronicle/map/BuildVersion.java +++ b/src/main/java/net/openhft/chronicle/map/BuildVersion.java @@ -32,7 +32,7 @@ class BuildVersion { /** - * gets the version of NULL if it can not be read + * @return version of ChronicleMap being used, or NULL if its not known */ public static String version() { @@ -61,8 +61,16 @@ class BuildVersion { * @return gets the version from the pom.xml */ private static String getVersionFromPom() { - final File file = new File(new File(BuildVersion.class.getResource("/").getPath()) - .getParentFile().getParentFile().getAbsolutePath() + "/pom.xml"); + + final String absolutePath = new File(BuildVersion.class.getResource(BuildVersion.class + .getSimpleName() + ".class").getPath()) + .getParentFile().getParentFile().getParentFile().getParentFile().getParentFile() + .getParentFile().getParentFile().getAbsolutePath(); + + if (!absolutePath.endsWith("Chronicle-Map")) + return null; + + final File file = new File(absolutePath + "/pom.xml"); try (Reader reader = new FileReader(file)) { @@ -70,7 +78,10 @@ class BuildVersion { Model model = xpp3Reader.read(reader); return model.getVersion(); - + } catch (NoClassDefFoundError e) { + // if you want to get the version possibly in development add in to your pom + // pax-url-aether.jar + return null; } catch (Exception e) { return null; }