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
92f62043
Commit
92f62043
authored
Jun 20, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix placeholder support in <springProfile>'s name attribute
Closes gh-13450
parent
6081db5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
8 deletions
+100
-8
SpringProfileAction.java
...ngframework/boot/logging/logback/SpringProfileAction.java
+7
-8
SpringProfileActionTests.java
...mework/boot/logging/logback/SpringProfileActionTests.java
+93
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java
View file @
92f62043
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -69,14 +69,13 @@ class SpringProfileAction extends Action implements InPlayListener {
private
boolean
acceptsProfiles
(
InterpretationContext
ic
,
Attributes
attributes
)
{
String
[]
profileNames
=
StringUtils
.
trimArrayElements
(
StringUtils
.
commaDelimitedListToStringArray
(
attributes
.
getValue
(
NAME_ATTRIBUTE
)));
if
(
profileNames
.
length
!=
0
)
{
for
(
String
profileName
:
profileNames
)
{
OptionHelper
.
substVars
(
profileName
,
ic
,
this
.
context
);
}
return
this
.
environment
!=
null
&&
this
.
environment
.
acceptsProfiles
(
profileNames
);
if
(
this
.
environment
==
null
||
profileNames
.
length
==
0
)
{
return
false
;
}
return
false
;
for
(
int
i
=
0
;
i
<
profileNames
.
length
;
i
++)
{
profileNames
[
i
]
=
OptionHelper
.
substVars
(
profileNames
[
i
],
ic
,
this
.
context
);
}
return
this
.
environment
.
acceptsProfiles
(
profileNames
);
}
@Override
...
...
spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringProfileActionTests.java
0 → 100644
View file @
92f62043
/*
* 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
.
logging
.
logback
;
import
ch.qos.logback.core.Context
;
import
ch.qos.logback.core.ContextBase
;
import
ch.qos.logback.core.joran.action.Action
;
import
ch.qos.logback.core.joran.spi.ActionException
;
import
ch.qos.logback.core.joran.spi.InterpretationContext
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.xml.sax.Attributes
;
import
org.springframework.core.env.Environment
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link SpringProfileAction}.
*
* @author Andy Wilkinson
*/
public
class
SpringProfileActionTests
{
private
final
Environment
environment
=
mock
(
Environment
.
class
);
private
final
SpringProfileAction
action
=
new
SpringProfileAction
(
this
.
environment
);
private
final
Context
context
=
new
ContextBase
();
private
final
InterpretationContext
interpretationContext
=
new
InterpretationContext
(
this
.
context
,
null
);
private
final
Attributes
attributes
=
mock
(
Attributes
.
class
);
@Before
public
void
setUp
()
{
this
.
action
.
setContext
(
this
.
context
);
}
@Test
public
void
environmentIsQueriedWithProfileFromNameAttribute
()
throws
ActionException
{
given
(
this
.
attributes
.
getValue
(
Action
.
NAME_ATTRIBUTE
)).
willReturn
(
"dev"
);
this
.
action
.
begin
(
this
.
interpretationContext
,
null
,
this
.
attributes
);
verify
(
this
.
environment
).
acceptsProfiles
(
"dev"
);
}
@Test
public
void
environmentIsQueriedWithMultipleProfilesFromCommaSeparatedNameAttribute
()
throws
ActionException
{
given
(
this
.
attributes
.
getValue
(
Action
.
NAME_ATTRIBUTE
)).
willReturn
(
"dev,qa"
);
this
.
action
.
begin
(
this
.
interpretationContext
,
null
,
this
.
attributes
);
verify
(
this
.
environment
).
acceptsProfiles
(
"dev"
,
"qa"
);
}
@Test
public
void
environmentIsQueriedWithResolvedValueWhenNameAttributeUsesAPlaceholder
()
throws
ActionException
{
given
(
this
.
attributes
.
getValue
(
Action
.
NAME_ATTRIBUTE
)).
willReturn
(
"${profile}"
);
this
.
context
.
putProperty
(
"profile"
,
"dev"
);
this
.
action
.
begin
(
this
.
interpretationContext
,
null
,
this
.
attributes
);
verify
(
this
.
environment
).
acceptsProfiles
(
"dev"
);
}
@Test
public
void
environmentIsQueriedWithResolvedValuesFromCommaSeparatedNameNameAttributeWithPlaceholders
()
throws
ActionException
{
given
(
this
.
attributes
.
getValue
(
Action
.
NAME_ATTRIBUTE
))
.
willReturn
(
"${profile1},${profile2}"
);
this
.
context
.
putProperty
(
"profile1"
,
"dev"
);
this
.
context
.
putProperty
(
"profile2"
,
"qa"
);
this
.
action
.
begin
(
this
.
interpretationContext
,
null
,
this
.
attributes
);
verify
(
this
.
environment
).
acceptsProfiles
(
"dev"
,
"qa"
);
}
}
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