Skip to content

Commit 9682386

Browse files
committed
Merge branch '2.4.x'
Closes gh-26139
2 parents 5142fe9 + 302d500 commit 9682386

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ String getDirectory() {
7474
return this.directory;
7575
}
7676

77+
String getProfile() {
78+
return this.profile;
79+
}
80+
7781
boolean isSkippable() {
7882
return this.configDataLocation.isOptional() || this.directory != null || this.profile != null;
7983
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ public Resource getResource() {
7474
return this.resource;
7575
}
7676

77+
/**
78+
* Return the profile or {@code null} if the resource is not profile specific.
79+
* @return the profile or {@code null}
80+
* @since 2.4.6
81+
*/
82+
public String getProfile() {
83+
return this.reference.getProfile();
84+
}
85+
7786
boolean isEmptyDirectory() {
7887
return this.emptyDirectory;
7988
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ void applyToAppliesPostProcessing() {
127127
assertThat(this.environment.getActiveProfiles()).containsExactly("dev");
128128
assertThat(listener.getAddedPropertySources()).hasSizeGreaterThan(0);
129129
assertThat(listener.getProfiles().getActive()).containsExactly("dev");
130+
assertThat(listener.getAddedPropertySources().stream().anyMatch((added) -> hasDevProfile(added.getResource())))
131+
.isTrue();
132+
}
133+
134+
private boolean hasDevProfile(ConfigDataResource resource) {
135+
return (resource instanceof StandardConfigDataResource)
136+
&& "dev".equals(((StandardConfigDataResource) resource).getProfile());
130137
}
131138

132139
}

0 commit comments

Comments
 (0)