diff options
author | James Moger <james.moger@gitblit.com> | 2015-05-11 14:50:20 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-05-11 15:00:25 -0400 |
commit | c230f3695b834866d5472ee60e23679f0950632b (patch) | |
tree | a412a04bfc261b30e3ca8b972a4414ffdffc7fc9 | |
parent | 5544de49ace3313f9f6c77b0d7070ef1f6d81231 (diff) | |
download | iciql-c230f3695b834866d5472ee60e23679f0950632b.tar.gz iciql-c230f3695b834866d5472ee60e23679f0950632b.zip |
Use manifest method to get version
-rw-r--r-- | src/main/java/com/iciql/Constants.java | 18 |
1 files 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);
|