Support application name with dashes (#2177)

This commit is contained in:
woshikid
2022-11-03 08:21:15 +08:00
committed by GitHub
parent 828de40108
commit e302c12db7
2 changed files with 14 additions and 15 deletions

View File

@@ -107,18 +107,17 @@ public class PropertyPathEndpoint implements ApplicationEventPublisherAware {
if (path != null) {
String stem = StringUtils.stripFilenameExtension(StringUtils.getFilename(StringUtils.cleanPath(path)));
// TODO: correlate with service registry
int index = stem.indexOf("-");
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 {
services.add(name);
String name = stem + "-";
int index;
// support application name with dashes
while ((index = name.lastIndexOf("-")) >= 0) {
name = name.substring(0, index);
if ("application".equals(name)) {
services.add("*");
}
else {
services.add(name);
}
}
}
return services;

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("[*]");
.isEqualTo("[application-local, *]");
}
@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]");
.toString()).isEqualTo("[foo-local, foo]");
}
@Test
public void testNotifyMultiDash() {
assertThat(this.endpoint.notifyByPath(new HttpHeaders(), Collections.singletonMap("path", "foo-local-dev.yml"))
.toString()).isEqualTo("[foo]");
.toString()).isEqualTo("[foo-local-dev, foo-local, foo]");
}
}