|
18 | 18 |
|
19 | 19 | import com.navercorp.pinpoint.bootstrap.BootLogger; |
20 | 20 | import com.navercorp.pinpoint.bootstrap.util.ProfileConstants; |
| 21 | +import com.navercorp.pinpoint.bootstrap.util.StringUtils; |
21 | 22 |
|
22 | 23 | import java.nio.file.Path; |
23 | 24 | import java.nio.file.Paths; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Collections; |
24 | 27 | import java.util.List; |
25 | 28 | import java.util.Map; |
26 | 29 | import java.util.Objects; |
@@ -134,11 +137,55 @@ private String getActiveProfile(Properties defaultProperties) { |
134 | 137 | return supportedProfile.toString(); |
135 | 138 | } |
136 | 139 | } |
| 140 | + |
| 141 | + // handle alias |
| 142 | + String resolvedProfile = resolveAlias(defaultProperties, profile); |
| 143 | + if (resolvedProfile != null) { |
| 144 | + return resolvedProfile; |
| 145 | + } |
137 | 146 | throw new IllegalStateException("unsupported profile:" + profile); |
138 | 147 | } |
139 | 148 |
|
140 | 149 | private void loadProperties(Properties dstProperties, Properties property) { |
141 | 150 | Map<Object, Object> copy = PropertyLoaderUtils.filterAllowedPrefix(property); |
142 | 151 | dstProperties.putAll(copy); |
143 | 152 | } |
| 153 | + |
| 154 | + private String resolveAlias(Properties defaultProperties, String profile) { |
| 155 | + if (StringUtils.isEmpty(profile)) { |
| 156 | + return null; |
| 157 | + } |
| 158 | + |
| 159 | + for (Path supportedProfile : supportedProfiles) { |
| 160 | + String supportedProfileName = supportedProfile.toString(); |
| 161 | + String aliasesStr = javaSystemProperty.getProperty(ProfileConstants.PROFILE_ALIAS_KEY_PREFIX + supportedProfileName); |
| 162 | + if (aliasesStr == null) { |
| 163 | + aliasesStr = defaultProperties.getProperty(ProfileConstants.PROFILE_ALIAS_KEY_PREFIX + supportedProfileName); |
| 164 | + if (aliasesStr == null) { |
| 165 | + continue; |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + List<String> aliases = splitAndTrimToList(aliasesStr); |
| 170 | + for (String aliasForSupportedProfile : aliases) { |
| 171 | + if (aliasForSupportedProfile.equalsIgnoreCase(profile)) { |
| 172 | + logger.info(String.format("resolved profile alias: %s, profile: %s", profile, supportedProfileName)); |
| 173 | + return supportedProfileName; |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + return null; |
| 178 | + } |
| 179 | + |
| 180 | + private List<String> splitAndTrimToList(String str) { |
| 181 | + List<String> result = new ArrayList<>(); |
| 182 | + String[] splits = str.split(","); |
| 183 | + for (String part : splits) { |
| 184 | + String trimmed = part.trim(); |
| 185 | + if (!trimmed.isEmpty()) { |
| 186 | + result.add(trimmed); |
| 187 | + } |
| 188 | + } |
| 189 | + return result; |
| 190 | + } |
144 | 191 | } |
0 commit comments