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 | |
parent | ff3df66cdebab32ca8c7f06d45ec2c817abe70bb (diff) | |
download | iciql-c9c00d3131227997c3cef27c69687fa72a8026fc.tar.gz iciql-c9c00d3131227997c3cef27c69687fa72a8026fc.zip |
Use version metadata stamped by the build process
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/iciql/Constants.java | 40 | ||||
-rw-r--r-- | src/test/java/com/iciql/test/IciqlSuite.java | 6 |
2 files changed, 36 insertions, 10 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;
+ }
}
diff --git a/src/test/java/com/iciql/test/IciqlSuite.java b/src/test/java/com/iciql/test/IciqlSuite.java index c80da93..f730657 100644 --- a/src/test/java/com/iciql/test/IciqlSuite.java +++ b/src/test/java/com/iciql/test/IciqlSuite.java @@ -353,7 +353,7 @@ public class IciqlSuite { // Header
out.println(dividerMajor);
out.println(MessageFormat.format("{0} {1} ({2}) testing {3} database configurations", Constants.NAME,
- Constants.VERSION, Constants.VERSION_DATE, TEST_DBS.length));
+ Constants.getVersion(), Constants.getBuildDate(), TEST_DBS.length));
out.println(dividerMajor);
out.println();
@@ -432,7 +432,7 @@ public class IciqlSuite { out.println();
out.println(dividerMajor);
out.println(MessageFormat.format("{0} {1} ({2}) test suite performance results", Constants.NAME,
- Constants.VERSION, Constants.VERSION_DATE));
+ Constants.getVersion(), Constants.getBuildDate()));
StringBuilder compressedSystem = new StringBuilder();
compressedSystem.append(" on ");
@@ -496,7 +496,7 @@ public class IciqlSuite { }
private static void usage(JCommander jc, ParameterException t) {
- System.out.println(Constants.NAME + " test suite v" + Constants.VERSION);
+ System.out.println(Constants.NAME + " test suite v" + Constants.getVersion());
System.out.println();
if (t != null) {
System.out.println(t.getMessage());
|