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
80ad6385
Commit
80ad6385
authored
Apr 22, 2021
by
ChangYong
Committed by
Andy Wilkinson
May 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect use of spring.profiles.include as a YAML list
See gh-26205
parent
1d5abf5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
ConfigDataEnvironment.java
...gframework/boot/context/config/ConfigDataEnvironment.java
+2
-0
ConfigDataEnvironmentTests.java
...ework/boot/context/config/ConfigDataEnvironmentTests.java
+50
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironment.java
View file @
80ad6385
...
...
@@ -297,6 +297,8 @@ class ConfigDataEnvironment {
binder
.
bind
(
Profiles
.
INCLUDE_PROFILES
,
STRING_LIST
).
ifBound
((
includes
)
->
{
if
(!
contributor
.
isActive
(
activationContext
))
{
InactiveConfigDataAccessException
.
throwIfPropertyFound
(
contributor
,
Profiles
.
INCLUDE_PROFILES
);
InactiveConfigDataAccessException
.
throwIfPropertyFound
(
contributor
,
Profiles
.
INCLUDE_PROFILES
.
append
(
"[0]"
));
}
result
.
addAll
(
includes
);
});
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java
View file @
80ad6385
...
...
@@ -27,6 +27,8 @@ import java.util.stream.Collectors;
import
org.junit.jupiter.api.Disabled
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.TestInfo
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
import
org.springframework.boot.ConfigurableBootstrapContext
;
import
org.springframework.boot.DefaultBootstrapContext
;
...
...
@@ -45,6 +47,7 @@ import org.springframework.mock.env.MockPropertySource;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatNoException
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
...
...
@@ -216,6 +219,53 @@ class ConfigDataEnvironmentTests {
assertThat
(
this
.
environment
.
getActiveProfiles
()).
containsExactly
(
"test"
);
}
@ParameterizedTest
@CsvSource
({
"include"
,
"include[0]"
})
void
processAndApplyThrowExceptionWhenActivateProfileWithProfileInclude
(
String
property
,
TestInfo
info
)
{
this
.
environment
.
setProperty
(
"spring.config.location"
,
getConfigLocation
(
info
));
ConfigDataEnvironment
configDataEnvironment
=
new
ConfigDataEnvironment
(
this
.
logFactory
,
this
.
bootstrapContext
,
this
.
environment
,
this
.
resourceLoader
,
this
.
additionalProfiles
,
null
)
{
@Override
protected
ConfigDataEnvironmentContributors
createContributors
(
List
<
ConfigDataEnvironmentContributor
>
contributors
)
{
Map
<
String
,
Object
>
source
=
new
LinkedHashMap
<>();
source
.
put
(
"spring.config.activate.on-profile"
,
"activate"
);
source
.
put
(
"spring.profiles."
+
property
,
"include"
);
ConfigData
data
=
new
ConfigData
(
Collections
.
singleton
(
new
MapPropertySource
(
"test"
,
source
)));
contributors
.
add
(
ConfigDataEnvironmentContributor
.
ofUnboundImport
(
ConfigDataLocation
.
of
(
"test"
),
mock
(
ConfigDataResource
.
class
),
false
,
data
,
0
));
return
super
.
createContributors
(
contributors
);
}
};
assertThatExceptionOfType
(
InactiveConfigDataAccessException
.
class
)
.
isThrownBy
(
configDataEnvironment:
:
processAndApply
);
}
@ParameterizedTest
@CsvSource
({
"spring.config.activate.on-profile"
,
"spring.profiles.include"
,
"spring.profiles.include[0]"
})
void
processAndApplyDoseNotThrowExceptionWhenUsingEitherActivateProfileOrProfileInclude
(
String
property
,
TestInfo
info
)
{
this
.
environment
.
setProperty
(
"spring.config.location"
,
getConfigLocation
(
info
));
ConfigDataEnvironment
configDataEnvironment
=
new
ConfigDataEnvironment
(
this
.
logFactory
,
this
.
bootstrapContext
,
this
.
environment
,
this
.
resourceLoader
,
this
.
additionalProfiles
,
null
)
{
@Override
protected
ConfigDataEnvironmentContributors
createContributors
(
List
<
ConfigDataEnvironmentContributor
>
contributors
)
{
Map
<
String
,
Object
>
source
=
new
LinkedHashMap
<>();
source
.
put
(
property
,
"only"
);
ConfigData
data
=
new
ConfigData
(
Collections
.
singleton
(
new
MapPropertySource
(
"test"
,
source
)));
contributors
.
add
(
ConfigDataEnvironmentContributor
.
ofUnboundImport
(
ConfigDataLocation
.
of
(
"test"
),
mock
(
ConfigDataResource
.
class
),
false
,
data
,
0
));
return
super
.
createContributors
(
contributors
);
}
};
assertThatNoException
().
isThrownBy
(
configDataEnvironment:
:
processAndApply
);
}
@Test
@Disabled
(
"Disabled until spring.profiles support is dropped"
)
void
processAndApplyWhenHasInvalidPropertyThrowsException
()
{
...
...
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