Update PropertyPathEndpoint to ignore profiles - Fixes gh-2138 (#2139)

This commit is contained in:
kid
2022-09-13 20:38:26 +08:00
committed by GitHub
parent 3a3af768b5
commit 15f26c0040
2 changed files with 9 additions and 15 deletions

View File

@@ -108,22 +108,16 @@ public class PropertyPathEndpoint implements ApplicationEventPublisherAware {
String stem = StringUtils.stripFilenameExtension(StringUtils.getFilename(StringUtils.cleanPath(path)));
// TODO: correlate with service registry
int index = stem.indexOf("-");
while (index >= 0) {
String name = stem.substring(0, index);
String profile = stem.substring(index + 1);
if ("application".equals(name)) {
services.add("*:" + profile);
}
else if (!name.startsWith("application")) {
services.add(name + ":" + profile);
}
index = stem.indexOf("-", index + 1);
}
String name = stem;
if (index > 0) {
name = stem.substring(0, index);
}
// foo.properties is targeted at the foo application,
// while application.properties is targeted at all applications
if ("application".equals(name)) {
services.add("*");
}
else if (!name.startsWith("application")) {
else {
services.add(name);
}
}

View File

@@ -72,7 +72,7 @@ public class PropertyPathEndpointTests {
public void testNotifyAllWithProfile() {
assertThat(this.endpoint
.notifyByPath(new HttpHeaders(), Collections.singletonMap("path", "application-local.yml")).toString())
.isEqualTo("[*:local]");
.isEqualTo("[*]");
}
@Test
@@ -92,13 +92,13 @@ public class PropertyPathEndpointTests {
@Test
public void testNotifyOneWithProfile() {
assertThat(this.endpoint.notifyByPath(new HttpHeaders(), Collections.singletonMap("path", "foo-local.yml"))
.toString()).isEqualTo("[foo:local, foo-local]");
.toString()).isEqualTo("[foo]");
}
@Test
public void testNotifyMultiDash() {
assertThat(this.endpoint.notifyByPath(new HttpHeaders(), Collections.singletonMap("path", "foo-local-dev.yml"))
.toString()).isEqualTo("[foo:local-dev, foo-local:dev, foo-local-dev]");
.toString()).isEqualTo("[foo]");
}
}