Skip to content

Commit ea9706a

Browse files
authored
Merge pull request #287 from adrienlauer/check-tool
Checktool
2 parents bfa3b6b + f23d476 commit ea9706a

32 files changed

+879
-57
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Version 3.12.0 (2021-01-31)
22

33
* [new] Java 15 support
4+
* [new] The `check` tool analyzes and show discrepancies between configuration files (actual config) and configuration objects (expected config).
45
* [chg] Move main entrypoint logic from `SeedMain.main()` to `Seed.launch()`, allowing custom main methods in addition to the built-in `SeedMain`.
56
* [chg] Upgrade Shiro to 1.7.1 (fixes CVE-2020-11989, CVE-2020-17510, CVE-2020-1957, CVE-2020-13933 and CVE-2019-12422).
67
* [chg] Upgrade Guice to 5.0.1

core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@
151151
<version>${glassfish-javax.el.version}</version>
152152
<optional>true</optional>
153153
</dependency>
154+
<dependency>
155+
<groupId>org.hibernate</groupId>
156+
<artifactId>hibernate-validator</artifactId>
157+
<version>${hibernate-validator.version}</version>
158+
<optional>true</optional>
159+
</dependency>
154160

155161
<!-- Test dependencies -->
156162
<dependency>

core/src/main/java/org/seedstack/seed/core/Seed.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.seed.core;
910

1011
import com.google.common.base.Strings;

core/src/main/java/org/seedstack/seed/core/SeedRuntime.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.seed.core;
910

1011
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;

core/src/main/java/org/seedstack/seed/core/internal/CoreErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.seed.core.internal;
910

1011
import org.seedstack.shed.exception.ErrorCode;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright © 2013-2021, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.seed.core.internal.configuration.tool;
9+
10+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11+
import io.nuun.kernel.api.plugin.InitState;
12+
import io.nuun.kernel.api.plugin.context.InitContext;
13+
import io.nuun.kernel.api.plugin.request.ClasspathScanRequest;
14+
import java.util.ArrayList;
15+
import java.util.Collection;
16+
import java.util.Collections;
17+
import java.util.List;
18+
import org.seedstack.coffig.Coffig;
19+
import org.seedstack.coffig.Config;
20+
import org.seedstack.seed.core.SeedRuntime;
21+
import org.seedstack.seed.core.internal.AbstractSeedTool;
22+
23+
public abstract class AbstractConfigTool extends AbstractSeedTool {
24+
final Node root = new Node();
25+
@SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "Field is initialized by a call to 'setup' method")
26+
Coffig configuration;
27+
28+
@Override
29+
protected void setup(SeedRuntime seedRuntime) {
30+
configuration = seedRuntime.getConfiguration();
31+
}
32+
33+
@Override
34+
public Collection<ClasspathScanRequest> classpathScanRequests() {
35+
return classpathScanRequestBuilder()
36+
.annotationType(Config.class)
37+
.build();
38+
}
39+
40+
@Override
41+
protected InitState initialize(InitContext initContext) {
42+
List<Node> nodes = new ArrayList<>();
43+
initContext.scannedClassesByAnnotationClass().get(Config.class).stream().map(
44+
configClass -> new Node(configClass, configuration)).forEach(nodes::add);
45+
Collections.sort(nodes);
46+
nodes.forEach(this::buildTree);
47+
return InitState.INITIALIZED;
48+
}
49+
50+
private void buildTree(Node node) {
51+
Node current = root;
52+
String[] path = node.getPath();
53+
for (String part : path) {
54+
if (!part.isEmpty()) {
55+
Node child = current.getChild(part);
56+
if (child != null) {
57+
current = child;
58+
} else {
59+
current.addChild(node);
60+
break;
61+
}
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)