Skip to content

Commit 54c043a

Browse files
authored
Config metadata update (helidon-io#4403)
* Update to configuration metadata processor and HealthSupport config documentation (and dependent classes) * Use response type of build method when inheriting builder Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
1 parent 8551c0a commit 54c043a

16 files changed

Lines changed: 266 additions & 59 deletions

File tree

config/metadata-processor/src/main/java/io/helidon/config/metadata/processor/ConfigMetadataHandler.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ - a standalone class (probably with public static create(Config) method)
186186
- an interface/abstract class only used for inheritance
187187
*/
188188

189-
ConfiguredType type = new ConfiguredType(targetClass,
189+
ConfiguredType type = new ConfiguredType(className,
190+
targetClass,
190191
standalone,
191192
keyPrefix,
192193
description,
@@ -255,6 +256,19 @@ private BuilderTypeInfo findBuilder(TypeElement classElement) {
255256
}
256257
}
257258
}
259+
TypeMirror superMirror = classElement.getSuperclass();
260+
String buildTarget = findBuildMethodTarget(classElement);
261+
if (superMirror.getKind() != TypeKind.NONE) {
262+
TypeElement superclass = (TypeElement) typeUtils.asElement(typeUtils.erasure(superMirror));
263+
found = findBuilder(superclass);
264+
if (found.isBuilder) {
265+
if (buildTarget == null) {
266+
return found;
267+
} else {
268+
return new BuilderTypeInfo(buildTarget);
269+
}
270+
}
271+
}
258272
return new BuilderTypeInfo();
259273
}
260274

@@ -471,6 +485,23 @@ private void processTargetType(TypeElement typeElement,
471485
}
472486
}
473487

488+
private String findBuildMethodTarget(TypeElement typeElement) {
489+
return elementUtils.getAllMembers(typeElement)
490+
.stream()
491+
.filter(it -> it.getKind() == ElementKind.METHOD)
492+
.map(ExecutableElement.class::cast)
493+
// public
494+
.filter(it -> it.getModifiers().contains(Modifier.PUBLIC))
495+
// static
496+
.filter(it -> !it.getModifiers().contains(Modifier.STATIC))
497+
.filter(it -> it.getSimpleName().contentEquals("build"))
498+
.filter(it -> it.getParameters().isEmpty())
499+
.filter(it -> it.getReturnType().getKind() != TypeKind.VOID)
500+
.findFirst()
501+
.map(it -> it.getReturnType().toString())
502+
.orElse(null);
503+
}
504+
474505
private boolean hasCreate(TypeElement typeElement) {
475506
return elementUtils.getAllMembers(typeElement)
476507
.stream()

config/metadata-processor/src/main/java/io/helidon/config/metadata/processor/ConfiguredType.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,17 +27,27 @@
2727
final class ConfiguredType {
2828
private final Set<ConfiguredProperty> allProperties = new HashSet<>();
2929
private final List<ProducerMethod> producerMethods = new LinkedList<>();
30-
/**
30+
/*
3131
* The type that is built by a builder, or created using create method.
3232
*/
3333
private final String targetClass;
34+
/*
35+
The type we are processing that has @Configured annotation
36+
*/
37+
private final String annotatedClass;
3438
private final boolean standalone;
3539
private final String prefix;
3640
private final String description;
3741
private final List<String> provides;
3842
private final List<String> inherited = new LinkedList<>();
3943

40-
ConfiguredType(String targetClass, boolean standalone, String prefix, String description, List<String> provides) {
44+
ConfiguredType(String annotatedClass,
45+
String targetClass,
46+
boolean standalone,
47+
String prefix,
48+
String description,
49+
List<String> provides) {
50+
this.annotatedClass = annotatedClass;
4151
this.targetClass = targetClass;
4252
this.standalone = standalone;
4353
this.prefix = prefix;
@@ -75,6 +85,10 @@ String targetClass() {
7585
return targetClass;
7686
}
7787

88+
String annotatedClass() {
89+
return annotatedClass;
90+
}
91+
7892
boolean standalone() {
7993
return standalone;
8094
}
@@ -87,6 +101,7 @@ public void write(JArray typeArray) {
87101
JObject typeObject = new JObject();
88102

89103
typeObject.add("type", targetClass());
104+
typeObject.add("annotatedType", annotatedClass());
90105
if (standalone()) {
91106
typeObject.add("standalone", true);
92107
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
3+
Copyright (c) 2022 Oracle and/or its affiliates.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
///////////////////////////////////////////////////////////////////////////////
18+
19+
:description: Configuration of io.helidon.health.HealthSupport
20+
:keywords: helidon, config, io.helidon.health.HealthSupport
21+
:basic-table-intro: The table below lists the configuration keys that configure io.helidon.health.HealthSupport
22+
23+
[source,text]
24+
.Type
25+
----
26+
io.helidon.health.HealthSupport
27+
----
28+
29+
30+
31+
==== Configuration options
32+
33+
34+
35+
36+
Optional configuration options:
37+
[cols="3,3,2,5"]
38+
39+
|===
40+
|key |type |default value |description
41+
42+
|`exclude-classes` |Class<?>[&#93; |{nbsp} |A class may be excluded from invoking health checks on it.
43+
This allows configurable approach to disabling broken health-checks.
44+
|`timeout-millis` |long |{nbsp} |health endpoint timeout (ms)
45+
|`exclude` |string[&#93; |{nbsp} |Add health checks to a black list.
46+
Health check results that match by name with a blacklisted records will not be
47+
part of the result.
48+
|`include` |string[&#93; |{nbsp} |Add health checks to a white list (in case #includeAll is set to `false`.
49+
|`enabled` |boolean |{nbsp} |HealthSupport can be disabled by invoking this method.
50+
|`web-context` |string |{nbsp} |Sets the web context to use for the service's endpoint.
51+
|`routing` |string |{nbsp} |Sets the routing name to use for setting up the service's endpoint.
52+
|`cors` |link:../../shared/config/io.helidon.webserver.cors.CrossOriginConfig.adoc[CrossOriginConfig] |{nbsp} |Sets the cross-origin config builder for use in establishing CORS support for the service endpoints.
53+
54+
|===
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
3+
Copyright (c) 2022 Oracle and/or its affiliates.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
///////////////////////////////////////////////////////////////////////////////
18+
19+
:description: Configuration of io.helidon.webserver.cors.CrossOriginConfig
20+
:keywords: helidon, config, io.helidon.webserver.cors.CrossOriginConfig
21+
:basic-table-intro: The table below lists the configuration keys that configure io.helidon.webserver.cors.CrossOriginConfig
22+
23+
[source,text]
24+
.Type
25+
----
26+
io.helidon.webserver.cors.CrossOriginConfig
27+
----
28+
29+
30+
31+
==== Configuration options
32+
33+
34+
35+
36+
Optional configuration options:
37+
[cols="3,3,2,5"]
38+
39+
|===
40+
|key |type |default value |description
41+
42+
|`path-pattern` |string |`{+}` |Updates the path prefix for this cross-origin config.
43+
|`allow-headers` |string[&#93; |`*` |Sets the allow headers.
44+
|`max-age-seconds` |long |`3600` |Sets the maximum age.
45+
|`allow-credentials` |boolean |`false` |Sets the allow credentials flag.
46+
|`allow-origins` |string[&#93; |`*` |Sets the allowOrigins.
47+
|`expose-headers` |string[&#93; |{nbsp} |Sets the expose headers.
48+
|`allow-methods` |string[&#93; |`*` |Sets the allow methods.
49+
|`enabled` |boolean |`true` |Sets whether this config should be enabled or not.
50+
51+
|===

health/health/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
<dependency>
6767
<groupId>io.helidon.config</groupId>
6868
<artifactId>helidon-config-metadata</artifactId>
69+
<scope>provided</scope>
70+
<optional>true</optional>
71+
</dependency>
72+
<dependency>
73+
<groupId>io.helidon.config</groupId>
74+
<artifactId>helidon-config-metadata-processor</artifactId>
75+
<scope>provided</scope>
76+
<optional>true</optional>
6977
</dependency>
7078
<dependency>
7179
<groupId>org.junit.jupiter</groupId>

health/health/src/main/java/io/helidon/health/HealthSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public static final class Builder extends HelidonRestServiceSupport.Builder<Buil
352352
private long timeoutMillis = DEFAULT_TIMEOUT_MILLIS;
353353

354354
private Builder() {
355-
super(Builder.class, DEFAULT_WEB_CONTEXT);
355+
super(DEFAULT_WEB_CONTEXT);
356356
}
357357

358358
@Override
@@ -377,7 +377,7 @@ public Builder addIncluded(String healthCheckName) {
377377
* @param names names of health checks to include
378378
* @return updated builder instance
379379
*/
380-
@ConfiguredOption(key = INCLUDE_CONFIG_KEY)
380+
@ConfiguredOption(key = INCLUDE_CONFIG_KEY, type = String.class, kind = ConfiguredOption.Kind.LIST)
381381
public Builder addIncluded(Collection<String> names) {
382382
if (null == names) {
383383
return this;
@@ -407,7 +407,7 @@ public Builder addExcluded(String healthCheckName) {
407407
* @param names names of health checks to exclude
408408
* @return updated builder instance
409409
*/
410-
@ConfiguredOption(key = EXCLUDE_CONFIG_KEY)
410+
@ConfiguredOption(key = EXCLUDE_CONFIG_KEY, type = String.class, kind = ConfiguredOption.Kind.LIST)
411411
public Builder addExcluded(Collection<String> names) {
412412
if (null == names) {
413413
return this;
@@ -443,7 +443,7 @@ private void timeoutMillis(long aLong) {
443443
* @param unit timeout time unit
444444
* @return updated builder instance
445445
*/
446-
@ConfiguredOption(key = TIMEOUT_CONFIG_KEY, description = "health endpoint timeout (ms)")
446+
@ConfiguredOption(key = TIMEOUT_CONFIG_KEY, description = "health endpoint timeout (ms)", type = Long.class)
447447
public Builder timeout(long timeout, TimeUnit unit) {
448448
timeoutMillis(unit.toMillis(timeout));
449449
return this;

health/health/src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
requires transitive microprofile.health.api;
2525
requires io.helidon.webserver;
2626
requires io.helidon.servicecommon.rest;
27-
requires io.helidon.config.metadata;
27+
requires static io.helidon.config.metadata;
2828
requires io.helidon.webserver.cors;
2929
requires io.helidon.media.jsonp;
3030
requires jakarta.json;

integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -125,7 +125,7 @@ public static class Builder extends HelidonRestServiceSupport.Builder<Builder, M
125125
private Supplier<MeterRegistryFactory> meterRegistryFactorySupplier = null;
126126

127127
private Builder() {
128-
super(Builder.class, DEFAULT_CONTEXT);
128+
super(DEFAULT_CONTEXT);
129129
}
130130

131131
@Override

metrics/metrics/src/main/java/io/helidon/metrics/MetricsSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ public static class Builder extends HelidonRestServiceSupport.Builder<Builder, M
621621
* Creates a new builder instance.
622622
*/
623623
protected Builder() {
624-
super(Builder.class, MetricsSettings.Builder.DEFAULT_CONTEXT);
624+
super(MetricsSettings.Builder.DEFAULT_CONTEXT);
625625
}
626626

627627
@Override

metrics/service-api/src/test/java/io/helidon/metrics/serviceapi/MyMetricsServiceSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ public static class Builder extends HelidonRestServiceSupport.Builder<Builder, M
6767
private ComponentMetricsSettings.Builder componentMetricsSettingsBuilder = ComponentMetricsSettings.builder();
6868

6969
public Builder() {
70-
super(Builder.class, "/myservice");
70+
super("/myservice");
7171
}
7272

7373
public Builder componentMetricsSettings(ComponentMetricsSettings.Builder componentMetricsSettingsBuilder) {

0 commit comments

Comments
 (0)