|
|
|
@ -18,6 +18,8 @@
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.polaris.config.adapter;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
@ -123,46 +125,49 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
|
|
|
|
|
|
// priority: application-${profile} > application > boostrap-${profile} > boostrap
|
|
|
|
|
String[] activeProfiles = environment.getActiveProfiles();
|
|
|
|
|
buildInternalConfigFiles(internalConfigFiles, namespace, serviceName, activeProfiles);
|
|
|
|
|
|
|
|
|
|
// Compatible with defaultProfiles configuration
|
|
|
|
|
if (ArrayUtils.isEmpty(activeProfiles)) {
|
|
|
|
|
String[] defaultProfiles = environment.getDefaultProfiles();
|
|
|
|
|
buildInternalConfigFiles(internalConfigFiles, namespace, serviceName, defaultProfiles);
|
|
|
|
|
List<String> profileList = new ArrayList<>();
|
|
|
|
|
if (ArrayUtils.isNotEmpty(activeProfiles)) {
|
|
|
|
|
profileList.addAll(Arrays.asList(activeProfiles));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// build default config properties files .
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties"));
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml"));
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties"));
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml"));
|
|
|
|
|
else if (ArrayUtils.isNotEmpty(defaultProfiles)) {
|
|
|
|
|
profileList.addAll(Arrays.asList(defaultProfiles));
|
|
|
|
|
}
|
|
|
|
|
// build application config files
|
|
|
|
|
buildInternalApplicationConfigFiles(internalConfigFiles, namespace, serviceName, profileList);
|
|
|
|
|
// build bootstrap config files
|
|
|
|
|
buildInternalBootstrapConfigFiles(internalConfigFiles, namespace, serviceName, profileList);
|
|
|
|
|
|
|
|
|
|
return internalConfigFiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buildInternalConfigFiles(List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, String[] profiles) {
|
|
|
|
|
|
|
|
|
|
if (profiles != null) {
|
|
|
|
|
for (String profile : profiles) {
|
|
|
|
|
private void buildInternalApplicationConfigFiles(
|
|
|
|
|
List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, List<String> profileList) {
|
|
|
|
|
for (String profile : profileList) {
|
|
|
|
|
if (!StringUtils.hasText(profile)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".properties"));
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".yml"));
|
|
|
|
|
}
|
|
|
|
|
// build default config properties files.
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties"));
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String profile : profiles) {
|
|
|
|
|
private void buildInternalBootstrapConfigFiles(
|
|
|
|
|
List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, List<String> profileList) {
|
|
|
|
|
for (String profile : profileList) {
|
|
|
|
|
if (!StringUtils.hasText(profile)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".properties"));
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".yml"));
|
|
|
|
|
}
|
|
|
|
|
// build default config properties files.
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties"));
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource,
|
|
|
|
|
List<ConfigFileGroup> configFileGroups) {
|
|
|
|
|