From 3225ba64ce9f196b828d7c2ea124c03bd0d62955 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sat, 28 Mar 2015 12:26:01 +0000 Subject: [PATCH] LANG-1103: Add SystemUtils.IS_JAVA_1_9 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1669753 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 1 + .../org/apache/commons/lang3/SystemUtils.java | 12 +++++++++ .../apache/commons/lang3/SystemUtilsTest.java | 26 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9e3418034..da8963221 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ + Add SystemUtils.IS_JAVA_1_9 Make logic for comparing OS versions in SystemUtils smarter Shutdown thread pools in test cases FastDateParser and FastDatePrinter support 'X' format diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java index ba99a4ae0..c23450b19 100644 --- a/src/main/java/org/apache/commons/lang3/SystemUtils.java +++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java @@ -939,6 +939,18 @@ public class SystemUtils { */ public static final boolean IS_JAVA_1_8 = getJavaVersionMatches("1.8"); + /** + *

+ * Is {@code true} if this is Java version 1.9 (also 1.9.x versions). + *

+ *

+ * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}. + *

+ * + * @since 3.4 + */ + public static final boolean IS_JAVA_1_9 = getJavaVersionMatches("1.9"); + // Operating system checks // ----------------------------------------------------------------------- // These MUST be declared after those above as they depend on the diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java index fa474d1cb..19703040f 100644 --- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java @@ -105,6 +105,8 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_5); assertFalse(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.1")) { assertTrue(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_2); @@ -113,6 +115,8 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_5); assertFalse(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.2")) { assertFalse(SystemUtils.IS_JAVA_1_1); assertTrue(SystemUtils.IS_JAVA_1_2); @@ -121,6 +125,8 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_5); assertFalse(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.3")) { assertFalse(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_2); @@ -129,6 +135,8 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_5); assertFalse(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.4")) { assertFalse(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_2); @@ -137,6 +145,8 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_5); assertFalse(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.5")) { assertFalse(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_2); @@ -145,6 +155,8 @@ public class SystemUtilsTest { assertTrue(SystemUtils.IS_JAVA_1_5); assertFalse(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.6")) { assertFalse(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_2); @@ -153,6 +165,8 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_5); assertTrue(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.7")) { assertFalse(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_2); @@ -162,6 +176,7 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_6); assertTrue(SystemUtils.IS_JAVA_1_7); assertFalse(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); } else if (javaVersion.startsWith("1.8")) { assertFalse(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_2); @@ -171,6 +186,17 @@ public class SystemUtilsTest { assertFalse(SystemUtils.IS_JAVA_1_6); assertFalse(SystemUtils.IS_JAVA_1_7); assertTrue(SystemUtils.IS_JAVA_1_8); + assertFalse(SystemUtils.IS_JAVA_1_9); + } else if (javaVersion.startsWith("1.9")) { + assertFalse(SystemUtils.IS_JAVA_1_1); + assertFalse(SystemUtils.IS_JAVA_1_2); + assertFalse(SystemUtils.IS_JAVA_1_3); + assertFalse(SystemUtils.IS_JAVA_1_4); + assertFalse(SystemUtils.IS_JAVA_1_5); + assertFalse(SystemUtils.IS_JAVA_1_6); + assertFalse(SystemUtils.IS_JAVA_1_7); + assertFalse(SystemUtils.IS_JAVA_1_8); + assertTrue(SystemUtils.IS_JAVA_1_9); } else { System.out.println("Can't test IS_JAVA value: "+javaVersion); }