You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/07/05 14:26:09 UTC

[commons-lang] 09/09: Add SystemUtils.IS_JAVA_17

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 6001ae8a0c9f5815ee368ae1967d6de1b786a9e7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 5 10:25:46 2022 -0400

    Add SystemUtils.IS_JAVA_17
---
 src/changes/changes.xml                            |  1 +
 .../java/org/apache/commons/lang3/SystemUtils.java | 10 ++++++++
 .../org/apache/commons/lang3/SystemUtilsTest.java  | 29 ++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8e8a16353..1b7ca9fe7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -152,6 +152,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add ExceptionUtils.stream(Throwable).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add ExceptionUtils.getRootCauseStackTraceList(Throwable).</action>
     <action                   type="add" dev="ggregory" due-to="Will Herrmann, Gary Gregory, Roland Kreuzer">Add SystemUtils.IS_OS_WINDOWS_11.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_17.</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Dependabot, XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.4 #742, #752, #764, #833, #867.</action>
     <action                   type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from 2 to 3 #819, #825, #859.</action>
diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index 4a810cdc0..12db15573 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -1060,6 +1060,16 @@ public class SystemUtils {
      */
     public static final boolean IS_JAVA_16 = getJavaVersionMatches("16");
 
+    /**
+     * Is {@code true} if this is Java version 17 (also 17.x versions).
+     * <p>
+     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
+     * </p>
+     *
+     * @since 3.13.0
+     */
+    public static final boolean IS_JAVA_17 = getJavaVersionMatches("17");
+
     // 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 3c4ca25b9..61237a232 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -74,6 +74,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("1.8")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -92,6 +93,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("9")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -110,6 +112,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("10")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -128,6 +131,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("11")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -146,6 +150,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("12")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -164,6 +169,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("13")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -182,6 +188,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("14")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -200,6 +207,7 @@ public class SystemUtilsTest {
             assertTrue(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("15")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -218,6 +226,7 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertTrue(SystemUtils.IS_JAVA_15);
             assertFalse(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
         } else if (javaVersion.startsWith("16")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -236,6 +245,26 @@ public class SystemUtilsTest {
             assertFalse(SystemUtils.IS_JAVA_14);
             assertFalse(SystemUtils.IS_JAVA_15);
             assertTrue(SystemUtils.IS_JAVA_16);
+            assertFalse(SystemUtils.IS_JAVA_17);
+        } else if (javaVersion.startsWith("17")) {
+            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);
+            assertFalse(SystemUtils.IS_JAVA_1_9);
+            assertFalse(SystemUtils.IS_JAVA_9);
+            assertFalse(SystemUtils.IS_JAVA_10);
+            assertFalse(SystemUtils.IS_JAVA_11);
+            assertFalse(SystemUtils.IS_JAVA_12);
+            assertFalse(SystemUtils.IS_JAVA_13);
+            assertFalse(SystemUtils.IS_JAVA_14);
+            assertFalse(SystemUtils.IS_JAVA_15);
+            assertFalse(SystemUtils.IS_JAVA_16);
+            assertTrue(SystemUtils.IS_JAVA_17);
         } else {
             System.out.println("Can't test IS_JAVA value: " + javaVersion);
         }