From 2548a8ab0b3649ed3fc8eac331ebeb1f28f02c3d Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Mon, 3 Oct 2022 16:36:33 +0200 Subject: [PATCH] Deactivate Java 18 preview language feature tests and enable LangUtil to parse Java versions like '19+36-2238'. Signed-off-by: Alexander Kriegisch --- .../systemtest/ajc196/AllTestsAspectJ196.java | 2 +- .../systemtest/ajc199/AllTestsAspectJ199.java | 3 +++ .../main/java/org/aspectj/util/LangUtil.java | 20 +++++++++---------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java b/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java index c2e13b550..d3cbfb9ab 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java @@ -26,7 +26,7 @@ public class AllTestsAspectJ196 { // Do not run tests using a previous compiler's preview features anymore. They would all fail. /* if (LangUtil.is14VMOrGreater() && !LangUtil.is15VMOrGreater()) { - suite.addTest(Ajc196PreviewFeaturesTests.suite()); + suite.addTest(Java14PreviewFeaturesTests.suite()); } */ return suite; diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java b/tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java index 6ff7adee4..6b77073be 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java @@ -23,9 +23,12 @@ public class AllTestsAspectJ199 { suite.addTest(SanityTestsJava18.suite()); suite.addTest(Ajc199TestsJava.suite()); } + // Do not run tests using a previous compiler's preview features anymore. They would all fail. + /* if (LangUtil.is18VMOrGreater() && !LangUtil.is19VMOrGreater()) { suite.addTest(Java18PreviewFeaturesTests.suite()); } + */ return suite; } } diff --git a/util/src/main/java/org/aspectj/util/LangUtil.java b/util/src/main/java/org/aspectj/util/LangUtil.java index 944e95040..02aa7d94b 100644 --- a/util/src/main/java/org/aspectj/util/LangUtil.java +++ b/util/src/main/java/org/aspectj/util/LangUtil.java @@ -57,6 +57,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" + // TODO: Use java.lang.Runtime class (since Java 9, now AspectJ needs Java 11+ due to JDT Core anyway) + final String JAVA_VERSION_NOT_FOUND = "System properties appear damaged, cannot find: java.version/java.runtime.version/java.vm.version"; try { String vm = System.getProperty("java.version"); // JLS 20.18.7 if (vm == null) { @@ -66,15 +68,12 @@ public class LangUtil { vm = System.getProperty("java.vm.version"); } if (vm == null) { - new RuntimeException( - "System properties appear damaged, cannot find: java.version/java.runtime.version/java.vm.version") - .printStackTrace(System.err); + new RuntimeException(JAVA_VERSION_NOT_FOUND).printStackTrace(System.err); vmVersion = 1.5; } else { - // 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 numbers = getFirstNumbers(vm); + List numbers = getJavaMajorMinor(vm); if (numbers.get(0) == 1) { // Old school for 1.0 > 1.8 vmVersion = numbers.get(0)+(numbers.get(1)/10d); @@ -89,18 +88,19 @@ public class LangUtil { } } } catch (Throwable t) { - new RuntimeException( - "System properties appear damaged, cannot find: java.version/java.runtime.version/java.vm.version", t) - .printStackTrace(System.err); + new RuntimeException(JAVA_VERSION_NOT_FOUND, t).printStackTrace(System.err); vmVersion = 1.5; } } - private static List getFirstNumbers(String vm) { + private static List getJavaMajorMinor(String vm) { List result = new ArrayList<>(); - StringTokenizer st = new StringTokenizer(vm,".-_"); + // Can be something like '1.5', '11.0.16.1', '19+36-2238' + StringTokenizer st = new StringTokenizer(vm,".-_+"); try { result.add(Integer.parseInt(st.nextToken())); + // FIXME: The minor will be wrong for version strings like '19+36-2238'. + // The minor is only relevant for Java <= 1.8. Even so, this is super ugly. result.add(Integer.parseInt(st.nextToken())); } catch (Exception e) { // NoSuchElementException if no more tokens -- 2.39.5