changeset 1072:21d5793de4c0

7901226: JMH version number reporting depends on the Locale Summary: Remove the Locale-specific bits, store only neutral date, always print the version.
author shade
date Mon, 22 Dec 2014 19:27:38 +0300
parents df151f9c0071
children fd7425c74b22
files jmh-core/pom.xml jmh-core/src/main/java/org/openjdk/jmh/util/Version.java jmh-core/src/main/resources/jmh.properties
diffstat 3 files changed, 42 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/pom.xml	Mon Dec 22 17:47:35 2014 +0300
+++ b/jmh-core/pom.xml	Mon Dec 22 19:27:38 2014 +0300
@@ -75,8 +75,8 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <timestamp>${maven.build.timestamp}</timestamp>
-        <maven.build.timestamp.format>EEE MMM dd HH:mm:ss zzz yyyy</maven.build.timestamp.format>
+        <buildDate>${maven.build.timestamp}</buildDate>
+        <maven.build.timestamp.format>yyyy/MM/dd</maven.build.timestamp.format>
     </properties>
 
     <build>
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Version.java	Mon Dec 22 17:47:35 2014 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Version.java	Mon Dec 22 19:27:38 2014 +0300
@@ -31,6 +31,7 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Locale;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
@@ -39,33 +40,49 @@
     public static void printVersion(OutputFormat pw) {
         Properties p = new Properties();
         InputStream s = Version.class.getResourceAsStream("/jmh.properties");
-        String time = null;
-        if (s != null) {
-            try {
-                p.load(s);
-                time = (String) p.get("jmh.buildTime");
 
-                Date parse = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(time);
-                long diff = (System.currentTimeMillis() - parse.getTime()) / TimeUnit.DAYS.toMillis(1);
+        if (s == null) {
+            pw.println("# Cannot figure out JMH version, no jmh.properties");
+            return;
+        }
 
-                pw.print("# JMH " + p.get("jmh.version") + " (released ");
-                if (diff > 0) {
-                    pw.print(String.format("%d days ago", diff));
-                    if (diff > 30) {
-                        pw.print(", please consider updating!");
-                    }
-                } else {
-                    pw.print("today");
+        try {
+            p.load(s);
+        } catch (IOException e) {
+            pw.println("# Cannot figure out JMH version");
+            return;
+        }
+
+        String version = (String) p.get("jmh.version");
+        if (version == null) {
+            pw.println("# Cannot read jmh.version");
+            return;
+        }
+
+        pw.print("# JMH " + version + " ");
+
+        String time = (String) p.get("jmh.buildDate");
+        if (time == null) {
+            pw.println("(cannot read jmh.buildDate)");
+            return;
+        }
+
+        pw.print("(released ");
+        try {
+            Date parse = new SimpleDateFormat("yyyy/MM/dd", Locale.ROOT).parse(time);
+            long diff = (System.currentTimeMillis() - parse.getTime()) / TimeUnit.DAYS.toMillis(1);
+            if (diff > 0) {
+                pw.print(String.format("%d days ago", diff));
+                if (diff > 30) {
+                    pw.print(", please consider updating!");
                 }
-                pw.println(")");
-            } catch (IOException e) {
-                pw.println("# Can not figure out JMH version");
-            } catch (ParseException e) {
-                pw.println("# Can not figure out JMH version, unable to parse the build time: " + time);
+            } else {
+                pw.print("today");
             }
-        } else {
-            pw.println("# Can not figure out JMH version, no jmh.properties");
+        } catch (ParseException e) {
+            pw.print(time);
         }
+        pw.println(")");
     }
 
 }
--- a/jmh-core/src/main/resources/jmh.properties	Mon Dec 22 17:47:35 2014 +0300
+++ b/jmh-core/src/main/resources/jmh.properties	Mon Dec 22 19:27:38 2014 +0300
@@ -24,4 +24,4 @@
 #
 
 jmh.version=${project.version}
-jmh.buildTime=${timestamp}
\ No newline at end of file
+jmh.buildDate=${buildDate}