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
a12baed5
Commit
a12baed5
authored
Jun 04, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
c1ab3eab
67b548da
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
21 deletions
+53
-21
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+25
-20
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+11
-0
ConfigFileApplicationListenerYamlProfileNegationTests.java
...onfigFileApplicationListenerYamlProfileNegationTests.java
+1
-1
applicationloop-loop.properties
...g-boot/src/test/resources/applicationloop-loop.properties
+1
-0
applicationloop.properties
...spring-boot/src/test/resources/applicationloop.properties
+1
-0
cascadingprofiles.yml
...ject/spring-boot/src/test/resources/cascadingprofiles.yml
+14
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
a12baed5
...
@@ -328,6 +328,9 @@ public class ConfigFileApplicationListener
...
@@ -328,6 +328,9 @@ public class ConfigFileApplicationListener
initializeProfiles
();
initializeProfiles
();
while
(!
this
.
profiles
.
isEmpty
())
{
while
(!
this
.
profiles
.
isEmpty
())
{
Profile
profile
=
this
.
profiles
.
poll
();
Profile
profile
=
this
.
profiles
.
poll
();
if
(
profile
!=
null
&&
!
profile
.
isDefaultProfile
())
{
addProfileToEnvironment
(
profile
.
getName
());
}
load
(
profile
,
this
::
getPositiveProfileFilter
,
load
(
profile
,
this
::
getPositiveProfileFilter
,
addToLoaded
(
MutablePropertySources:
:
addLast
,
false
));
addToLoaded
(
MutablePropertySources:
:
addLast
,
false
));
this
.
processedProfiles
.
add
(
profile
);
this
.
processedProfiles
.
add
(
profile
);
...
@@ -347,15 +350,13 @@ public class ConfigFileApplicationListener
...
@@ -347,15 +350,13 @@ public class ConfigFileApplicationListener
// first so that it is processed first and has lowest priority.
// first so that it is processed first and has lowest priority.
this
.
profiles
.
add
(
null
);
this
.
profiles
.
add
(
null
);
Set
<
Profile
>
activatedViaProperty
=
getProfilesActivatedViaProperty
();
Set
<
Profile
>
activatedViaProperty
=
getProfilesActivatedViaProperty
();
processOtherActiveProfiles
(
activatedViaProperty
);
this
.
profiles
.
addAll
(
getOtherActiveProfiles
(
activatedViaProperty
)
);
// Any pre-existing active profiles set via property sources (e.g.
// Any pre-existing active profiles set via property sources (e.g.
// System
// System properties) take precedence over those added in config files.
// properties) take precedence over those added in config files.
addActiveProfiles
(
activatedViaProperty
);
addActiveProfiles
(
activatedViaProperty
);
if
(
this
.
profiles
.
size
()
==
1
)
{
// only has null profile
if
(
this
.
profiles
.
size
()
==
1
)
{
// only has null profile
for
(
String
defaultProfileName
:
this
.
environment
.
getDefaultProfiles
())
{
for
(
String
defaultProfileName
:
this
.
environment
.
getDefaultProfiles
())
{
ConfigFileApplicationListener
.
Profile
defaultProfile
=
new
ConfigFileApplicationListener
.
Profile
(
Profile
defaultProfile
=
new
Profile
(
defaultProfileName
,
true
);
defaultProfileName
,
true
);
this
.
profiles
.
add
(
defaultProfile
);
this
.
profiles
.
add
(
defaultProfile
);
}
}
}
}
...
@@ -373,19 +374,22 @@ public class ConfigFileApplicationListener
...
@@ -373,19 +374,22 @@ public class ConfigFileApplicationListener
return
activeProfiles
;
return
activeProfiles
;
}
}
private
void
processOtherActiveProfiles
(
Set
<
Profile
>
activatedViaProperty
)
{
private
List
<
Profile
>
getOtherActiveProfiles
(
Set
<
Profile
>
activatedViaProperty
)
{
List
<
Profile
>
otherActiveProfiles
=
Arrays
return
Arrays
.
stream
(
this
.
environment
.
getActiveProfiles
()).
map
(
Profile:
:
new
)
.
stream
(
this
.
environment
.
getActiveProfiles
()).
map
(
Profile:
:
new
)
.
filter
((
profile
)
->
!
activatedViaProperty
.
contains
(
profile
))
.
filter
((
o
)
->
!
activatedViaProperty
.
contains
(
o
))
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
this
.
profiles
.
addAll
(
otherActiveProfiles
);
}
}
void
addActiveProfiles
(
Set
<
Profile
>
profiles
)
{
void
addActiveProfiles
(
Set
<
Profile
>
profiles
)
{
if
(
this
.
activatedProfiles
||
profiles
.
isEmpty
())
{
if
(
profiles
.
isEmpty
())
{
return
;
}
if
(
this
.
activatedProfiles
)
{
this
.
logger
.
debug
(
"Profiles already activated, '"
+
profiles
+
"' will not be applied"
);
return
;
return
;
}
}
addProfiles
(
profiles
);
this
.
profiles
.
addAll
(
profiles
);
if
(
this
.
logger
.
isDebugEnabled
())
{
if
(
this
.
logger
.
isDebugEnabled
())
{
this
.
logger
.
debug
(
"Activated activeProfiles "
this
.
logger
.
debug
(
"Activated activeProfiles "
+
StringUtils
.
collectionToCommaDelimitedString
(
profiles
));
+
StringUtils
.
collectionToCommaDelimitedString
(
profiles
));
...
@@ -394,13 +398,6 @@ public class ConfigFileApplicationListener
...
@@ -394,13 +398,6 @@ public class ConfigFileApplicationListener
removeUnprocessedDefaultProfiles
();
removeUnprocessedDefaultProfiles
();
}
}
void
addProfiles
(
Set
<
Profile
>
profiles
)
{
for
(
Profile
profile
:
profiles
)
{
this
.
profiles
.
add
(
profile
);
addProfileToEnvironment
(
profile
.
getName
());
}
}
private
void
removeUnprocessedDefaultProfiles
()
{
private
void
removeUnprocessedDefaultProfiles
()
{
this
.
profiles
.
removeIf
(
this
.
profiles
.
removeIf
(
(
profile
)
->
(
profile
!=
null
&&
profile
.
isDefaultProfile
()));
(
profile
)
->
(
profile
!=
null
&&
profile
.
isDefaultProfile
()));
...
@@ -526,7 +523,7 @@ public class ConfigFileApplicationListener
...
@@ -526,7 +523,7 @@ public class ConfigFileApplicationListener
for
(
Document
document
:
documents
)
{
for
(
Document
document
:
documents
)
{
if
(
filter
.
match
(
document
))
{
if
(
filter
.
match
(
document
))
{
addActiveProfiles
(
document
.
getActiveProfiles
());
addActiveProfiles
(
document
.
getActiveProfiles
());
addProfiles
(
document
.
getIncludeProfiles
());
add
Included
Profiles
(
document
.
getIncludeProfiles
());
loaded
.
add
(
document
);
loaded
.
add
(
document
);
}
}
}
}
...
@@ -542,6 +539,14 @@ public class ConfigFileApplicationListener
...
@@ -542,6 +539,14 @@ public class ConfigFileApplicationListener
}
}
}
}
private
void
addIncludedProfiles
(
Set
<
Profile
>
includeProfiles
)
{
LinkedList
<
Profile
>
existingProfiles
=
new
LinkedList
<>(
this
.
profiles
);
this
.
profiles
.
clear
();
this
.
profiles
.
addAll
(
includeProfiles
);
this
.
profiles
.
removeAll
(
this
.
processedProfiles
);
this
.
profiles
.
addAll
(
existingProfiles
);
}
private
List
<
Document
>
loadDocuments
(
PropertySourceLoader
loader
,
String
name
,
private
List
<
Document
>
loadDocuments
(
PropertySourceLoader
loader
,
String
name
,
Resource
resource
)
throws
IOException
{
Resource
resource
)
throws
IOException
{
DocumentsCacheKey
cacheKey
=
new
DocumentsCacheKey
(
loader
,
resource
);
DocumentsCacheKey
cacheKey
=
new
DocumentsCacheKey
(
loader
,
resource
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
a12baed5
...
@@ -892,6 +892,17 @@ public class ConfigFileApplicationListenerTests {
...
@@ -892,6 +892,17 @@ public class ConfigFileApplicationListenerTests {
assertThat
(
this
.
environment
.
getProperty
(
"value"
)).
isNull
();
assertThat
(
this
.
environment
.
getProperty
(
"value"
)).
isNull
();
}
}
@Test
public
void
includeLoop
()
{
// gh-13361
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.config.name=applicationloop"
);
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
assertThat
(
environment
.
acceptsProfiles
(
"loop"
)).
isTrue
();
}
private
Condition
<
ConfigurableEnvironment
>
matchingPropertySource
(
private
Condition
<
ConfigurableEnvironment
>
matchingPropertySource
(
final
String
sourceName
)
{
final
String
sourceName
)
{
return
new
Condition
<
ConfigurableEnvironment
>(
return
new
Condition
<
ConfigurableEnvironment
>(
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerYamlProfileNegationTests.java
View file @
a12baed5
...
@@ -94,7 +94,7 @@ public class ConfigFileApplicationListenerYamlProfileNegationTests {
...
@@ -94,7 +94,7 @@ public class ConfigFileApplicationListenerYamlProfileNegationTests {
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=cascadingprofiles"
;
String
configName
=
"--spring.config.name=cascadingprofiles"
;
this
.
context
=
application
.
run
(
configName
);
this
.
context
=
application
.
run
(
configName
);
assertVersionProperty
(
this
.
context
,
"
E"
,
"A"
,
"B"
,
"C"
,
"E
"
,
"D"
);
assertVersionProperty
(
this
.
context
,
"
D"
,
"A"
,
"C"
,
"E"
,
"B
"
,
"D"
);
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-a"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-a"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-b"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-b"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-c"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-c"
)).
isNull
();
...
...
spring-boot-project/spring-boot/src/test/resources/applicationloop-loop.properties
0 → 100644
View file @
a12baed5
spring.profiles.include
=
loop
spring-boot-project/spring-boot/src/test/resources/applicationloop.properties
0 → 100644
View file @
a12baed5
spring.profiles.include
=
loop
spring-boot-project/spring-boot/src/test/resources/cascadingprofiles.yml
View file @
a12baed5
...
@@ -12,6 +12,7 @@ spring:
...
@@ -12,6 +12,7 @@ spring:
include
:
include
:
-
C
-
C
-
E
-
E
version
:
A
---
---
spring.profiles
:
B
spring.profiles
:
B
...
@@ -21,6 +22,19 @@ spring:
...
@@ -21,6 +22,19 @@ spring:
include
:
include
:
-
D
-
D
-
E
-
E
version
:
B
---
spring.profiles
:
C
version
:
C
---
spring.profiles
:
D
version
:
D
---
---
spring.profiles
:
E
spring.profiles
:
E
...
...
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