Updates for boot 2.4.1 property source name.
Fixes gh-1771
This commit is contained in:
@@ -54,7 +54,7 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc
|
||||
private static final String[] DEFAULT_LOCATIONS = new String[] { "classpath:/", "classpath:/config/", "file:./",
|
||||
"file:./config/" };
|
||||
|
||||
static final Pattern RESOURCE_PATTERN = Pattern.compile("Config resource '(.*?)' via location.*");
|
||||
static final Pattern RESOURCE_PATTERN = Pattern.compile("Config resource '(.*?)' via location '(.*)'");
|
||||
|
||||
private static Log logger = LogFactory.getLog(NativeEnvironmentRepository.class);
|
||||
|
||||
@@ -226,12 +226,14 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc
|
||||
continue;
|
||||
}
|
||||
Matcher matcher = RESOURCE_PATTERN.matcher(name);
|
||||
String location = null;
|
||||
if (matcher.find()) {
|
||||
name = matcher.group(1);
|
||||
location = matcher.group(2);
|
||||
}
|
||||
// TODO: needed anymore?
|
||||
name = name.replace("applicationConfig: [", "");
|
||||
name = name.replace("file [", "");
|
||||
name = name.replace("file [", "file:");
|
||||
name = name.replace("]", "");
|
||||
if (this.searchLocations != null) {
|
||||
boolean matches = false;
|
||||
@@ -256,6 +258,15 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc
|
||||
matches = true;
|
||||
break;
|
||||
}
|
||||
if (location.startsWith("file:")) {
|
||||
location = StringUtils
|
||||
.cleanPath(new File(location.substring("file:".length())).getAbsolutePath()) + "/";
|
||||
}
|
||||
if (location != null && location.startsWith(pattern)
|
||||
&& !location.substring(pattern.length()).contains("/")) {
|
||||
matches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matches) {
|
||||
// Don't include this one: it wasn't matched by our search locations
|
||||
|
||||
@@ -102,6 +102,26 @@ public class NativeEnvironmentRepositoryTests {
|
||||
assertThat(environment.getPropertySources().get(0).getName().contains("application-dev.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanBoot240Classpath() {
|
||||
Environment environment = new Environment("application");
|
||||
environment.add(new PropertySource(
|
||||
"Config resource 'classpath:/configs/application-myprofile.yml' via location 'classpath:/configs/' (document #0)",
|
||||
Collections.singletonMap("foo", "bar")));
|
||||
assertThat(environment.getPropertySources().size()).isEqualTo(1);
|
||||
assertThat(environment.getPropertySources().get(0).getName().contains("application-myprofile.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanBoot241Classpath() {
|
||||
Environment environment = new Environment("application");
|
||||
environment.add(new PropertySource(
|
||||
"Config resource 'class path resource [configs/application.yml]' via location 'classpath:/configs/' (document #0)",
|
||||
Collections.singletonMap("foo", "bar")));
|
||||
assertThat(environment.getPropertySources().size()).isEqualTo(1);
|
||||
assertThat(environment.getPropertySources().get(0).getName().contains("application-myprofile.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // FIXME: configdata
|
||||
public void labelled() {
|
||||
|
||||
Reference in New Issue
Block a user