Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
1907f3fe
Commit
1907f3fe
authored
Oct 22, 2020
by
Scott Frederick
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x'
Closes gh-23815
parents
2d8528d5
43cfebac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
1 deletion
+49
-1
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+21
-0
StandardConfigDataLocationResolver.java
...ot/context/config/StandardConfigDataLocationResolver.java
+6
-1
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+21
-0
testproperties.properties
...c/test/resources/config/.hidden/testproperties.properties
+1
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
1907f3fe
...
...
@@ -18,6 +18,8 @@ package org.springframework.boot.context.config;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
...
...
@@ -108,6 +110,7 @@ import org.springframework.util.StringUtils;
* @author Andy Wilkinson
* @author Eddú Meléndez
* @author Madhura Bhave
* @author Scott Frederick
* @since 1.0.0
* @deprecated since 2.4.0 in favor of {@link ConfigDataEnvironmentPostProcessor}
*/
...
...
@@ -504,6 +507,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
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
)
+
"]"
;
List
<
Document
>
documents
=
loadDocuments
(
loader
,
name
,
resource
);
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
)
{
if
(!
locationReference
.
contains
(
"*"
))
{
return
locationReference
;
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java
View file @
1907f3fe
...
...
@@ -49,6 +49,7 @@ import org.springframework.util.StringUtils;
*
* @author Madhura Bhave
* @author Phillip Webb
* @author Scott Frederick
* @since 2.4.0
*/
public
class
StandardConfigDataLocationResolver
...
...
@@ -304,7 +305,7 @@ public class StandardConfigDataLocationResolver
return
new
Resource
[]
{
directoryResource
};
}
File
directory
=
getDirectory
(
resourceLocationPattern
,
directoryResource
);
File
[]
subDirectories
=
directory
.
listFiles
(
File:
:
is
Directory
);
File
[]
subDirectories
=
directory
.
listFiles
(
this
::
isVisible
Directory
);
if
(
subDirectories
==
null
)
{
return
EMPTY_RESOURCES
;
}
...
...
@@ -340,4 +341,8 @@ public class StandardConfigDataLocationResolver
}
}
private
boolean
isVisibleDirectory
(
File
file
)
{
return
file
.
isDirectory
()
&&
!
file
.
getName
().
startsWith
(
"."
);
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
1907f3fe
...
...
@@ -69,6 +69,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Dave Syer
* @author Eddú Meléndez
* @author Madhura Bhave
* @author Scott Frederick
*/
@Deprecated
@ExtendWith
({
OutputCaptureExtension
.
class
,
UseLegacyProcessing
.
class
})
...
...
@@ -1075,6 +1076,16 @@ class ConfigFileApplicationListenerTests {
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
void
locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch
()
{
String
location
=
"file:src/test/resources/config/*/"
;
...
...
@@ -1119,6 +1130,16 @@ class ConfigFileApplicationListenerTests {
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
)
{
return
new
Condition
<
ConfigurableEnvironment
>(
"environment containing property source "
+
sourceName
)
{
...
...
spring-boot-project/spring-boot/src/test/resources/config/.hidden/testproperties.properties
0 → 100644
View file @
1907f3fe
fourth.property
=
shouldbehidden
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment