commit
1907f3fe1e
|
@ -18,6 +18,8 @@ package org.springframework.boot.context.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -108,6 +110,7 @@ import org.springframework.util.StringUtils;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
|
* @author Scott Frederick
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @deprecated since 2.4.0 in favor of {@link ConfigDataEnvironmentPostProcessor}
|
* @deprecated since 2.4.0 in favor of {@link ConfigDataEnvironmentPostProcessor}
|
||||||
*/
|
*/
|
||||||
|
@ -504,6 +507,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (resource.isFile() && hasHiddenPathElement(resource)) {
|
||||||
|
if (this.logger.isTraceEnabled()) {
|
||||||
|
StringBuilder description = getDescription("Skipped location with hidden path element ",
|
||||||
|
location, resource, profile);
|
||||||
|
this.logger.trace(description);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String name = "applicationConfig: [" + getLocationName(location, resource) + "]";
|
String name = "applicationConfig: [" + getLocationName(location, resource) + "]";
|
||||||
List<Document> documents = loadDocuments(loader, name, resource);
|
List<Document> documents = loadDocuments(loader, name, resource);
|
||||||
if (CollectionUtils.isEmpty(documents)) {
|
if (CollectionUtils.isEmpty(documents)) {
|
||||||
|
@ -540,6 +551,16 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasHiddenPathElement(Resource resource) throws IOException {
|
||||||
|
String cleanPath = StringUtils.cleanPath(resource.getFile().getAbsolutePath());
|
||||||
|
for (Path value : Paths.get(cleanPath)) {
|
||||||
|
if (value.toString().startsWith(".")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private String getLocationName(String locationReference, Resource resource) {
|
private String getLocationName(String locationReference, Resource resource) {
|
||||||
if (!locationReference.contains("*")) {
|
if (!locationReference.contains("*")) {
|
||||||
return locationReference;
|
return locationReference;
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.springframework.util.StringUtils;
|
||||||
*
|
*
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Scott Frederick
|
||||||
* @since 2.4.0
|
* @since 2.4.0
|
||||||
*/
|
*/
|
||||||
public class StandardConfigDataLocationResolver
|
public class StandardConfigDataLocationResolver
|
||||||
|
@ -304,7 +305,7 @@ public class StandardConfigDataLocationResolver
|
||||||
return new Resource[] { directoryResource };
|
return new Resource[] { directoryResource };
|
||||||
}
|
}
|
||||||
File directory = getDirectory(resourceLocationPattern, directoryResource);
|
File directory = getDirectory(resourceLocationPattern, directoryResource);
|
||||||
File[] subDirectories = directory.listFiles(File::isDirectory);
|
File[] subDirectories = directory.listFiles(this::isVisibleDirectory);
|
||||||
if (subDirectories == null) {
|
if (subDirectories == null) {
|
||||||
return EMPTY_RESOURCES;
|
return EMPTY_RESOURCES;
|
||||||
}
|
}
|
||||||
|
@ -340,4 +341,8 @@ public class StandardConfigDataLocationResolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isVisibleDirectory(File file) {
|
||||||
|
return file.isDirectory() && !file.getName().startsWith(".");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
|
* @author Scott Frederick
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ExtendWith({ OutputCaptureExtension.class, UseLegacyProcessing.class })
|
@ExtendWith({ OutputCaptureExtension.class, UseLegacyProcessing.class })
|
||||||
|
@ -1075,6 +1076,16 @@ class ConfigFileApplicationListenerTests {
|
||||||
assertThat(this.environment.getProperty("third.property")).isNull();
|
assertThat(this.environment.getProperty("third.property")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void locationsWithWildcardDirectoriesShouldIgnoreHiddenDirectories() {
|
||||||
|
String location = "file:src/test/resources/config/*/";
|
||||||
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
|
||||||
|
"spring.config.location=" + location);
|
||||||
|
this.initializer.setSearchNames("testproperties");
|
||||||
|
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||||
|
assertThat(this.environment.getProperty("fourth.property")).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch() {
|
void locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch() {
|
||||||
String location = "file:src/test/resources/config/*/";
|
String location = "file:src/test/resources/config/*/";
|
||||||
|
@ -1119,6 +1130,16 @@ class ConfigFileApplicationListenerTests {
|
||||||
assertThat(second).isEqualTo("ball");
|
assertThat(second).isEqualTo("ball");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void locationsWithWildcardFilesShouldIgnoreHiddenDirectories() {
|
||||||
|
String location = "file:src/test/resources/config/*/testproperties.properties";
|
||||||
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
|
||||||
|
"spring.config.location=" + location);
|
||||||
|
this.initializer.setSearchNames("testproperties");
|
||||||
|
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||||
|
assertThat(this.environment.getProperty("fourth.property")).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
private Condition<ConfigurableEnvironment> matchingPropertySource(final String sourceName) {
|
private Condition<ConfigurableEnvironment> matchingPropertySource(final String sourceName) {
|
||||||
return new Condition<ConfigurableEnvironment>("environment containing property source " + sourceName) {
|
return new Condition<ConfigurableEnvironment>("environment containing property source " + sourceName) {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
fourth.property=shouldbehidden
|
Loading…
Reference in New Issue