mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Add StandardConfigDataResource.getProfile method
Add a `StandardConfigDataResource.getProfile()` method so that it's possible to tell the profile used when reading a profile specific resource. Fixes gh-25940
This commit is contained in:
parent
270bf0f937
commit
302d500ee9
@ -74,6 +74,10 @@ class StandardConfigDataReference {
|
||||
return this.directory;
|
||||
}
|
||||
|
||||
String getProfile() {
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
boolean isSkippable() {
|
||||
return this.configDataLocation.isOptional() || this.directory != null || this.profile != null;
|
||||
}
|
||||
|
@ -74,6 +74,15 @@ public class StandardConfigDataResource extends ConfigDataResource {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the profile or {@code null} if the resource is not profile specific.
|
||||
* @return the profile or {@code null}
|
||||
* @since 2.4.6
|
||||
*/
|
||||
public String getProfile() {
|
||||
return this.reference.getProfile();
|
||||
}
|
||||
|
||||
boolean isEmptyDirectory() {
|
||||
return this.emptyDirectory;
|
||||
}
|
||||
|
@ -127,6 +127,13 @@ class ConfigDataEnvironmentPostProcessorTests {
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("dev");
|
||||
assertThat(listener.getAddedPropertySources()).hasSizeGreaterThan(0);
|
||||
assertThat(listener.getProfiles().getActive()).containsExactly("dev");
|
||||
assertThat(listener.getAddedPropertySources().stream().anyMatch((added) -> hasDevProfile(added.getResource())))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
private boolean hasDevProfile(ConfigDataResource resource) {
|
||||
return (resource instanceof StandardConfigDataResource)
|
||||
&& "dev".equals(((StandardConfigDataResource) resource).getProfile());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user