Skip to content

Commit

Permalink
Using commons-lang3 to replace commons-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanwenjun committed Feb 11, 2022
1 parent 9d27eb8 commit 59a7ec7
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions apollo-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
<artifactId>janino</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<!-- Micrometer core dependecy -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions apollo-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- end of util -->
<!-- log -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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([email protected])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -50,7 +49,6 @@
import java.util.Set;
import java.util.regex.Matcher;


public abstract class ConfigPublishEmailBuilder {

private static final String EMERGENCY_PUBLISH_TAG = "<span style='color:red'>(紧急发布)</span>";
Expand Down Expand Up @@ -81,7 +79,6 @@ public abstract class ConfigPublishEmailBuilder {

protected FastDateFormat dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");


@Autowired
private RolePermissionService rolePermissionService;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
*/
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;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;


public class RelativeDateFormat {
private static final FastDateFormat TIMESTAMP_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd");

Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<javax.mail.version>1.6.2</javax.mail.version>
<javassist.version>3.23.1-GA</javassist.version>
<nacos-discovery-api.version>1.4.0</nacos-discovery-api.version>
<common-lang3.version>3.12.0</common-lang3.version>
<!-- Plugins Version -->
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
Expand Down Expand Up @@ -175,9 +176,9 @@
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${common-lang3.version}</version>
</dependency>
<!-- to fix CVE-2020-26217 -->
<dependency>
Expand Down

0 comments on commit 59a7ec7

Please sign in to comment.