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
0893df4a
Commit
0893df4a
authored
May 03, 2021
by
Scott Frederick
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-26346
parents
199bc2dc
dbee0cf9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
8 deletions
+57
-8
ConfigDataLocationBindHandler.java
...rk/boot/context/config/ConfigDataLocationBindHandler.java
+10
-3
ConfigDataEnvironmentContributorTests.java
...context/config/ConfigDataEnvironmentContributorTests.java
+15
-4
ConfigDataLocationBindHandlerTests.java
...ot/context/config/ConfigDataLocationBindHandlerTests.java
+32
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java
View file @
0893df4a
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,7 +16,10 @@
...
@@ -16,7 +16,10 @@
package
org
.
springframework
.
boot
.
context
.
config
;
package
org
.
springframework
.
boot
.
context
.
config
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
org.springframework.boot.context.properties.bind.AbstractBindHandler
;
import
org.springframework.boot.context.properties.bind.AbstractBindHandler
;
import
org.springframework.boot.context.properties.bind.BindContext
;
import
org.springframework.boot.context.properties.bind.BindContext
;
...
@@ -30,6 +33,7 @@ import org.springframework.boot.origin.Origin;
...
@@ -30,6 +33,7 @@ import org.springframework.boot.origin.Origin;
* objects.
* objects.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Scott Frederick
*/
*/
class
ConfigDataLocationBindHandler
extends
AbstractBindHandler
{
class
ConfigDataLocationBindHandler
extends
AbstractBindHandler
{
...
@@ -40,19 +44,22 @@ class ConfigDataLocationBindHandler extends AbstractBindHandler {
...
@@ -40,19 +44,22 @@ class ConfigDataLocationBindHandler extends AbstractBindHandler {
return
withOrigin
(
context
,
(
ConfigDataLocation
)
result
);
return
withOrigin
(
context
,
(
ConfigDataLocation
)
result
);
}
}
if
(
result
instanceof
List
)
{
if
(
result
instanceof
List
)
{
List
<
Object
>
list
=
(
List
<
Object
>)
result
;
List
<
Object
>
list
=
(
(
List
<
Object
>)
result
).
stream
().
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
())
;
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Object
element
=
list
.
get
(
i
);
Object
element
=
list
.
get
(
i
);
if
(
element
instanceof
ConfigDataLocation
)
{
if
(
element
instanceof
ConfigDataLocation
)
{
list
.
set
(
i
,
withOrigin
(
context
,
(
ConfigDataLocation
)
element
));
list
.
set
(
i
,
withOrigin
(
context
,
(
ConfigDataLocation
)
element
));
}
}
}
}
return
list
;
}
}
if
(
result
instanceof
ConfigDataLocation
[])
{
if
(
result
instanceof
ConfigDataLocation
[])
{
ConfigDataLocation
[]
locations
=
(
ConfigDataLocation
[])
result
;
ConfigDataLocation
[]
locations
=
Arrays
.
stream
((
ConfigDataLocation
[])
result
).
filter
(
Objects:
:
nonNull
)
.
toArray
(
ConfigDataLocation
[]::
new
);
for
(
int
i
=
0
;
i
<
locations
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
locations
.
length
;
i
++)
{
locations
[
i
]
=
withOrigin
(
context
,
locations
[
i
]);
locations
[
i
]
=
withOrigin
(
context
,
locations
[
i
]);
}
}
return
locations
;
}
}
return
result
;
return
result
;
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorTests.java
View file @
0893df4a
...
@@ -43,13 +43,14 @@ import static org.mockito.Mockito.mock;
...
@@ -43,13 +43,14 @@ import static org.mockito.Mockito.mock;
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
* @author Scott Frederick
*/
*/
class
ConfigDataEnvironmentContributorTests
{
class
ConfigDataEnvironmentContributorTests
{
private
static
final
ConfigDataLocation
TEST_LOCATION
=
ConfigDataLocation
.
of
(
"test"
);
private
static
final
ConfigDataLocation
TEST_LOCATION
=
ConfigDataLocation
.
of
(
"test"
);
private
ConfigDataActivationContext
activationContext
=
new
ConfigDataActivationContext
(
CloudPlatform
.
KUBERNETES
,
private
final
ConfigDataActivationContext
activationContext
=
new
ConfigDataActivationContext
(
null
);
CloudPlatform
.
KUBERNETES
,
null
);
@Test
@Test
void
getKindReturnsKind
()
{
void
getKindReturnsKind
()
{
...
@@ -125,6 +126,16 @@ class ConfigDataEnvironmentContributorTests {
...
@@ -125,6 +126,16 @@ class ConfigDataEnvironmentContributorTests {
ConfigDataLocation
.
of
(
"boot"
));
ConfigDataLocation
.
of
(
"boot"
));
}
}
@Test
void
getImportsIgnoresEmptyElements
()
{
MockPropertySource
propertySource
=
new
MockPropertySource
();
propertySource
.
setProperty
(
"spring.config.import"
,
"spring,,boot,"
);
ConfigData
configData
=
new
ConfigData
(
Collections
.
singleton
(
propertySource
));
ConfigDataEnvironmentContributor
contributor
=
createBoundContributor
(
null
,
configData
,
0
);
assertThat
(
contributor
.
getImports
()).
containsExactly
(
ConfigDataLocation
.
of
(
"spring"
),
ConfigDataLocation
.
of
(
"boot"
));
}
@Test
@Test
void
hasUnprocessedImportsWhenNoImportsReturnsFalse
()
{
void
hasUnprocessedImportsWhenNoImportsReturnsFalse
()
{
ConfigData
configData
=
new
ConfigData
(
Collections
.
singleton
(
new
MockPropertySource
()));
ConfigData
configData
=
new
ConfigData
(
Collections
.
singleton
(
new
MockPropertySource
()));
...
@@ -205,9 +216,9 @@ class ConfigDataEnvironmentContributorTests {
...
@@ -205,9 +216,9 @@ class ConfigDataEnvironmentContributorTests {
"classpath:application-profile.properties"
);
"classpath:application-profile.properties"
);
ConfigDataEnvironmentContributor
classpathImports
=
createBoundContributor
(
"classpath:/"
);
ConfigDataEnvironmentContributor
classpathImports
=
createBoundContributor
(
"classpath:/"
);
classpathImports
=
classpathImports
.
withChildren
(
ImportPhase
.
BEFORE_PROFILE_ACTIVATION
,
classpathImports
=
classpathImports
.
withChildren
(
ImportPhase
.
BEFORE_PROFILE_ACTIVATION
,
Arrays
.
as
List
(
classpathApplication
));
Collections
.
singleton
List
(
classpathApplication
));
classpathImports
=
classpathImports
.
withChildren
(
ImportPhase
.
AFTER_PROFILE_ACTIVATION
,
classpathImports
=
classpathImports
.
withChildren
(
ImportPhase
.
AFTER_PROFILE_ACTIVATION
,
Arrays
.
as
List
(
classpathProfile
));
Collections
.
singleton
List
(
classpathProfile
));
ConfigDataEnvironmentContributor
root
=
createBoundContributor
(
"root"
);
ConfigDataEnvironmentContributor
root
=
createBoundContributor
(
"root"
);
root
=
root
.
withChildren
(
ImportPhase
.
BEFORE_PROFILE_ACTIVATION
,
Arrays
.
asList
(
fileImports
,
classpathImports
));
root
=
root
.
withChildren
(
ImportPhase
.
BEFORE_PROFILE_ACTIVATION
,
Arrays
.
asList
(
fileImports
,
classpathImports
));
assertThat
(
asLocationsList
(
root
.
iterator
())).
containsExactly
(
"file:application-profile.properties"
,
assertThat
(
asLocationsList
(
root
.
iterator
())).
containsExactly
(
"file:application-profile.properties"
,
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationBindHandlerTests.java
View file @
0893df4a
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ConfigDataLocationBindHandler}.
* Tests for {@link ConfigDataLocationBindHandler}.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Scott Frederick
*/
*/
class
ConfigDataLocationBindHandlerTests
{
class
ConfigDataLocationBindHandlerTests
{
...
@@ -54,6 +55,21 @@ class ConfigDataLocationBindHandlerTests {
...
@@ -54,6 +55,21 @@ class ConfigDataLocationBindHandlerTests {
assertThat
(
bound
[
2
].
getOrigin
()).
hasToString
(
expectedLocation
);
assertThat
(
bound
[
2
].
getOrigin
()).
hasToString
(
expectedLocation
);
}
}
@Test
void
bindToArrayFromCommaStringPropertyIgnoresEmptyElements
()
{
MapConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
();
source
.
put
(
"locations"
,
",a,,b,c,"
);
Binder
binder
=
new
Binder
(
source
);
ConfigDataLocation
[]
bound
=
binder
.
bind
(
"locations"
,
ARRAY
,
this
.
handler
).
get
();
String
expectedLocation
=
"\"locations\" from property source \"source\""
;
assertThat
(
bound
[
0
]).
hasToString
(
"a"
);
assertThat
(
bound
[
0
].
getOrigin
()).
hasToString
(
expectedLocation
);
assertThat
(
bound
[
1
]).
hasToString
(
"b"
);
assertThat
(
bound
[
1
].
getOrigin
()).
hasToString
(
expectedLocation
);
assertThat
(
bound
[
2
]).
hasToString
(
"c"
);
assertThat
(
bound
[
2
].
getOrigin
()).
hasToString
(
expectedLocation
);
}
@Test
@Test
void
bindToArrayFromIndexedPropertiesSetsOrigin
()
{
void
bindToArrayFromIndexedPropertiesSetsOrigin
()
{
MapConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
();
MapConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
();
...
@@ -85,6 +101,21 @@ class ConfigDataLocationBindHandlerTests {
...
@@ -85,6 +101,21 @@ class ConfigDataLocationBindHandlerTests {
assertThat
(
bound
.
getLocation
(
2
).
getOrigin
()).
hasToString
(
expectedLocation
);
assertThat
(
bound
.
getLocation
(
2
).
getOrigin
()).
hasToString
(
expectedLocation
);
}
}
@Test
void
bindToValueObjectFromCommaStringPropertyIgnoresEmptyElements
()
{
MapConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
();
source
.
put
(
"test.locations"
,
",a,b,,c,"
);
Binder
binder
=
new
Binder
(
source
);
ValueObject
bound
=
binder
.
bind
(
"test"
,
VALUE_OBJECT
,
this
.
handler
).
get
();
String
expectedLocation
=
"\"test.locations\" from property source \"source\""
;
assertThat
(
bound
.
getLocation
(
0
)).
hasToString
(
"a"
);
assertThat
(
bound
.
getLocation
(
0
).
getOrigin
()).
hasToString
(
expectedLocation
);
assertThat
(
bound
.
getLocation
(
1
)).
hasToString
(
"b"
);
assertThat
(
bound
.
getLocation
(
1
).
getOrigin
()).
hasToString
(
expectedLocation
);
assertThat
(
bound
.
getLocation
(
2
)).
hasToString
(
"c"
);
assertThat
(
bound
.
getLocation
(
2
).
getOrigin
()).
hasToString
(
expectedLocation
);
}
@Test
@Test
void
bindToValueObjectFromIndexedPropertiesSetsOrigin
()
{
void
bindToValueObjectFromIndexedPropertiesSetsOrigin
()
{
MapConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
();
MapConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
();
...
...
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