Support multiple labels in NativeEnvironmentRepository (#2454)
* Support multiple labels in NativeEnvironmentRepository Related to #2449 * Reverse labels --------- Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -210,9 +211,19 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc
|
||||
if (this.addLabelLocations) {
|
||||
for (String location : locations) {
|
||||
if (StringUtils.hasText(label)) {
|
||||
String labelled = location + label.trim() + "/";
|
||||
if (isDirectory(labelled)) {
|
||||
output.add(labelled);
|
||||
List<String> labels;
|
||||
if (label.contains(",")) {
|
||||
labels = Arrays.asList(StringUtils.commaDelimitedListToStringArray(label));
|
||||
Collections.reverse(labels);
|
||||
}
|
||||
else {
|
||||
labels = Collections.singletonList(label);
|
||||
}
|
||||
for (String l : labels) {
|
||||
String labelled = location + l + "/";
|
||||
if (isDirectory(labelled)) {
|
||||
output.add(labelled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,16 @@ public class NativeEnvironmentRepositoryTests {
|
||||
assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isNotEqualTo("dev_bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locationAddMultipleLabelLocations() {
|
||||
this.repository.setSearchLocations("classpath:/test/dev/");
|
||||
Environment environment = this.repository.findOne("foo", "development", "ignore,applicationxyz");
|
||||
assertThat(environment.getPropertySources()).hasSize(3);
|
||||
assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("app");
|
||||
assertThat(environment.getPropertySources().get(1).getSource().get("foo")).isEqualTo("default-app");
|
||||
assertThat(environment.getPropertySources().get(2).getSource().get("foo")).isEqualTo("dev_bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tryToStartReactive() {
|
||||
this.repository.setSearchLocations("classpath:/test/reactive/");
|
||||
|
||||
Reference in New Issue
Block a user