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
ba0fe1ed
Commit
ba0fe1ed
authored
May 17, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-26581 Closes gh-26582 Closes gh-26583
parents
2bbad949
c45bb2bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
12 deletions
+53
-12
StandardConfigDataLocationResolver.java
...ot/context/config/StandardConfigDataLocationResolver.java
+25
-9
ConfigDataEnvironmentPostProcessorIntegrationTests.java
...g/ConfigDataEnvironmentPostProcessorIntegrationTests.java
+28
-3
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java
View file @
ba0fe1ed
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.context.config;
import
java.io.File
;
import
java.util.ArrayDeque
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Deque
;
...
...
@@ -27,6 +28,7 @@ import java.util.List;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
import
org.apache.commons.logging.Log
;
...
...
@@ -244,19 +246,33 @@ public class StandardConfigDataLocationResolver
Set
<
StandardConfigDataReference
>
references
)
{
Set
<
StandardConfigDataResource
>
empty
=
new
LinkedHashSet
<>();
for
(
StandardConfigDataReference
reference
:
references
)
{
if
(
reference
.
isMandatoryDirectory
())
{
Resource
resource
=
this
.
resourceLoader
.
getResource
(
reference
.
getDirectory
());
if
(
resource
instanceof
ClassPathResource
)
{
continue
;
}
StandardConfigDataResource
configDataResource
=
new
StandardConfigDataResource
(
reference
,
resource
);
ConfigDataResourceNotFoundException
.
throwIfDoesNotExist
(
configDataResource
,
resource
);
empty
.
add
(
new
StandardConfigDataResource
(
reference
,
resource
,
true
));
}
empty
.
addAll
(
resolveEmptyDirectories
(
reference
));
}
return
empty
;
}
private
Set
<
StandardConfigDataResource
>
resolveEmptyDirectories
(
StandardConfigDataReference
reference
)
{
if
(!
this
.
resourceLoader
.
isPattern
(
reference
.
getResourceLocation
()))
{
return
resolveNonPatternEmptyDirectories
(
reference
);
}
return
resolvePatternEmptyDirectories
(
reference
);
}
private
Set
<
StandardConfigDataResource
>
resolveNonPatternEmptyDirectories
(
StandardConfigDataReference
reference
)
{
Resource
resource
=
this
.
resourceLoader
.
getResource
(
reference
.
getDirectory
());
return
(
resource
instanceof
ClassPathResource
||
!
resource
.
exists
())
?
Collections
.
emptySet
()
:
Collections
.
singleton
(
new
StandardConfigDataResource
(
reference
,
resource
,
true
));
}
private
Set
<
StandardConfigDataResource
>
resolvePatternEmptyDirectories
(
StandardConfigDataReference
reference
)
{
Resource
[]
resources
=
this
.
resourceLoader
.
getResources
(
reference
.
getDirectory
(),
ResourceType
.
DIRECTORY
);
Assert
.
state
(
resources
.
length
>
0
,
"No subdirectories found for mandatory directory location '"
+
reference
.
getDirectory
()
+
"'."
);
return
Arrays
.
stream
(
resources
).
filter
(
Resource:
:
exists
)
.
map
((
resource
)
->
new
StandardConfigDataResource
(
reference
,
resource
,
true
))
.
collect
(
Collectors
.
toCollection
(
LinkedHashSet:
:
new
));
}
private
List
<
StandardConfigDataResource
>
resolve
(
StandardConfigDataReference
reference
)
{
if
(!
this
.
resourceLoader
.
isPattern
(
reference
.
getResourceLocation
()))
{
return
resolveNonPattern
(
reference
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java
View file @
ba0fe1ed
...
...
@@ -547,7 +547,7 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
@Test
void
runWhenConfigLocationHasNonOptionalMissingFileDirectoryThrowsResourceNotFoundException
()
{
File
location
=
new
File
(
this
.
temp
,
"application.unknown"
);
assertThatExceptionOfType
(
ConfigData
Resource
NotFoundException
.
class
).
isThrownBy
(()
->
this
.
application
assertThatExceptionOfType
(
ConfigData
Location
NotFoundException
.
class
).
isThrownBy
(()
->
this
.
application
.
run
(
"--spring.config.location="
+
StringUtils
.
cleanPath
(
location
.
getAbsolutePath
())
+
"/"
));
}
...
...
@@ -566,6 +566,12 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
.
run
(
"--spring.config.location="
+
StringUtils
.
cleanPath
(
location
.
getAbsolutePath
())
+
"/"
));
}
@Test
void
runWhenConfigLocationHasMandatoryDirectoryThatDoesntExistThrowsException
()
{
assertThatExceptionOfType
(
ConfigDataLocationNotFoundException
.
class
).
isThrownBy
(
()
->
this
.
application
.
run
(
"--spring.config.location="
+
StringUtils
.
cleanPath
(
"invalid/"
)));
}
@Test
void
runWhenConfigLocationHasNonOptionalEmptyFileDoesNotThrowException
()
throws
IOException
{
File
location
=
new
File
(
this
.
temp
,
"application.properties"
);
...
...
@@ -686,13 +692,32 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
@Test
void
runWhenHasWildcardLocationLoadsFromAllMatchingLocations
()
{
ConfigurableApplicationContext
context
=
this
.
application
.
run
(
"--spring.config.location=optional:file:src/test/resources/config/*/"
,
"--spring.config.name=testproperties"
);
"--spring.config.location=file:src/test/resources/config/*/"
,
"--spring.config.name=testproperties"
);
ConfigurableEnvironment
environment
=
context
.
getEnvironment
();
assertThat
(
environment
.
getProperty
(
"first.property"
)).
isEqualTo
(
"apple"
);
assertThat
(
environment
.
getProperty
(
"second.property"
)).
isEqualTo
(
"ball"
);
}
@Test
void
runWhenMandatoryWildcardLocationHasEmptyFileDirectory
()
{
assertThatNoException
()
.
isThrownBy
(()
->
this
.
application
.
run
(
"--spring.config.location=file:src/test/resources/config/*/"
));
}
@Test
void
runWhenMandatoryWildcardLocationHasNoSubdirectories
()
{
assertThatIllegalStateException
().
isThrownBy
(
()
->
this
.
application
.
run
(
"--spring.config.location=file:src/test/resources/config/0-empty/*/"
))
.
withMessage
(
"No subdirectories found for mandatory directory location 'file:src/test/resources/config/0-empty/*/'."
);
}
@Test
void
runWhenHasMandatoryWildcardLocationThatDoesNotExist
()
{
assertThatExceptionOfType
(
ConfigDataLocationNotFoundException
.
class
)
.
isThrownBy
(()
->
this
.
application
.
run
(
"--spring.config.location=file:invalid/*/"
));
}
@Test
// gh-24990
void
runWhenHasProfileSpecificFileWithActiveOnProfileProperty
()
{
ConfigurableApplicationContext
context
=
this
.
application
...
...
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