commit
110c36e607
|
|
@ -148,15 +148,16 @@ public class Profiles implements Iterable<String> {
|
||||||
return reversed;
|
return reversed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> asUniqueItemList(Collection<String> strings) {
|
private List<String> asUniqueItemList(Collection<String> profiles) {
|
||||||
return asUniqueItemList(strings, null);
|
return asUniqueItemList(profiles, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> asUniqueItemList(Collection<String> strings, Collection<String> additional) {
|
private List<String> asUniqueItemList(Collection<String> profiles, Collection<String> additional) {
|
||||||
LinkedHashSet<String> uniqueItems = new LinkedHashSet<>(strings);
|
LinkedHashSet<String> uniqueItems = new LinkedHashSet<>();
|
||||||
if (!CollectionUtils.isEmpty(additional)) {
|
if (!CollectionUtils.isEmpty(additional)) {
|
||||||
uniqueItems.addAll(additional);
|
uniqueItems.addAll(additional);
|
||||||
}
|
}
|
||||||
|
uniqueItems.addAll(profiles);
|
||||||
return Collections.unmodifiableList(new ArrayList<>(uniqueItems));
|
return Collections.unmodifiableList(new ArrayList<>(uniqueItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -592,15 +592,14 @@ class SpringApplicationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addProfilesOrder() {
|
void additionalProfilesOrderedBeforeActiveProfiles() {
|
||||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
application.setWebApplicationType(WebApplicationType.NONE);
|
||||||
application.setAdditionalProfiles("foo");
|
application.setAdditionalProfiles("foo");
|
||||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||||
application.setEnvironment(environment);
|
application.setEnvironment(environment);
|
||||||
this.context = application.run("--spring.profiles.active=bar,spam");
|
this.context = application.run("--spring.profiles.active=bar,spam");
|
||||||
// Since Boot 2.4 additional should always be last
|
assertThat(environment.getActiveProfiles()).containsExactly("foo", "bar", "spam");
|
||||||
assertThat(environment.getActiveProfiles()).containsExactly("bar", "spam", "foo");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -308,7 +308,7 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
|
||||||
void runWhenProfilesPresentBeforeConfigFileProcessingAugmentsProfileActivatedByConfigFile() {
|
void runWhenProfilesPresentBeforeConfigFileProcessingAugmentsProfileActivatedByConfigFile() {
|
||||||
this.application.setAdditionalProfiles("other");
|
this.application.setAdditionalProfiles("other");
|
||||||
ConfigurableApplicationContext context = this.application.run("--spring.config.name=enableprofile");
|
ConfigurableApplicationContext context = this.application.run("--spring.config.name=enableprofile");
|
||||||
assertThat(context.getEnvironment().getActiveProfiles()).containsExactly("myprofile", "other");
|
assertThat(context.getEnvironment().getActiveProfiles()).containsExactly("other", "myprofile");
|
||||||
String property = context.getEnvironment().getProperty("other.property");
|
String property = context.getEnvironment().getProperty("other.property");
|
||||||
assertThat(property).isEqualTo("fromotherpropertiesfile");
|
assertThat(property).isEqualTo("fromotherpropertiesfile");
|
||||||
property = context.getEnvironment().getProperty("the.property");
|
property = context.getEnvironment().getProperty("the.property");
|
||||||
|
|
|
||||||
|
|
@ -143,9 +143,9 @@ class ProfilesTests {
|
||||||
@Test
|
@Test
|
||||||
void getActiveWhenHasAdditionalIncludesAdditional() {
|
void getActiveWhenHasAdditionalIncludesAdditional() {
|
||||||
MockEnvironment environment = new MockEnvironment();
|
MockEnvironment environment = new MockEnvironment();
|
||||||
environment.setProperty("spring.profiles.active", "a,b,c");
|
environment.setProperty("spring.profiles.active", "d,e,f");
|
||||||
Binder binder = Binder.get(environment);
|
Binder binder = Binder.get(environment);
|
||||||
Profiles profiles = new Profiles(environment, binder, Arrays.asList("d", "e", "f"));
|
Profiles profiles = new Profiles(environment, binder, Arrays.asList("a", "b", "c"));
|
||||||
assertThat(profiles.getActive()).containsExactly("a", "b", "c", "d", "e", "f");
|
assertThat(profiles.getActive()).containsExactly("a", "b", "c", "d", "e", "f");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue