Skip to content

Commit 94d0213

Browse files
committed
Fix config eval in classes section, fixes #283
1 parent 9346f00 commit 94d0213

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [chg] Move main entrypoint logic from `SeedMain.main()` to `Seed.launch()`, allowing custom main methods in addition to the built-in `SeedMain`.
44
* [chg] Upgrade Shiro to 1.7.1 (fixes CVE-2020-11989, CVE-2020-17510, CVE-2020-1957, CVE-2020-13933 and CVE-2019-12422).
55
* [fix] Detection of color output under recent versions of IntelliJ.
6+
* [fix] Fix configuration evaluation (macros, functions, ...) in `classes` section (see https://github.com/seedstack/seed/issues/283).
67

78
# Version 3.11.0 (2020-10-28)
89

core/src/main/java/org/seedstack/seed/core/internal/configuration/ClassConfigurationMapper.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,28 @@
77
*/
88
package org.seedstack.seed.core.internal.configuration;
99

10-
import static org.seedstack.shed.reflect.Types.rawClassOf;
11-
1210
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13-
import java.lang.reflect.ParameterizedType;
14-
import java.lang.reflect.Type;
15-
import java.util.HashMap;
16-
import java.util.Map;
11+
import org.seedstack.coffig.Coffig;
1712
import org.seedstack.coffig.TreeNode;
1813
import org.seedstack.coffig.spi.ConfigurationMapper;
1914
import org.seedstack.seed.ClassConfiguration;
2015
import org.seedstack.seed.SeedException;
2116
import org.seedstack.seed.core.internal.CoreErrorCode;
2217

18+
import java.lang.reflect.ParameterizedType;
19+
import java.lang.reflect.Type;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
import static org.seedstack.shed.reflect.Types.rawClassOf;
24+
2325
public class ClassConfigurationMapper implements ConfigurationMapper {
26+
private Coffig coffig;
27+
28+
public void initialize(Coffig coffig) {
29+
this.coffig = coffig;
30+
}
31+
2432
@Override
2533
public boolean canHandle(Type type) {
2634
if (type instanceof ParameterizedType) {
@@ -40,7 +48,7 @@ public Object map(TreeNode treeNode, Type type) {
4048
Map<String, String> result = new HashMap<>();
4149
treeNode.namedNodes()
4250
.filter(namedNode -> isValueNode(namedNode.node()))
43-
.forEach(namedNode -> result.put(namedNode.name(), namedNode.node().value()));
51+
.forEach(namedNode -> result.put(namedNode.name(), (String) coffig.getMapper().map(namedNode.node(), String.class)));
4452
return ClassConfiguration.of(rawType, result);
4553
} else {
4654
throw SeedException.createNew(CoreErrorCode.INVALID_CLASS_CONFIGURATION)

core/src/test/java/org/seedstack/seed/core/ConfigurationIT.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import static org.assertj.core.api.Assertions.assertThat;
1111

1212
import com.google.inject.Injector;
13+
1314
import javax.inject.Inject;
15+
1416
import org.junit.Test;
1517
import org.junit.runner.RunWith;
1618
import org.seedstack.coffig.Coffig;
@@ -134,10 +136,11 @@ public void configuration_object_injection() {
134136
public void class_attributes_can_be_retrieved() {
135137
Application application = injector.getInstance(Application.class);
136138
ClassConfiguration<ConfigurationIT> configuration = application.getConfiguration(ConfigurationIT.class);
137-
assertThat(configuration.keySet()).containsExactly("key1", "key2", "key3");
139+
assertThat(configuration.keySet()).containsExactlyInAnyOrder("key1", "key2", "key3", "evalKey");
138140
assertThat(configuration.get("key1")).isEqualTo("value1");
139141
assertThat(configuration.get("key2")).isEqualTo("value2bis");
140142
assertThat(configuration.get("key3")).isEqualTo("value3");
143+
assertThat(configuration.get("evalKey")).isEqualTo("VALUE");
141144
}
142145

143146
@Test

core/src/test/resources/application.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classes:
1919
ConfigurationIT:
2020
key2: value2bis
2121
key3: value3
22+
evalKey: ${env.ABDKSKFZOALKCHKHJ:'VALUE'}
2223
logging:
2324
level: INFO
2425
file:

0 commit comments

Comments
 (0)