]> source.dussan.org Git - iciql.git/commitdiff
Use manifest method to get version
authorJames Moger <james.moger@gitblit.com>
Mon, 11 May 2015 18:50:20 +0000 (14:50 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 11 May 2015 19:00:25 +0000 (15:00 -0400)
src/main/java/com/iciql/Constants.java

index 6b5d83a198f4fb89a2c99f44d40e1959ade916be..e27e24a7f0da2950cbb655c05c3a5cfa97eb1239 100644 (file)
@@ -32,11 +32,7 @@ public class Constants {
        public static final String API_CURRENT = "15";\r
 \r
        public static String getVersion() {\r
-               String v = Constants.class.getPackage().getImplementationVersion();\r
-               if (v == null) {\r
-                       return "0.0.0-SNAPSHOT";\r
-               }\r
-               return v;\r
+               return getManifestValue("implementation-version", "0.0.0-SNAPSHOT");\r
        }\r
 \r
        public static String getBuildDate() {\r
@@ -47,12 +43,14 @@ public class Constants {
                Class<?> clazz = Constants.class;\r
                String className = clazz.getSimpleName() + ".class";\r
                String classPath = clazz.getResource(className).toString();\r
-               if (!classPath.startsWith("jar")) {\r
-                       // Class not from JAR\r
-                       return defaultValue;\r
-               }\r
                try {\r
-                       String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";\r
+                       String manifestPath;\r
+                       if (classPath.indexOf('!') > -1) {\r
+                               manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";\r
+                       } else {\r
+                               String pkgPath = "/" + clazz.getPackage().getName().replace('.', '/');\r
+                               manifestPath = classPath.substring(0, classPath.indexOf(pkgPath))  + "/META-INF/MANIFEST.MF";\r
+                       }\r
                        Manifest manifest = new Manifest(new URL(manifestPath).openStream());\r
                        Attributes attr = manifest.getMainAttributes();\r
                        String value = attr.getValue(attrib);\r