From: James Moger Date: Mon, 11 May 2015 18:50:20 +0000 (-0400) Subject: Use manifest method to get version X-Git-Tag: v1.6.1~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c230f3695b834866d5472ee60e23679f0950632b;p=iciql.git Use manifest method to get version --- 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);