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
b9fcb6a5
Commit
b9fcb6a5
authored
Aug 02, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
c41199ba
16aff4cd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
381 deletions
+33
-381
CompositePropertySources.java
...ork/boot/context/properties/CompositePropertySources.java
+0
-59
FilteredPropertySources.java
...work/boot/context/properties/FilteredPropertySources.java
+0
-72
PropertySourcesDeducer.java
...ework/boot/context/properties/PropertySourcesDeducer.java
+8
-21
CompositePropertySourcesTests.java
...oot/context/properties/CompositePropertySourcesTests.java
+0
-144
ConfigurationPropertiesTests.java
...boot/context/properties/ConfigurationPropertiesTests.java
+25
-0
FilteredPropertySourcesTests.java
...boot/context/properties/FilteredPropertySourcesTests.java
+0
-85
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/CompositePropertySources.java
deleted
100644 → 0
View file @
c41199ba
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
context
.
properties
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Objects
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.PropertySources
;
/**
* A composite {@link PropertySources} backed by one or more {@code PropertySources}.
* Changes to the backing {@code PropertySources} are automatically reflected in the
* composite.
*
* @author Andy Wilkinson
*/
final
class
CompositePropertySources
implements
PropertySources
{
private
final
List
<
PropertySources
>
propertySources
;
CompositePropertySources
(
PropertySources
...
propertySources
)
{
this
.
propertySources
=
Arrays
.
asList
(
propertySources
);
}
@Override
public
Iterator
<
PropertySource
<?>>
iterator
()
{
return
this
.
propertySources
.
stream
().
flatMap
(
PropertySources:
:
stream
).
iterator
();
}
@Override
public
boolean
contains
(
String
name
)
{
return
this
.
propertySources
.
stream
()
.
anyMatch
((
sources
)
->
sources
.
contains
(
name
));
}
@Override
public
PropertySource
<?>
get
(
String
name
)
{
return
this
.
propertySources
.
stream
().
map
((
sources
)
->
sources
.
get
(
name
))
.
filter
(
Objects:
:
nonNull
).
findFirst
().
orElse
(
null
);
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java
deleted
100644 → 0
View file @
c41199ba
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
context
.
properties
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Set
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.PropertySources
;
/**
* A {@link PropertySources} decorator that filters property sources by name.
*
* @author Andy Wilkinson
*/
final
class
FilteredPropertySources
implements
PropertySources
{
private
final
PropertySources
delegate
;
private
final
Set
<
String
>
filtered
;
FilteredPropertySources
(
PropertySources
delegate
,
String
...
filtered
)
{
this
.
delegate
=
delegate
;
this
.
filtered
=
new
HashSet
<>(
Arrays
.
asList
(
filtered
));
}
@Override
public
boolean
contains
(
String
name
)
{
if
(
included
(
name
))
{
return
this
.
delegate
.
contains
(
name
);
}
return
false
;
}
@Override
public
PropertySource
<?>
get
(
String
name
)
{
if
(
included
(
name
))
{
return
this
.
delegate
.
get
(
name
);
}
return
null
;
}
@Override
public
Iterator
<
PropertySource
<?>>
iterator
()
{
return
this
.
delegate
.
stream
().
filter
(
this
::
included
).
iterator
();
}
private
boolean
included
(
PropertySource
<?>
propertySource
)
{
return
included
(
propertySource
.
getName
());
}
private
boolean
included
(
String
name
)
{
return
(!
this
.
filtered
.
contains
(
name
));
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertySourcesDeducer.java
View file @
b9fcb6a5
...
@@ -27,7 +27,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
...
@@ -27,7 +27,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.PropertySources
;
import
org.springframework.core.env.PropertySources
;
import
org.springframework.util.Assert
;
/**
/**
* Utility to deduce the {@link PropertySources} to use for configuration binding.
* Utility to deduce the {@link PropertySources} to use for configuration binding.
...
@@ -45,20 +44,16 @@ class PropertySourcesDeducer {
...
@@ -45,20 +44,16 @@ class PropertySourcesDeducer {
}
}
public
PropertySources
getPropertySources
()
{
public
PropertySources
getPropertySources
()
{
MutablePropertySources
environmentPropertySources
=
extractEnvironmentPropertySources
();
PropertySourcesPlaceholderConfigurer
configurer
=
getSinglePropertySourcesPlaceholderConfigurer
();
PropertySourcesPlaceholderConfigurer
placeholderConfigurer
=
getSinglePropertySourcesPlaceholderConfigurer
();
if
(
configurer
!=
null
)
{
if
(
placeholderConfigurer
==
null
)
{
return
configurer
.
getAppliedPropertySources
();
Assert
.
state
(
environmentPropertySources
!=
null
,
"Unable to obtain PropertySources from "
+
"PropertySourcesPlaceholderConfigurer or Environment"
);
return
environmentPropertySources
;
}
}
PropertySources
appliedPropertySources
=
placeholderConfigurer
MutablePropertySources
sources
=
extractEnvironmentPropertySources
();
.
getAppliedPropertySources
();
if
(
sources
!=
null
)
{
if
(
environmentPropertySources
==
null
)
{
return
sources
;
return
appliedPropertySources
;
}
}
return
merge
(
environmentPropertySources
,
appliedPropertySources
);
throw
new
IllegalStateException
(
"Unable to obtain PropertySources from "
+
"PropertySourcesPlaceholderConfigurer or Environment"
);
}
}
private
MutablePropertySources
extractEnvironmentPropertySources
()
{
private
MutablePropertySources
extractEnvironmentPropertySources
()
{
...
@@ -84,12 +79,4 @@ class PropertySourcesDeducer {
...
@@ -84,12 +79,4 @@ class PropertySourcesDeducer {
return
null
;
return
null
;
}
}
private
PropertySources
merge
(
PropertySources
environmentPropertySources
,
PropertySources
appliedPropertySources
)
{
FilteredPropertySources
filtered
=
new
FilteredPropertySources
(
appliedPropertySources
,
PropertySourcesPlaceholderConfigurer
.
ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME
);
return
new
CompositePropertySources
(
filtered
,
environmentPropertySources
);
}
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/CompositePropertySourcesTests.java
deleted
100644 → 0
View file @
c41199ba
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
context
.
properties
;
import
java.util.Collections
;
import
org.junit.Test
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link CompositePropertySources}.
*
* @author Andy Wilkinson
*/
public
class
CompositePropertySourcesTests
{
@Test
public
void
containsReturnsFalseWithNoBackingSources
()
{
assertThat
(
new
CompositePropertySources
().
contains
(
"foo"
)).
isFalse
();
}
@Test
public
void
getReturnsNullWithNoBackingSources
()
{
assertThat
(
new
CompositePropertySources
().
get
(
"foo"
)).
isNull
();
}
@Test
public
void
iteratorIsEmptyWithNoBackingSources
()
{
assertThat
(
new
CompositePropertySources
().
iterator
()).
hasSize
(
0
);
}
@Test
public
void
containsReturnsTrueForPropertySourceFoundInBackingSources
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
sources
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
assertThat
(
new
CompositePropertySources
(
sources
).
contains
(
"foo"
)).
isTrue
();
}
@Test
public
void
containsReturnsFalseForPropertySourceNotFoundInBackingSources
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
sources
.
addFirst
(
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
()));
assertThat
(
new
CompositePropertySources
(
sources
).
contains
(
"foo"
)).
isFalse
();
}
@Test
public
void
getReturnsPropertySourceFoundInBackingSources
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
MapPropertySource
fooSource
=
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
());
sources
.
addFirst
(
fooSource
);
assertThat
(
new
CompositePropertySources
(
sources
).
get
(
"foo"
)).
isEqualTo
(
fooSource
);
}
@Test
public
void
getReturnsNullWhenPropertySourceNotFoundInBackingSources
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
sources
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
assertThat
(
new
CompositePropertySources
(
sources
).
get
(
"bar"
)).
isNull
();
}
@Test
public
void
iteratorContainsSingleEntryWithSingleBackingSource
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
MapPropertySource
fooSource
=
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
());
sources
.
addFirst
(
fooSource
);
assertThat
(
new
CompositePropertySources
(
sources
).
iterator
())
.
containsExactly
(
fooSource
);
}
@Test
public
void
iteratorReflectsOrderingOfSourcesAcrossMultipleBackingSources
()
{
MutablePropertySources
sourcesOne
=
new
MutablePropertySources
();
MapPropertySource
fooSource
=
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
());
sourcesOne
.
addFirst
(
fooSource
);
MapPropertySource
barSource
=
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
());
sourcesOne
.
addFirst
(
barSource
);
MutablePropertySources
sourcesTwo
=
new
MutablePropertySources
();
MapPropertySource
bazSource
=
new
MapPropertySource
(
"baz"
,
Collections
.
emptyMap
());
sourcesTwo
.
addFirst
(
bazSource
);
assertThat
(
new
CompositePropertySources
(
sourcesOne
,
sourcesTwo
).
iterator
())
.
containsExactly
(
barSource
,
fooSource
,
bazSource
);
}
@Test
public
void
containsReflectsChangesInTheBackingSources
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
sources
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
assertThat
(
new
CompositePropertySources
(
sources
).
contains
(
"bar"
)).
isFalse
();
MapPropertySource
barSource
=
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
());
sources
.
addFirst
(
barSource
);
assertThat
(
new
CompositePropertySources
(
sources
).
contains
(
"bar"
)).
isTrue
();
}
@Test
public
void
getReflectsChangesInTheBackingSources
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
sources
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
assertThat
(
new
CompositePropertySources
(
sources
).
get
(
"bar"
)).
isNull
();
MapPropertySource
barSource
=
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
());
sources
.
addFirst
(
barSource
);
assertThat
(
new
CompositePropertySources
(
sources
).
get
(
"bar"
)).
isEqualTo
(
barSource
);
}
@Test
public
void
iteratorReflectsChangesInTheBackingSources
()
{
MutablePropertySources
sources
=
new
MutablePropertySources
();
MapPropertySource
fooSource
=
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
());
sources
.
addFirst
(
fooSource
);
assertThat
(
new
CompositePropertySources
(
sources
).
iterator
())
.
containsExactly
(
fooSource
);
MapPropertySource
barSource
=
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
());
sources
.
addFirst
(
barSource
);
assertThat
(
new
CompositePropertySources
(
sources
).
iterator
())
.
containsExactly
(
barSource
,
fooSource
);
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java
View file @
b9fcb6a5
...
@@ -25,6 +25,7 @@ import java.util.HashMap;
...
@@ -25,6 +25,7 @@ import java.util.HashMap;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
...
@@ -352,6 +353,15 @@ public class ConfigurationPropertiesTests {
...
@@ -352,6 +353,15 @@ public class ConfigurationPropertiesTests {
assertThat
(
bean
.
getValue
()).
isEqualTo
(
"foo"
);
assertThat
(
bean
.
getValue
()).
isEqualTo
(
"foo"
);
}
}
@Test
public
void
loadWithPropertyPlaceholderShouldNotAlterPropertySourceOrder
()
{
load
(
WithPropertyPlaceholderWithLocalPropertiesValueConfiguration
.
class
,
"com.example.bar=a"
);
SimplePrefixedProperties
bean
=
this
.
context
.
getBean
(
SimplePrefixedProperties
.
class
);
assertThat
(
bean
.
getBar
()).
isEqualTo
(
"a"
);
}
@Test
@Test
public
void
loadWhenHasPostConstructShouldTriggerPostConstructWithBoundBean
()
{
public
void
loadWhenHasPostConstructShouldTriggerPostConstructWithBoundBean
()
{
MockEnvironment
environment
=
new
MockEnvironment
();
MockEnvironment
environment
=
new
MockEnvironment
();
...
@@ -959,6 +969,21 @@ public class ConfigurationPropertiesTests {
...
@@ -959,6 +969,21 @@ public class ConfigurationPropertiesTests {
}
}
@Configuration
@EnableConfigurationProperties
(
SimplePrefixedProperties
.
class
)
static
class
WithPropertyPlaceholderWithLocalPropertiesValueConfiguration
{
@Bean
public
static
PropertySourcesPlaceholderConfigurer
configurer
()
{
PropertySourcesPlaceholderConfigurer
placeholderConfigurer
=
new
PropertySourcesPlaceholderConfigurer
();
Properties
properties
=
new
Properties
();
properties
.
put
(
"com.example.bar"
,
"b"
);
placeholderConfigurer
.
setProperties
(
properties
);
return
placeholderConfigurer
;
}
}
@Configuration
@Configuration
@EnableConfigurationProperties
@EnableConfigurationProperties
static
class
WithFactoryBeanConfiguration
{
static
class
WithFactoryBeanConfiguration
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/FilteredPropertySourcesTests.java
deleted
100644 → 0
View file @
c41199ba
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
context
.
properties
;
import
java.util.Collections
;
import
org.junit.Test
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link FilteredPropertySources}.
*
* @author Andy Wilkinson
*/
public
class
FilteredPropertySourcesTests
{
@Test
public
void
getReturnsNullForFilteredSource
()
{
MutablePropertySources
delegate
=
new
MutablePropertySources
();
delegate
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
assertThat
(
new
FilteredPropertySources
(
delegate
,
"foo"
).
get
(
"foo"
)).
isNull
();
}
@Test
public
void
getReturnsSourceThatIsNotFiltered
()
{
MutablePropertySources
delegate
=
new
MutablePropertySources
();
delegate
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
MapPropertySource
barSource
=
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
());
delegate
.
addFirst
(
barSource
);
assertThat
(
new
FilteredPropertySources
(
delegate
,
"foo"
).
get
(
"bar"
))
.
isEqualTo
(
barSource
);
}
@Test
public
void
containsReturnsFalseForFilteredSource
()
{
MutablePropertySources
delegate
=
new
MutablePropertySources
();
delegate
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
assertThat
(
new
FilteredPropertySources
(
delegate
,
"foo"
).
contains
(
"foo"
))
.
isFalse
();
}
@Test
public
void
containsReturnsTrueForSourceThatIsNotFiltered
()
{
MutablePropertySources
delegate
=
new
MutablePropertySources
();
delegate
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
MapPropertySource
barSource
=
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
());
delegate
.
addFirst
(
barSource
);
assertThat
(
new
FilteredPropertySources
(
delegate
,
"foo"
).
contains
(
"bar"
)).
isTrue
();
}
@Test
public
void
iteratorOmitsSourceThatIsFiltered
()
{
MutablePropertySources
delegate
=
new
MutablePropertySources
();
MapPropertySource
barSource
=
new
MapPropertySource
(
"bar"
,
Collections
.
emptyMap
());
delegate
.
addFirst
(
barSource
);
delegate
.
addFirst
(
new
MapPropertySource
(
"foo"
,
Collections
.
emptyMap
()));
MapPropertySource
bazSource
=
new
MapPropertySource
(
"baz"
,
Collections
.
emptyMap
());
delegate
.
addFirst
(
bazSource
);
assertThat
(
new
FilteredPropertySources
(
delegate
,
"foo"
).
iterator
())
.
containsExactly
(
bazSource
,
barSource
);
}
}
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