Skip to content

Commit 80610fa

Browse files
committed
Restore order of additional and active profiles
This commit restores the order of additional and active profiles so that active profiles now take precedence. Fixes gh-26189
1 parent 64e76ba commit 80610fa

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/Profiles.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,16 @@ private List<String> asReversedList(List<String> list) {
145145
return reversed;
146146
}
147147

148-
private List<String> asUniqueItemList(Collection<String> strings) {
149-
return asUniqueItemList(strings, null);
148+
private List<String> asUniqueItemList(Collection<String> profiles) {
149+
return asUniqueItemList(profiles, null);
150150
}
151151

152-
private List<String> asUniqueItemList(Collection<String> strings, Collection<String> additional) {
153-
LinkedHashSet<String> uniqueItems = new LinkedHashSet<>(strings);
152+
private List<String> asUniqueItemList(Collection<String> profiles, Collection<String> additional) {
153+
LinkedHashSet<String> uniqueItems = new LinkedHashSet<>();
154154
if (!CollectionUtils.isEmpty(additional)) {
155155
uniqueItems.addAll(additional);
156156
}
157+
uniqueItems.addAll(profiles);
157158
return Collections.unmodifiableList(new ArrayList<>(uniqueItems));
158159
}
159160

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,14 @@ void addProfiles() {
594594
}
595595

596596
@Test
597-
void addProfilesOrder() {
597+
void additionalProfilesOrderedBeforeActiveProfiles() {
598598
SpringApplication application = new SpringApplication(ExampleConfig.class);
599599
application.setWebApplicationType(WebApplicationType.NONE);
600600
application.setAdditionalProfiles("foo");
601601
ConfigurableEnvironment environment = new StandardEnvironment();
602602
application.setEnvironment(environment);
603603
this.context = application.run("--spring.profiles.active=bar,spam");
604-
// Since Boot 2.4 additional should always be last
605-
assertThat(environment.getActiveProfiles()).containsExactly("bar", "spam", "foo");
604+
assertThat(environment.getActiveProfiles()).containsExactly("foo", "bar", "spam");
606605
}
607606

608607
@Test

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void runWhenTwoProfilesSetProgrammaticallyLoadsWithPreservedProfileOrder() {
308308
void runWhenProfilesPresentBeforeConfigFileProcessingAugmentsProfileActivatedByConfigFile() {
309309
this.application.setAdditionalProfiles("other");
310310
ConfigurableApplicationContext context = this.application.run("--spring.config.name=enableprofile");
311-
assertThat(context.getEnvironment().getActiveProfiles()).containsExactly("myprofile", "other");
311+
assertThat(context.getEnvironment().getActiveProfiles()).containsExactly("other", "myprofile");
312312
String property = context.getEnvironment().getProperty("other.property");
313313
assertThat(property).isEqualTo("fromotherpropertiesfile");
314314
property = context.getEnvironment().getProperty("the.property");

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ProfilesTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ void getActiveWithProfileGroups() {
143143
@Test
144144
void getActiveWhenHasAdditionalIncludesAdditional() {
145145
MockEnvironment environment = new MockEnvironment();
146-
environment.setProperty("spring.profiles.active", "a,b,c");
146+
environment.setProperty("spring.profiles.active", "d,e,f");
147147
Binder binder = Binder.get(environment);
148-
Profiles profiles = new Profiles(environment, binder, Arrays.asList("d", "e", "f"));
148+
Profiles profiles = new Profiles(environment, binder, Arrays.asList("a", "b", "c"));
149149
assertThat(profiles.getActive()).containsExactly("a", "b", "c", "d", "e", "f");
150150
}
151151

0 commit comments

Comments
 (0)