diff options
author | James Moger <james.moger@gitblit.com> | 2014-11-17 17:30:23 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-04-10 09:02:04 -0400 |
commit | c9c00d3131227997c3cef27c69687fa72a8026fc (patch) | |
tree | e6e9f8b60a06922e3892934bd04834899d7572ae /src/main | |
parent | ff3df66cdebab32ca8c7f06d45ec2c817abe70bb (diff) | |
download | iciql-c9c00d3131227997c3cef27c69687fa72a8026fc.tar.gz iciql-c9c00d3131227997c3cef27c69687fa72a8026fc.zip |
Use version metadata stamped by the build process
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/iciql/Constants.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/main/java/com/iciql/Constants.java b/src/main/java/com/iciql/Constants.java index ba75de3..6b5d83a 100644 --- a/src/main/java/com/iciql/Constants.java +++ b/src/main/java/com/iciql/Constants.java @@ -16,6 +16,10 @@ package com.iciql;
+import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
/**
* Iciql constants.
*/
@@ -25,14 +29,36 @@ public class Constants { // The build script extracts this exact line so be careful editing it
// and only use A-Z a-z 0-9 .-_ in the string.
- public static final String VERSION = "1.6.0-SNAPSHOT";
+ public static final String API_CURRENT = "15";
- // The build script extracts this exact line so be careful editing it
- // and only use A-Z a-z 0-9 .-_ in the string.
- public static final String VERSION_DATE = "PENDING";
+ public static String getVersion() {
+ String v = Constants.class.getPackage().getImplementationVersion();
+ if (v == null) {
+ return "0.0.0-SNAPSHOT";
+ }
+ return v;
+ }
- // The build script extracts this exact line so be careful editing it
- // and only use A-Z a-z 0-9 .-_ in the string.
- public static final String API_CURRENT = "15";
+ public static String getBuildDate() {
+ return getManifestValue("build-date", "PENDING");
+ }
+ private static String getManifestValue(String attrib, String defaultValue) {
+ 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";
+ Manifest manifest = new Manifest(new URL(manifestPath).openStream());
+ Attributes attr = manifest.getMainAttributes();
+ String value = attr.getValue(attrib);
+ return value;
+ } catch (Exception e) {
+ }
+ return defaultValue;
+ }
}
|