1818
1919import com .navercorp .pinpoint .bootstrap .BootLogger ;
2020import com .navercorp .pinpoint .bootstrap .util .ProfileConstants ;
21+ import com .navercorp .pinpoint .bootstrap .util .StringUtils ;
2122
2223import java .nio .file .Path ;
2324import java .nio .file .Paths ;
@@ -116,12 +117,7 @@ private void saveAgentRootPath(Path agentRootPath, Properties properties) {
116117
117118
118119 private String getActiveProfile (Properties defaultProperties ) {
119- // env option support??
120- // String envProfile = System.getenv(ACTIVE_PROFILE_KEY);
121- String profile = javaSystemProperty .getProperty (ProfileConstants .ACTIVE_PROFILE_KEY );
122- if (profile == null ) {
123- profile = defaultProperties .getProperty (ProfileConstants .ACTIVE_PROFILE_KEY );
124- }
120+ String profile = getProfileProperties (defaultProperties , ProfileConstants .ACTIVE_PROFILE_KEY );
125121 if (profile == null ) {
126122 throw new RuntimeException ("Failed to detect pinpoint profile. Please add -D" +
127123 ProfileConstants .ACTIVE_PROFILE_KEY +
@@ -134,11 +130,46 @@ private String getActiveProfile(Properties defaultProperties) {
134130 return supportedProfile .toString ();
135131 }
136132 }
133+
134+ // handle alias
135+ for (Path supportedProfile : supportedProfiles ) {
136+ String supportedProfileName = supportedProfile .toString ();
137+ String aliasesStr = getProfileProperties (defaultProperties , ProfileConstants .PROFILE_ALIAS_KEY_PREFIX + supportedProfileName );
138+ if (containsAlias (aliasesStr , profile )) {
139+ logger .info (String .format ("resolved profile alias '%s' to supported profile '%s'" , profile , supportedProfileName ));
140+ return supportedProfileName ;
141+ }
142+ }
137143 throw new IllegalStateException ("unsupported profile:" + profile );
138144 }
139145
146+ private String getProfileProperties (Properties defaultProperties , String key ) {
147+ // env option support??
148+ // String envProfile = System.getenv(ACTIVE_PROFILE_KEY);
149+ String value = javaSystemProperty .getProperty (key );
150+ if (value == null ) {
151+ value = defaultProperties .getProperty (key );
152+ }
153+ return value ;
154+ }
155+
156+
140157 private void loadProperties (Properties dstProperties , Properties property ) {
141158 Map <Object , Object > copy = PropertyLoaderUtils .filterAllowedPrefix (property );
142159 dstProperties .putAll (copy );
143160 }
161+
162+ private boolean containsAlias (String aliasesStr , String profile ) {
163+ if (StringUtils .isEmpty (aliasesStr )) {
164+ return false ;
165+ }
166+
167+ String [] aliases = aliasesStr .split ("," );
168+ for (String alias : aliases ) {
169+ if (profile .equalsIgnoreCase (alias .trim ())) {
170+ return true ;
171+ }
172+ }
173+ return false ;
174+ }
144175}
0 commit comments