From c230f3695b834866d5472ee60e23679f0950632b Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 11 May 2015 14:50:20 -0400 Subject: [PATCH] Use manifest method to get version --- src/main/java/com/iciql/Constants.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/iciql/Constants.java b/src/main/java/com/iciql/Constants.java index 6b5d83a..e27e24a 100644 --- a/src/main/java/com/iciql/Constants.java +++ b/src/main/java/com/iciql/Constants.java @@ -32,11 +32,7 @@ public class Constants { public static final String API_CURRENT = "15"; public static String getVersion() { - String v = Constants.class.getPackage().getImplementationVersion(); - if (v == null) { - return "0.0.0-SNAPSHOT"; - } - return v; + return getManifestValue("implementation-version", "0.0.0-SNAPSHOT"); } public static String getBuildDate() { @@ -47,12 +43,14 @@ public class Constants { Class clazz = Constants.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); - if (!classPath.startsWith("jar")) { - // Class not from JAR - return defaultValue; - } try { - String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; + String manifestPath; + if (classPath.indexOf('!') > -1) { + manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; + } else { + String pkgPath = "/" + clazz.getPackage().getName().replace('.', '/'); + manifestPath = classPath.substring(0, classPath.indexOf(pkgPath)) + "/META-INF/MANIFEST.MF"; + } Manifest manifest = new Manifest(new URL(manifestPath).openStream()); Attributes attr = manifest.getMainAttributes(); String value = attr.getValue(attrib); -- 2.39.5