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
ddbecf62
Commit
ddbecf62
authored
Jun 08, 2020
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish 'Fix Mustache to not ignore native fetcher'
See gh-21060
parent
5199c11e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
28 deletions
+33
-28
MustacheEnvironmentCollector.java
.../autoconfigure/mustache/MustacheEnvironmentCollector.java
+23
-20
MustacheStandaloneIntegrationTests.java
...onfigure/mustache/MustacheStandaloneIntegrationTests.java
+10
-8
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java
View file @
ddbecf62
...
@@ -43,9 +43,9 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements En
...
@@ -43,9 +43,9 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements En
@Override
@Override
public
VariableFetcher
createFetcher
(
Object
ctx
,
String
name
)
{
public
VariableFetcher
createFetcher
(
Object
ctx
,
String
name
)
{
VariableFetcher
f
etcher
=
super
.
createFetcher
(
ctx
,
name
);
VariableFetcher
nativeF
etcher
=
super
.
createFetcher
(
ctx
,
name
);
if
(
f
etcher
!=
null
)
{
if
(
nativeF
etcher
!=
null
)
{
return
new
PropertyVariableFetcher
(
f
etcher
);
return
new
PropertyVariableFetcher
(
nativeF
etcher
);
}
}
if
(
this
.
environment
.
containsProperty
(
name
))
{
if
(
this
.
environment
.
containsProperty
(
name
))
{
return
new
PropertyVariableFetcher
();
return
new
PropertyVariableFetcher
();
...
@@ -53,6 +53,9 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements En
...
@@ -53,6 +53,9 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements En
return
null
;
return
null
;
}
}
/**
* {@link VariableFetcher} that also checks the {@link Environment}.
*/
private
class
PropertyVariableFetcher
implements
VariableFetcher
{
private
class
PropertyVariableFetcher
implements
VariableFetcher
{
private
final
VariableFetcher
nativeFetcher
;
private
final
VariableFetcher
nativeFetcher
;
...
@@ -61,29 +64,29 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements En
...
@@ -61,29 +64,29 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements En
this
.
nativeFetcher
=
null
;
this
.
nativeFetcher
=
null
;
}
}
PropertyVariableFetcher
(
VariableFetcher
nativeFetcher
)
{
PropertyVariableFetcher
(
VariableFetcher
delegate
)
{
this
.
nativeFetcher
=
nativeFetcher
;
this
.
nativeFetcher
=
delegate
;
}
}
@Override
@Override
public
Object
get
(
Object
ctx
,
String
name
)
{
public
Object
get
(
Object
ctx
,
String
name
)
{
Object
result
;
Object
result
=
getFromNativeFetcher
(
ctx
,
name
);
if
(
this
.
nativeFetcher
!=
null
)
{
result
=
(
result
!=
null
)
?
result
:
getFromEnvironment
(
name
);
try
{
return
(
result
!=
null
)
?
result
:
Template
.
NO_FETCHER_FOUND
;
result
=
this
.
nativeFetcher
.
get
(
ctx
,
name
);
}
if
(
result
!=
null
&&
result
!=
Template
.
NO_FETCHER_FOUND
)
{
return
result
;
private
Object
getFromNativeFetcher
(
Object
ctx
,
String
name
)
{
}
try
{
}
Object
result
=
(
this
.
nativeFetcher
!=
null
)
?
this
.
nativeFetcher
.
get
(
ctx
,
name
)
:
null
;
catch
(
Exception
ex
)
{
return
(
result
!=
Template
.
NO_FETCHER_FOUND
)
?
result
:
null
;
// fall through
}
}
}
result
=
MustacheEnvironmentCollector
.
this
.
environment
.
getProperty
(
name
);
catch
(
Exception
ex
)
{
if
(
result
==
null
)
{
return
null
;
return
Template
.
NO_FETCHER_FOUND
;
}
}
return
result
;
}
private
Object
getFromEnvironment
(
String
name
)
{
return
MustacheEnvironmentCollector
.
this
.
environment
.
getProperty
(
name
);
}
}
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java
View file @
ddbecf62
...
@@ -68,14 +68,14 @@ class MustacheStandaloneIntegrationTests {
...
@@ -68,14 +68,14 @@ class MustacheStandaloneIntegrationTests {
@Test
@Test
void
environmentCollectorCompoundKeyWithBean
()
{
void
environmentCollectorCompoundKeyWithBean
()
{
assertThat
(
this
.
compiler
.
compile
(
"Hello: {{foo.name}}"
)
assertThat
(
this
.
compiler
.
compile
(
"Hello: {{foo.name}}"
)
.
execute
(
Collections
.
singletonMap
(
"foo"
,
new
Foo
())))
.
execute
(
Collections
.
singletonMap
(
"foo"
,
new
Foo
()))).
isEqualTo
(
"Hello: Foo"
);
.
isEqualTo
(
"Hello: Foo"
);
}
}
@Test
@Test
void
environmentCollectorCompoundKeyWithBeanPrefersEnvironment
()
{
void
environmentCollectorCompoundKeyWithBeanPrefersEnvironment
()
{
assertThat
(
this
.
compiler
.
compile
(
"Hello: {{bar.name}}"
)
assertThat
(
this
.
compiler
.
compile
(
"Hello: {{bar.name}}"
)
.
execute
(
Collections
.
singletonMap
(
"bar"
,
new
Foo
())))
.
execute
(
Collections
.
singletonMap
(
"bar"
,
new
Foo
()))).
isEqualTo
(
"Hello: Bar"
);
.
isEqualTo
(
"Hello: Bar"
);
}
}
@Test
@Test
...
@@ -94,17 +94,19 @@ class MustacheStandaloneIntegrationTests {
...
@@ -94,17 +94,19 @@ class MustacheStandaloneIntegrationTests {
static
class
Application
{
static
class
Application
{
}
}
static
class
Foo
{
static
class
Foo
{
private
String
name
=
"Foo"
;
private
String
name
=
"Foo"
;
public
String
getName
()
{
String
getName
()
{
return
name
;
return
this
.
name
;
}
}
public
void
setName
(
String
name
)
{
void
setName
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
}
}
}
}
}
}
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