From 971b412659a78b5fa694461c051ba03f7b33aecd Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 26 May 2023 08:04:23 +0800 Subject: [PATCH] Fix the issue that env special case handling is missing in some case --- CHANGES.md | 1 + .../apollo/portal/environment/Env.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e0d83c9f574..dda6ea314c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,7 @@ Apollo 2.2.0 * [feat: check port use by another process or not when startup](https://github.com/apolloconfig/apollo/pull/4656) * [Bump springboot version from 2.7.9 to 2.7.11](https://github.com/apolloconfig/apollo/pull/4828) * [[Multi-Database Support][h2] Support run on h2](https://github.com/apolloconfig/apollo/pull/4851) +* [Fix the issue that env special case handling is missing in some case](https://github.com/apolloconfig/apollo/pull/4887) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/13?closed=1) \ No newline at end of file diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/environment/Env.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/environment/Env.java index 4b9c5707b7b..17c4a30f46d 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/environment/Env.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/environment/Env.java @@ -41,10 +41,10 @@ public class Env { com.ctrip.framework.apollo.core.enums.Env.LOCAL.name()); public static final Env DEV = addEnvironment( com.ctrip.framework.apollo.core.enums.Env.DEV.name()); - public static final Env FWS = addEnvironment( - com.ctrip.framework.apollo.core.enums.Env.FWS.name()); public static final Env FAT = addEnvironment( com.ctrip.framework.apollo.core.enums.Env.FAT.name()); + public static final Env FWS = addEnvironment( + com.ctrip.framework.apollo.core.enums.Env.FWS.name()); public static final Env UAT = addEnvironment( com.ctrip.framework.apollo.core.enums.Env.UAT.name()); public static final Env LPT = addEnvironment( @@ -77,7 +77,20 @@ private static String getWellFormName(String envName) { if (StringUtils.isBlank(envName)) { return ""; } - return envName.trim().toUpperCase(); + + String envWellFormName = envName.trim().toUpperCase(); + + // special case for production in case of typo + if ("PROD".equals(envWellFormName)) { + return Env.PRO.name; + } + + // special case that FAT & FWS should map to FAT + if ("FWS".equals(envWellFormName)) { + return Env.FAT.name; + } + + return envWellFormName; } /** @@ -88,15 +101,6 @@ private static String getWellFormName(String envName) { */ public static Env transformEnv(String envName) { final String envWellFormName = getWellFormName(envName); - // special case for production in case of typo - if ("PROD".equalsIgnoreCase(envWellFormName)) { - return Env.PRO; - } - - // special case that FAT & FWS should map to FAT - if ("FWS".equalsIgnoreCase(envWellFormName)) { - return Env.FAT; - } if (Env.exists(envWellFormName)) { return Env.valueOf(envWellFormName);