LANG-1443: Add more SystemUtils.IS_JAVA_XX variants (#415)
This commit is contained in:
parent
3e37b25ebc
commit
6e797a40a7
|
@ -46,7 +46,8 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<body>
|
||||
|
||||
<release version="3.9" date="????-??-??" description="??">
|
||||
<action type="add" dev="jochen">Adding the Functions class.</action>
|
||||
<action issue="LANG-1416" type="update" dev="britter">Add more SystemUtils.IS_JAVA_XX variants.</action>
|
||||
<action type="add" dev="jochen">Adding the Functions class.</action>
|
||||
<action issue="LANG-1416" type="update" dev="britter">Update to JUnit 5</action>
|
||||
<action issue="LANG-1417" type="update" dev="britter">Add @FunctionalInterface to ThreadPredicate and ThreadGroupPredicate</action>
|
||||
<action issue="LANG-1415" type="update" dev="britter">Update Java Language requirement to 1.8</action>
|
||||
|
|
|
@ -101,6 +101,20 @@ public enum JavaVersion {
|
|||
*/
|
||||
JAVA_11(11.0f, "11"),
|
||||
|
||||
/**
|
||||
* Java 12
|
||||
*
|
||||
* @since 3.9
|
||||
*/
|
||||
JAVA_12(12.0f, "12"),
|
||||
|
||||
/**
|
||||
* Java 13
|
||||
*
|
||||
* @since 3.9
|
||||
*/
|
||||
JAVA_13(13.0f, "13"),
|
||||
|
||||
/**
|
||||
* The most recent java version. Mainly introduced to avoid to break when a new version of Java is used.
|
||||
*/
|
||||
|
@ -204,6 +218,10 @@ public enum JavaVersion {
|
|||
return JAVA_10;
|
||||
} else if ("11".equals(nom)) {
|
||||
return JAVA_11;
|
||||
} else if ("12".equals(nom)) {
|
||||
return JAVA_12;
|
||||
} else if ("13".equals(nom)) {
|
||||
return JAVA_13;
|
||||
}
|
||||
if (nom == null) {
|
||||
return null;
|
||||
|
|
|
@ -997,6 +997,30 @@ public class SystemUtils {
|
|||
*/
|
||||
public static final boolean IS_JAVA_11 = getJavaVersionMatches("11");
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Is {@code true} if this is Java version 12 (also 12.x versions).
|
||||
* </p>
|
||||
* <p>
|
||||
* The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @since 3.9
|
||||
*/
|
||||
public static final boolean IS_JAVA_12 = getJavaVersionMatches("12");
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Is {@code true} if this is Java version 13 (also 13.x versions).
|
||||
* </p>
|
||||
* <p>
|
||||
* The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @since 3.9
|
||||
*/
|
||||
public static final boolean IS_JAVA_13 = getJavaVersionMatches("13");
|
||||
|
||||
// Operating system checks
|
||||
// -----------------------------------------------------------------------
|
||||
// These MUST be declared after those above as they depend on the
|
||||
|
|
|
@ -20,11 +20,11 @@ package org.apache.commons.lang3;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_0_9;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_12;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_13;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_3;
|
||||
|
@ -34,9 +34,12 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_6;
|
|||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_7;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT;
|
||||
import static org.apache.commons.lang3.JavaVersion.get;
|
||||
import static org.apache.commons.lang3.JavaVersion.getJavaVersion;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.JavaVersion}.
|
||||
|
@ -56,11 +59,13 @@ public class JavaVersionTest {
|
|||
assertEquals(JAVA_1_8, get("1.8"), "1.8 failed");
|
||||
assertEquals(JAVA_9, get("9"), "9 failed");
|
||||
assertEquals(JAVA_10, get("10"), "10 failed");
|
||||
assertEquals(JavaVersion.JAVA_11, get("11"), "11 failed");
|
||||
assertEquals(JAVA_11, get("11"), "11 failed");
|
||||
assertEquals(JAVA_12, get("12"), "12 failed");
|
||||
assertEquals(JAVA_13, get("13"), "13 failed");
|
||||
assertEquals(JAVA_RECENT, get("1.10"), "1.10 failed");
|
||||
// assertNull("2.10 unexpectedly worked", get("2.10"));
|
||||
assertEquals(get("1.5"), getJavaVersion("1.5"), "Wrapper method failed");
|
||||
assertEquals(JAVA_RECENT, get("12"), "Unhandled"); // LANG-1384
|
||||
assertEquals(JAVA_RECENT, get("14"), "Unhandled"); // LANG-1384
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -30,6 +30,8 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
|
|||
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_12;
|
||||
import static org.apache.commons.lang3.JavaVersion.JAVA_13;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
@ -141,6 +143,8 @@ public class SystemUtilsTest {
|
|||
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);
|
||||
} else if (javaVersion.startsWith("1.8")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
|
@ -154,6 +158,8 @@ public class SystemUtilsTest {
|
|||
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);
|
||||
} else if (javaVersion.startsWith("9")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
|
@ -167,6 +173,8 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.IS_JAVA_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_10);
|
||||
assertFalse(SystemUtils.IS_JAVA_11);
|
||||
assertFalse(SystemUtils.IS_JAVA_12);
|
||||
assertFalse(SystemUtils.IS_JAVA_13);
|
||||
} else if (javaVersion.startsWith("10")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
|
@ -180,6 +188,8 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.IS_JAVA_9);
|
||||
assertTrue(SystemUtils.IS_JAVA_10);
|
||||
assertFalse(SystemUtils.IS_JAVA_11);
|
||||
assertFalse(SystemUtils.IS_JAVA_12);
|
||||
assertFalse(SystemUtils.IS_JAVA_13);
|
||||
} else if (javaVersion.startsWith("11")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
|
@ -193,6 +203,38 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.IS_JAVA_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_10);
|
||||
assertTrue(SystemUtils.IS_JAVA_11);
|
||||
assertFalse(SystemUtils.IS_JAVA_12);
|
||||
assertFalse(SystemUtils.IS_JAVA_13);
|
||||
} else if (javaVersion.startsWith("12")) {
|
||||
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);
|
||||
assertTrue(SystemUtils.IS_JAVA_12);
|
||||
assertFalse(SystemUtils.IS_JAVA_13);
|
||||
} else if (javaVersion.startsWith("13")) {
|
||||
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);
|
||||
assertTrue(SystemUtils.IS_JAVA_13);
|
||||
} else {
|
||||
System.out.println("Can't test IS_JAVA value: " + javaVersion);
|
||||
}
|
||||
|
@ -433,6 +475,8 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_12));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_9) {
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
|
||||
|
@ -445,6 +489,8 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_12));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_10) {
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
|
||||
|
@ -457,6 +503,8 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_12));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_11) {
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
|
||||
|
@ -469,6 +517,36 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_11));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_12));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_12) {
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_3));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_4));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_5));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_6));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_7));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_11));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_12));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_13) {
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_3));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_4));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_5));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_6));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_7));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_11));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_12));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_13));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,6 +564,8 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_9));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_10));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_12));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_9) {
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_1));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_2));
|
||||
|
@ -498,6 +578,8 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_9));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_10));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_12));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_10) {
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_1));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_2));
|
||||
|
@ -510,6 +592,8 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_9));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_10));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_12));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_11) {
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_1));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_2));
|
||||
|
@ -522,6 +606,36 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_10));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_12));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_12) {
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_1));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_2));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_3));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_4));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_5));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_6));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_7));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_8));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_10));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_11));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_12));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_13));
|
||||
} else if (SystemUtils.IS_JAVA_13) {
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_1));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_2));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_3));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_4));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_5));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_6));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_7));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_1_8));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_10));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_11));
|
||||
assertFalse(SystemUtils.isJavaVersionAtMost(JAVA_12));
|
||||
assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_13));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue