Skip to content

Commit 8c4e6f7

Browse files
committed
Revert "Merge pull request #21060 from dsyer"
This reverts commit 6547ea5, reversing changes made to e9e4a34. Fixes gh-22039
1 parent 2f5145b commit 8c4e6f7

File tree

2 files changed

+7
-73
lines changed

2 files changed

+7
-73
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.samskivert.mustache.DefaultCollector;
2020
import com.samskivert.mustache.Mustache.Collector;
2121
import com.samskivert.mustache.Mustache.VariableFetcher;
22-
import com.samskivert.mustache.Template;
2322

2423
import org.springframework.context.EnvironmentAware;
2524
import org.springframework.core.env.ConfigurableEnvironment;
@@ -36,56 +35,29 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements En
3635

3736
private ConfigurableEnvironment environment;
3837

38+
private final VariableFetcher propertyFetcher = new PropertyVariableFetcher();
39+
3940
@Override
4041
public void setEnvironment(Environment environment) {
4142
this.environment = (ConfigurableEnvironment) environment;
4243
}
4344

4445
@Override
4546
public VariableFetcher createFetcher(Object ctx, String name) {
46-
VariableFetcher nativeFetcher = super.createFetcher(ctx, name);
47-
if (nativeFetcher != null) {
48-
return new PropertyVariableFetcher(nativeFetcher);
47+
VariableFetcher fetcher = super.createFetcher(ctx, name);
48+
if (fetcher != null) {
49+
return fetcher;
4950
}
5051
if (this.environment.containsProperty(name)) {
51-
return new PropertyVariableFetcher();
52+
return this.propertyFetcher;
5253
}
5354
return null;
5455
}
5556

56-
/**
57-
* {@link VariableFetcher} that also checks the {@link Environment}.
58-
*/
5957
private class PropertyVariableFetcher implements VariableFetcher {
6058

61-
private final VariableFetcher nativeFetcher;
62-
63-
PropertyVariableFetcher() {
64-
this.nativeFetcher = null;
65-
}
66-
67-
PropertyVariableFetcher(VariableFetcher delegate) {
68-
this.nativeFetcher = delegate;
69-
}
70-
7159
@Override
7260
public Object get(Object ctx, String name) {
73-
Object result = getFromNativeFetcher(ctx, name);
74-
result = (result != null) ? result : getFromEnvironment(name);
75-
return (result != null) ? result : Template.NO_FETCHER_FOUND;
76-
}
77-
78-
private Object getFromNativeFetcher(Object ctx, String name) {
79-
try {
80-
Object result = (this.nativeFetcher != null) ? this.nativeFetcher.get(ctx, name) : null;
81-
return (result != Template.NO_FETCHER_FOUND) ? result : null;
82-
}
83-
catch (Exception ex) {
84-
return null;
85-
}
86-
}
87-
88-
private Object getFromEnvironment(String name) {
8961
return MustacheEnvironmentCollector.this.environment.getProperty(name);
9062
}
9163

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @author Dave Syer
3838
*/
3939
@DirtiesContext
40-
@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = { "env.FOO=There", "foo=World", "bar.name=Bar" })
40+
@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = { "env.FOO=There", "foo=World" })
4141
class MustacheStandaloneIntegrationTests {
4242

4343
@Autowired
@@ -60,53 +60,15 @@ void environmentCollectorCompoundKeyStandard() {
6060
.isEqualTo("Hello: There");
6161
}
6262

63-
@Test
64-
void environmentCollectorCompoundKeyStandardMap() {
65-
assertThat(this.compiler.standardsMode(true).compile("Hello: {{env.foo}}")
66-
.execute(Collections.singletonMap("world", "World"))).isEqualTo("Hello: There");
67-
}
68-
69-
@Test
70-
void environmentCollectorCompoundKeyWithBean() {
71-
assertThat(this.compiler.compile("Hello: {{foo.name}}").execute(Collections.singletonMap("foo", new Foo())))
72-
.isEqualTo("Hello: Foo");
73-
}
74-
75-
@Test
76-
void environmentCollectorCompoundKeyWithBeanPrefersEnvironment() {
77-
assertThat(this.compiler.compile("Hello: {{bar.name}}").execute(Collections.singletonMap("bar", new Foo())))
78-
.isEqualTo("Hello: Bar");
79-
}
80-
8163
@Test
8264
void environmentCollectorSimpleKey() {
8365
assertThat(this.compiler.compile("Hello: {{foo}}").execute(new Object())).isEqualTo("Hello: World");
8466
}
8567

86-
@Test
87-
void environmentCollectorSimpleKeyMap() {
88-
assertThat(this.compiler.compile("Hello: {{foo}}").execute(Collections.singletonMap("world", "Foo")))
89-
.isEqualTo("Hello: World");
90-
}
91-
9268
@Configuration(proxyBeanMethods = false)
9369
@Import({ MustacheAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
9470
static class Application {
9571

9672
}
9773

98-
static class Foo {
99-
100-
private String name = "Foo";
101-
102-
String getName() {
103-
return this.name;
104-
}
105-
106-
void setName(String name) {
107-
this.name = name;
108-
}
109-
110-
}
111-
11274
}

0 commit comments

Comments
 (0)