Commit 302d500e authored by Phillip Webb's avatar Phillip Webb

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
parent 270bf0f9
......@@ -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());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment