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 2018/12/11 00:49:10 UTC
[1/2] [lang] [LANG-1427] Add API
org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost(JavaVersion)
Repository: commons-lang
Updated Branches:
refs/heads/master c36895534 -> e21cb463c
[LANG-1427] Add API
org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost(JavaVersion)
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/a410aab6
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/a410aab6
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/a410aab6
Branch: refs/heads/master
Commit: a410aab6515931489dc2594d4e0f0ecac2c66071
Parents: aae1a0a
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Dec 10 17:48:06 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Dec 10 17:48:06 2018 -0700
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
.../org/apache/commons/lang3/JavaVersion.java | 15 +++++
.../org/apache/commons/lang3/SystemUtils.java | 22 +++++--
.../apache/commons/lang3/SystemUtilsTest.java | 67 ++++++++++++++++----
4 files changed, 86 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/a410aab6/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ec5555d..b1e02e6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -51,6 +51,7 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1415" type="update" dev="britter">Update Java Language requirement to 1.8</action>
<action issue="LANG-1411" type="add" dev="britter" due-to="Alexander Tsvetkov">Add isEmpty method to ObjectUtils</action>
<action issue="LANG-1422" type="add" dev="ggregory">Add null-safe StringUtils.valueOf(char[]) to delegate to String.valueOf(char[])</action>
+ <action issue="LANG-1427" type="add" dev="ggregory">Add API org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost(JavaVersion)</action>
</release>
<release version="3.8.1" date="2018-09-19" description="This release is a bugfix for Restoring Bundle-SymbolicName in the MANIFEST.mf file.">
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/a410aab6/src/main/java/org/apache/commons/lang3/JavaVersion.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java
index 148c99e..aacd3a1 100644
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java
@@ -141,6 +141,21 @@ public enum JavaVersion {
return this.value >= requiredVersion.value;
}
+ //-----------------------------------------------------------------------
+ /**
+ * <p>Whether this version of Java is at most the version of Java passed in.</p>
+ *
+ * <p>For example:<br>
+ * {@code myVersion.atMost(JavaVersion.JAVA_1_4)}<p>
+ *
+ * @param requiredVersion the version to check against, not null
+ * @return true if this version is equal to or greater than the specified version
+ * @since 3.9
+ */
+ public boolean atMost(final JavaVersion requiredVersion) {
+ return this.value <= requiredVersion.value;
+ }
+
/**
* Transforms the given string with a Java version number to the
* corresponding constant of this enumeration class. This method is used
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/a410aab6/src/main/java/org/apache/commons/lang3/SystemUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index a37229b..cc51f11 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -1679,12 +1679,6 @@ public class SystemUtils {
* Is the Java version at least the requested version.
* </p>
* <p>
- * Example input:
- * </p>
- * <ul>
- * <li>{@code 1.2f} to test for Java 1.2</li>
- * <li>{@code 1.31f} to test for Java 1.3.1</li>
- * </ul>
*
* @param requiredVersion the required version, for example 1.31f
* @return {@code true} if the actual version is equal or greater than the required version
@@ -1695,6 +1689,22 @@ public class SystemUtils {
/**
* <p>
+ * Is the Java version at most the requested version.
+ * </p>
+ * <p>
+ * Example input:
+ * </p>
+ *
+ * @param requiredVersion the required version, for example 1.31f
+ * @return {@code true} if the actual version is equal or greater than the required version
+ * @since 3.9
+ */
+ public static boolean isJavaVersionAtMost(final JavaVersion requiredVersion) {
+ return JAVA_SPECIFICATION_VERSION_AS_ENUM.atMost(requiredVersion);
+ }
+
+ /**
+ * <p>
* Decides if the Java version matches.
* </p>
* <p>
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/a410aab6/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
index e56d1b0..82dcd14 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -421,19 +421,7 @@ public class SystemUtilsTest {
@Test
public void testIsJavaVersionAtLeast() {
- if (SystemUtils.IS_JAVA_1_7) {
- 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));
- assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_1_8));
- assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_9));
- assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10));
- assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11));
- } else if (SystemUtils.IS_JAVA_1_8) {
+ if (SystemUtils.IS_JAVA_1_8) {
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_3));
@@ -485,6 +473,59 @@ public class SystemUtilsTest {
}
@Test
+ public void testIsJavaVersionAtMost() {
+ if (SystemUtils.IS_JAVA_1_8) {
+ 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));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_1_8));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_9));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_10));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
+ } else if (SystemUtils.IS_JAVA_9) {
+ 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));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_9));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_10));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
+ } else if (SystemUtils.IS_JAVA_10) {
+ 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));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_10));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
+ } else if (SystemUtils.IS_JAVA_11) {
+ 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));
+ assertTrue(SystemUtils.isJavaVersionAtMost(JAVA_11));
+ }
+ }
+
+ @Test
public void testOSMatchesName() {
String osName = null;
assertFalse(SystemUtils.isOSNameMatch(osName, "Windows"));
[2/2] [lang] Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/commons-lang.git
Posted by gg...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/commons-lang.git
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/e21cb463
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/e21cb463
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/e21cb463
Branch: refs/heads/master
Commit: e21cb463c0824425abaa5e2dd96c24d8f52de619
Parents: a410aab c368955
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Dec 10 17:48:30 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Dec 10 17:48:30 2018 -0700
----------------------------------------------------------------------
pom.xml | 2 +-
.../builder/StandardToStringStyleTest.java | 22 ++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------