From 59a7ec71a086215856a591f65a0603e1df92fd47 Mon Sep 17 00:00:00 2001 From: ruanwenjun Date: Fri, 11 Feb 2022 12:24:01 +0800 Subject: [PATCH 1/3] Using commons-lang3 to replace commons-lang --- CHANGES.md | 2 +- apollo-common/pom.xml | 4 +-- .../common/utils/UniqueKeyGenerator.java | 8 ++--- apollo-core/pom.xml | 4 +++ .../framework/foundation/internals/Utils.java | 23 ++++++++---- .../foundation/internals/UtilsTest.java | 36 +++---------------- .../openapi/service/ConsumerService.java | 8 ++--- .../ConfigPublishEmailBuilder.java | 5 +-- .../controller/ConfigsExportController.java | 2 +- .../portal/spi/ldap/LdapUserService.java | 2 +- .../portal/util/RelativeDateFormat.java | 3 +- pom.xml | 7 ++-- 12 files changed, 42 insertions(+), 62 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8591e044a15..244961d087c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -41,6 +41,6 @@ Apollo 2.0.0 * [Fix update user's password failure](https://github.com/apolloconfig/apollo/pull/4212) * [Fix bug: associated namespace display incorrect in text view](https://github.com/apolloconfig/apollo/pull/4219) * [Add Ordered interface to ProviderManager SPI](https://github.com/apolloconfig/apollo/pull/4218) - +* [Using commons-lang3 to replace commons-lang](https://github.com/apolloconfig/apollo/pull/4225) ------------------ All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1) diff --git a/apollo-common/pom.xml b/apollo-common/pom.xml index 03c98adeb33..54f3a2ed48b 100644 --- a/apollo-common/pom.xml +++ b/apollo-common/pom.xml @@ -78,8 +78,8 @@ janino - commons-lang - commons-lang + org.apache.commons + commons-lang3 diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java index facbb2331f0..f914c7bb490 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java @@ -16,12 +16,10 @@ */ package com.ctrip.framework.apollo.common.utils; -import com.google.common.base.Joiner; - import com.ctrip.framework.apollo.core.utils.ByteUtil; import com.ctrip.framework.apollo.core.utils.MachineUtil; - -import org.apache.commons.lang.time.FastDateFormat; +import com.google.common.base.Joiner; +import org.apache.commons.lang3.time.FastDateFormat; import java.security.SecureRandom; import java.util.Date; @@ -34,8 +32,6 @@ public class UniqueKeyGenerator { private static final AtomicInteger counter = new AtomicInteger(new SecureRandom().nextInt()); private static final Joiner KEY_JOINER = Joiner.on("-"); - - public static String generate(Object... args){ String hexIdString = ByteUtil.toHexString(toByteArray(Objects.hash(args), MachineUtil.getMachineIdentifier(), diff --git a/apollo-core/pom.xml b/apollo-core/pom.xml index 3292b1cf8a5..b0ed116bfd8 100644 --- a/apollo-core/pom.xml +++ b/apollo-core/pom.xml @@ -42,6 +42,10 @@ com.google.guava guava + + org.apache.commons + commons-lang3 + diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java index 1eeaff3225e..ae080b1641e 100755 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java +++ b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java @@ -16,18 +16,27 @@ */ package com.ctrip.framework.foundation.internals; -import com.google.common.base.Strings; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; public class Utils { + + /** + * Judge if the given string contains any char. + * + * @param str + * @return true if the given string is blank + */ public static boolean isBlank(String str) { - return Strings.nullToEmpty(str).trim().isEmpty(); + return StringUtils.isBlank(str); } + /** + * Judge if the system is windows. + * + * @return true if the current system is windows. + */ public static boolean isOSWindows() { - String osName = System.getProperty("os.name"); - if (Utils.isBlank(osName)) { - return false; - } - return osName.startsWith("Windows"); + return SystemUtils.IS_OS_WINDOWS; } } diff --git a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java index f3d63e3a4f2..769849ed0d6 100644 --- a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java +++ b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java @@ -25,11 +25,6 @@ public class UtilsTest { private final String actualOsName = System.getProperty("os.name"); - @After - public void tearDown() { - System.setProperty("os.name", actualOsName); - } - @Test public void isBlankTrueGivenNull() { assertTrue(Utils.isBlank(null)); @@ -57,32 +52,11 @@ public void isBlankFalseGivenWhitespacePadded() { @Test public void isOsWindowsTrueGivenWindows10() { - System.setProperty("os.name", "Windows 10"); - assertTrue(Utils.isOSWindows()); + if (actualOsName.startsWith("Windows")) { + assertTrue(Utils.isOSWindows()); + } else { + assertFalse(Utils.isOSWindows()); + } } - @Test - public void isOSWindowsFalseGivenMacOsX() { - System.setProperty("os.name", "Mac OS X"); - assertFalse(Utils.isOSWindows()); - } - - @Test - public void isOSWindowsFalseGivenBlank() { - System.setProperty("os.name", ""); - assertFalse(Utils.isOSWindows()); - } - - // Explicitly calling out case sensitivity; revisit if Microsoft changes naming convention - @Test - public void isOSWindowsFalseGivenAllUppercaseWindows() { - System.setProperty("os.name", "WINDOWS 10"); - assertFalse(Utils.isOSWindows()); - } - - @Test - public void isOSWindowsFalseGivenAllLowercaseWindows() { - System.setProperty("os.name", "windows 10"); - assertFalse(Utils.isOSWindows()); - } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java index ed8fd9a3290..b09efbc5f0a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java @@ -38,16 +38,16 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.hash.Hashing; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; -import org.apache.commons.lang.time.FastDateFormat; +import org.apache.commons.lang3.time.FastDateFormat; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * @author Jason Song(song_s@ctrip.com) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/emailbuilder/ConfigPublishEmailBuilder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/emailbuilder/ConfigPublishEmailBuilder.java index d90e17be709..ac54ab4b8d8 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/emailbuilder/ConfigPublishEmailBuilder.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/emailbuilder/ConfigPublishEmailBuilder.java @@ -16,7 +16,6 @@ */ package com.ctrip.framework.apollo.portal.component.emailbuilder; - import com.google.common.collect.Lists; import com.ctrip.framework.apollo.common.constants.ReleaseOperation; @@ -38,7 +37,7 @@ import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.util.RoleUtils; -import org.apache.commons.lang.time.FastDateFormat; +import org.apache.commons.lang3.time.FastDateFormat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; @@ -50,7 +49,6 @@ import java.util.Set; import java.util.regex.Matcher; - public abstract class ConfigPublishEmailBuilder { private static final String EMERGENCY_PUBLISH_TAG = "(紧急发布)"; @@ -81,7 +79,6 @@ public abstract class ConfigPublishEmailBuilder { protected FastDateFormat dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); - @Autowired private RolePermissionService rolePermissionService; @Autowired diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java index da0f09092cd..2f497523ad9 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java @@ -27,7 +27,7 @@ import com.ctrip.framework.apollo.portal.service.NamespaceService; import com.ctrip.framework.apollo.portal.util.NamespaceBOUtils; -import org.apache.commons.lang.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateFormatUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Lazy; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java index a0d32fe1bf2..578bc705c9c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java @@ -34,7 +34,7 @@ import java.util.TreeSet; import javax.naming.directory.Attribute; import javax.naming.ldap.LdapName; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.dao.EmptyResultDataAccessException; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java index 8c67076c787..072915f969e 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java @@ -16,7 +16,7 @@ */ package com.ctrip.framework.apollo.portal.util; -import org.apache.commons.lang.time.FastDateFormat; +import org.apache.commons.lang3.time.FastDateFormat; import java.time.Duration; import java.time.Instant; @@ -24,7 +24,6 @@ import java.time.ZoneId; import java.util.Date; - public class RelativeDateFormat { private static final FastDateFormat TIMESTAMP_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd"); diff --git a/pom.xml b/pom.xml index 89198a4e21b..b96bf01757a 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,7 @@ 1.6.2 3.23.1-GA 1.4.0 + 3.12.0 3.6.0 2.19.1 @@ -175,9 +176,9 @@ 5.0.1 - commons-lang - commons-lang - 2.6 + org.apache.commons + commons-lang3 + ${common-lang3.version} From e5a2763f249bcfbc4276e01259b1f5a10966f8f9 Mon Sep 17 00:00:00 2001 From: ruanwenjun Date: Sun, 13 Feb 2022 19:19:43 +0800 Subject: [PATCH 2/3] Rollback Utils#isOSWindows --- apollo-core/pom.xml | 4 --- .../framework/foundation/internals/Utils.java | 23 ++++-------- .../foundation/internals/UtilsTest.java | 36 ++++++++++++++++--- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/apollo-core/pom.xml b/apollo-core/pom.xml index b0ed116bfd8..3292b1cf8a5 100644 --- a/apollo-core/pom.xml +++ b/apollo-core/pom.xml @@ -42,10 +42,6 @@ com.google.guava guava - - org.apache.commons - commons-lang3 - diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java index ae080b1641e..1eeaff3225e 100755 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java +++ b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/Utils.java @@ -16,27 +16,18 @@ */ package com.ctrip.framework.foundation.internals; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.SystemUtils; +import com.google.common.base.Strings; public class Utils { - - /** - * Judge if the given string contains any char. - * - * @param str - * @return true if the given string is blank - */ public static boolean isBlank(String str) { - return StringUtils.isBlank(str); + return Strings.nullToEmpty(str).trim().isEmpty(); } - /** - * Judge if the system is windows. - * - * @return true if the current system is windows. - */ public static boolean isOSWindows() { - return SystemUtils.IS_OS_WINDOWS; + String osName = System.getProperty("os.name"); + if (Utils.isBlank(osName)) { + return false; + } + return osName.startsWith("Windows"); } } diff --git a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java index 769849ed0d6..73bb960aa41 100644 --- a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java +++ b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java @@ -25,6 +25,11 @@ public class UtilsTest { private final String actualOsName = System.getProperty("os.name"); + @After + public void tearDown() { + System.setProperty("os.name", actualOsName); + } + @Test public void isBlankTrueGivenNull() { assertTrue(Utils.isBlank(null)); @@ -52,11 +57,32 @@ public void isBlankFalseGivenWhitespacePadded() { @Test public void isOsWindowsTrueGivenWindows10() { - if (actualOsName.startsWith("Windows")) { - assertTrue(Utils.isOSWindows()); - } else { + System.setProperty("os.name", "Windows 10"); + assertTrue(Utils.isOSWindows()); + } + + @Test + public void isOSWindowsFalseGivenMacOsX() { + System.setProperty("os.name", "Mac OS X"); + assertFalse(Utils.isOSWindows()); + } + + @Test + public void isOSWindowsFalseGivenBlank() { + System.setProperty("os.name", ""); + assertFalse(Utils.isOSWindows()); + } + + // Explicitly calling out case sensitivity; revisit if Microsoft changes naming convention + @Test + public void isOSWindowsFalseGivenAllUppercaseWindows() { + System.setProperty("os.name", "WINDOWS 10"); + assertFalse(Utils.isOSWindows()); + } + + @Test + public void isOSWindowsFalseGivenAllLowercaseWindows() { + System.setProperty("os.name", "windows 10"); assertFalse(Utils.isOSWindows()); } } - -} From 8af33cff3c1be6478ad7e176f47796b3d7b6bfde Mon Sep 17 00:00:00 2001 From: ruanwenjun Date: Mon, 14 Feb 2022 18:43:27 +0800 Subject: [PATCH 3/3] Reverse change of UtilsTest --- .../com/ctrip/framework/foundation/internals/UtilsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java index 73bb960aa41..f3d63e3a4f2 100644 --- a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java +++ b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java @@ -83,6 +83,6 @@ public void isOSWindowsFalseGivenAllUppercaseWindows() { @Test public void isOSWindowsFalseGivenAllLowercaseWindows() { System.setProperty("os.name", "windows 10"); - assertFalse(Utils.isOSWindows()); - } + assertFalse(Utils.isOSWindows()); } +}