diff options
author | Andy Clement <aclement@pivotal.io> | 2017-11-09 13:14:02 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2017-11-09 13:14:02 -0800 |
commit | d92319c43f5723d57887e09f2a839ee5b595fcfd (patch) | |
tree | 155e25d455e598ff5b55b0563645d4af23903bb4 /util | |
parent | 6765fdc34c775e99799b36d88cff8ab88dffc8e7 (diff) | |
download | aspectj-d92319c43f5723d57887e09f2a839ee5b595fcfd.tar.gz aspectj-d92319c43f5723d57887e09f2a839ee5b595fcfd.zip |
Updates to better cope with future JDKs
The version handling in LangUtil has been overhauled
to cope better with post 1.8 releases (JDK9 and JDK10 or 18.3
or whatever they call it). As part of this moved
to treating JDK9 as '9' rather than '1.9'. Also removed
duplicate version processing logic and had that defer to
the one place in LangUtil where we now deal with it.
Includes some generics tidyup in ajdoc. More ajdoc work
is necessary for Java10 because it removes the standard doclet
(old style). However trying to invoke the internal Javadoc
handler in Java10 is failing due to module visibility rules.
Diffstat (limited to 'util')
-rw-r--r-- | util/src/org/aspectj/util/LangUtil.java | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index 08c2da43a..ff6c7246c 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -49,6 +49,10 @@ public class LangUtil { return Double.toString(vmVersion); } + public static double getVmVersion() { + return vmVersion; + } + static { StringWriter buf = new StringWriter(); PrintWriter writer = new PrintWriter(buf); @@ -66,6 +70,8 @@ public class LangUtil { } static { + // http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html + // http://openjdk.java.net/jeps/223 "New Version-String Scheme" try { String vm = System.getProperty("java.version"); // JLS 20.18.7 if (vm == null) { @@ -80,17 +86,21 @@ public class LangUtil { .printStackTrace(System.err); vmVersion = 1.5; } else { - if (vm.startsWith("9")) { - // JDK 9 beta 99 starts using 9-ea as the version string. - vmVersion = 1.9; - } else { - try { - String versionString = vm.substring(0, 3); - Double temp = new Double(Double.parseDouble(versionString)); - vmVersion = temp.doubleValue(); - } catch (Exception e) { - vmVersion = 1.4; + // Version: [1-9][0-9]*((\.0)*\.[1-9][0-9]*)* + // Care about the first set of digits and second set if first digit is 1 + try { + List<Integer> numbers = getFirstNumbers(vm); + if (numbers.get(0) == 1) { + // Old school for 1.0 > 1.8 + vmVersion = numbers.get(0)+(numbers.get(1)/10d); + } else { + // numbers.get(0) is the major version (9 and above) + // Note here the number will be 9 (or 10), *not* 1.9 or 1.10 + vmVersion = numbers.get(0); } + } catch (Throwable t) { + // Give up + vmVersion = 1.5; } } } catch (Throwable t) { @@ -100,6 +110,19 @@ public class LangUtil { vmVersion = 1.5; } } + + private static List<Integer> getFirstNumbers(String vm) { + List<Integer> result = new ArrayList<Integer>(); + StringTokenizer st = new StringTokenizer(vm,".-_"); + try { + result.add(Integer.parseInt(st.nextToken())); + result.add(Integer.parseInt(st.nextToken())); + } catch (Exception e) { + // NoSuchElementException if no more tokens + // NumberFormatException if not a number + } + return result; + } public static boolean is13VMOrGreater() { return 1.3 <= vmVersion; @@ -126,7 +149,7 @@ public class LangUtil { } public static boolean is19VMOrGreater() { - return 1.9 <= vmVersion; + return 9 <= vmVersion; } /** |