Skip to content

Commit

Permalink
[ISSUE alibaba#8622] enhance derivative logic of NacosClientProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
onewe committed Oct 21, 2022
1 parent f78bcd4 commit bbfc723
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ private SearchableProperties(PropertiesPropertySource propertiesPropertySource)
JVM_ARGS_PROPERTY_SOURCE, SYSTEM_ENV_PROPERTY_SOURCE, DEFAULT_SETTING_PROPERTY_SOURCE);
}

private SearchableProperties(PropertiesPropertySource propertiesPropertySource, List<AbstractPropertySource> propertySources) {
this.propertiesPropertySource = propertiesPropertySource;
this.propertySources = propertySources;
}

@Override
public String getProperty(String key) {
return getProperty(key, null);
Expand Down Expand Up @@ -216,7 +221,19 @@ private List<AbstractPropertySource> sortPropertySource(SourceType firstType,

@Override
public NacosClientProperties derive() {
return new SearchableProperties(new PropertiesPropertySource(this.propertiesPropertySource));
List<AbstractPropertySource> propertySources = new ArrayList<>(this.propertySources);
PropertiesPropertySource newPropertiesPropertySource = new PropertiesPropertySource(this.propertiesPropertySource);
int index = 0;
for (int i = 0; i < propertySources.size(); i++) {
final AbstractPropertySource abstractPropertySource = propertySources.get(i);
final SourceType type = abstractPropertySource.getType();
if (SourceType.PROPERTIES.equals(type)) {
index = i;
}
}
propertySources.set(index, newPropertiesPropertySource);

return new SearchableProperties(newPropertiesPropertySource, propertySources);
}

@Override
Expand Down

0 comments on commit bbfc723

Please sign in to comment.