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
5603d619
Commit
5603d619
authored
Oct 26, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Consider aliases when checking descendants"
See gh-14967
parent
256ca681
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
35 deletions
+26
-35
AliasedConfigurationPropertySource.java
...properties/source/AliasedConfigurationPropertySource.java
+13
-12
ConfigurationPropertyNameAliases.java
...t/properties/source/ConfigurationPropertyNameAliases.java
+6
-4
AliasedConfigurationPropertySourceTests.java
...rties/source/AliasedConfigurationPropertySourceTests.java
+7
-19
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/AliasedConfigurationPropertySource.java
View file @
5603d619
...
...
@@ -16,8 +16,6 @@
package
org
.
springframework
.
boot
.
context
.
properties
.
source
;
import
java.util.Set
;
import
org.springframework.util.Assert
;
/**
...
...
@@ -60,16 +58,19 @@ class AliasedConfigurationPropertySource implements ConfigurationPropertySource
if
(
result
!=
ConfigurationPropertyState
.
ABSENT
)
{
return
result
;
}
Set
<
ConfigurationPropertyName
>
aliasNames
=
this
.
aliases
.
getAllNames
();
for
(
ConfigurationPropertyName
configurationPropertyName
:
aliasNames
)
{
boolean
descendantPresentInAlias
=
this
.
aliases
.
getAliases
(
configurationPropertyName
).
stream
()
.
filter
(
name:
:
isAncestorOf
).
findFirst
().
isPresent
();
if
(
descendantPresentInAlias
)
{
ConfigurationProperty
configurationProperty
=
this
.
getSource
()
.
getConfigurationProperty
(
configurationPropertyName
);
if
(
configurationProperty
!=
null
)
{
return
ConfigurationPropertyState
.
PRESENT
;
for
(
ConfigurationPropertyName
alias
:
getAliases
().
getAliases
(
name
))
{
ConfigurationPropertyState
aliasResult
=
this
.
source
.
containsDescendantOf
(
alias
);
if
(
aliasResult
!=
ConfigurationPropertyState
.
ABSENT
)
{
return
aliasResult
;
}
}
for
(
ConfigurationPropertyName
from
:
getAliases
())
{
for
(
ConfigurationPropertyName
alias
:
getAliases
().
getAliases
(
from
))
{
if
(
name
.
isAncestorOf
(
alias
))
{
if
(
this
.
source
.
getConfigurationProperty
(
from
)
!=
null
)
{
return
ConfigurationPropertyState
.
PRESENT
;
}
}
}
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameAliases.java
View file @
5603d619
...
...
@@ -18,9 +18,9 @@ package org.springframework.boot.context.properties.source;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.util.Assert
;
import
org.springframework.util.LinkedMultiValueMap
;
...
...
@@ -34,7 +34,8 @@ import org.springframework.util.MultiValueMap;
* @since 2.0.0
* @see ConfigurationPropertySource#withAliases(ConfigurationPropertyNameAliases)
*/
public
final
class
ConfigurationPropertyNameAliases
{
public
final
class
ConfigurationPropertyNameAliases
implements
Iterable
<
ConfigurationPropertyName
>
{
private
final
MultiValueMap
<
ConfigurationPropertyName
,
ConfigurationPropertyName
>
aliases
=
new
LinkedMultiValueMap
<>();
...
...
@@ -75,8 +76,9 @@ public final class ConfigurationPropertyNameAliases {
.
findFirst
().
orElse
(
null
);
}
public
Set
<
ConfigurationPropertyName
>
getAllNames
()
{
return
this
.
aliases
.
keySet
();
@Override
public
Iterator
<
ConfigurationPropertyName
>
iterator
()
{
return
this
.
aliases
.
keySet
().
iterator
();
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/AliasedConfigurationPropertySourceTests.java
View file @
5603d619
...
...
@@ -16,11 +16,11 @@
package
org
.
springframework
.
boot
.
context
.
properties
.
source
;
import
java.util.Collections
;
import
org.junit.Test
;
import
org.mockito.Answers
;
import
org.springframework.boot.origin.Origin
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -107,31 +107,19 @@ public class AliasedConfigurationPropertySourceTests {
.
willReturn
(
ConfigurationPropertyState
.
ABSENT
);
given
(
source
.
containsDescendantOf
(
ConfigurationPropertyName
.
of
(
"bar"
)))
.
willReturn
(
ConfigurationPropertyState
.
PRESENT
);
ConfigurationPropertyName
barBar
=
ConfigurationPropertyName
.
of
(
"bar.bar"
);
given
(
source
.
getConfigurationProperty
(
barBar
)).
willReturn
(
new
ConfigurationProperty
(
barBar
,
"barBarValue"
,
mock
(
Origin
.
class
)));
ConfigurationPropertySource
aliased
=
source
.
withAliases
(
new
ConfigurationPropertyNameAliases
(
"
bar.bar"
,
"foo.foo
"
));
.
withAliases
(
new
ConfigurationPropertyNameAliases
(
"
foo"
,
"bar
"
));
assertThat
(
aliased
.
containsDescendantOf
(
name
))
.
isEqualTo
(
ConfigurationPropertyState
.
PRESENT
);
}
@Test
public
void
containsDescendantOfWhenPresentInAliasShouldReturnPresent
()
{
ConfigurationPropertyName
name
=
ConfigurationPropertyName
.
of
(
"baz"
);
ConfigurationPropertySource
source
=
mock
(
ConfigurationPropertySource
.
class
,
withSettings
().
defaultAnswer
(
Answers
.
CALLS_REAL_METHODS
));
given
(
source
.
containsDescendantOf
(
name
))
.
willReturn
(
ConfigurationPropertyState
.
ABSENT
);
ConfigurationPropertyName
barFoo
=
ConfigurationPropertyName
.
of
(
"bar.foo"
);
given
(
source
.
getConfigurationProperty
(
barFoo
)).
willReturn
(
new
ConfigurationProperty
(
barFoo
,
"barFooValue"
,
mock
(
Origin
.
class
)));
ConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
(
Collections
.
singletonMap
(
"foo.bar"
,
"foobar"
));
ConfigurationPropertySource
aliased
=
source
.
withAliases
(
new
ConfigurationPropertyNameAliases
(
"
bar.foo
"
,
"baz.foo"
));
assertThat
(
aliased
.
containsDescendantOf
(
name
))
.
withAliases
(
new
ConfigurationPropertyNameAliases
(
"
foo.bar
"
,
"baz.foo"
));
assertThat
(
aliased
.
containsDescendantOf
(
ConfigurationPropertyName
.
of
(
"baz"
)
))
.
isEqualTo
(
ConfigurationPropertyState
.
PRESENT
);
}
...
...
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