Skip to content

Commit 3cb5c99

Browse files
authored
Configuration annotation processor. (helidon-io#3250)
* Configuration annotation processor. Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
1 parent 5a2ce0b commit 3cb5c99

86 files changed

Lines changed: 3753 additions & 38 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bom/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@
291291
<artifactId>helidon-config-mp</artifactId>
292292
<version>${helidon.version}</version>
293293
</dependency>
294+
<dependency>
295+
<groupId>io.helidon.config</groupId>
296+
<artifactId>helidon-config-metadata</artifactId>
297+
<version>${helidon.version}</version>
298+
</dependency>
299+
<dependency>
300+
<groupId>io.helidon.config</groupId>
301+
<artifactId>helidon-config-metadata-processor</artifactId>
302+
<version>${helidon.version}</version>
303+
</dependency>
294304
<!-- security -->
295305
<dependency>
296306
<groupId>io.helidon.security</groupId>

common/configurable/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
<groupId>io.helidon.config</groupId>
4747
<artifactId>helidon-config</artifactId>
4848
</dependency>
49+
<dependency>
50+
<groupId>io.helidon.config</groupId>
51+
<artifactId>helidon-config-metadata</artifactId>
52+
<scope>provided</scope>
53+
<optional>true</optional>
54+
</dependency>
55+
<dependency>
56+
<groupId>io.helidon.config</groupId>
57+
<artifactId>helidon-config-metadata-processor</artifactId>
58+
<scope>provided</scope>
59+
<optional>true</optional>
60+
</dependency>
4961
<dependency>
5062
<groupId>io.helidon.common</groupId>
5163
<artifactId>helidon-common-service-loader</artifactId>

common/configurable/src/main/java/io/helidon/common/configurable/LruCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.function.Supplier;
2525

2626
import io.helidon.config.Config;
27+
import io.helidon.config.metadata.Configured;
28+
import io.helidon.config.metadata.ConfiguredOption;
2729

2830
/**
2931
* Least recently used cache.
@@ -216,6 +218,7 @@ V directGet(K key) {
216218
* @param <K> type of keys
217219
* @param <V> type of values
218220
*/
221+
@Configured
219222
public static class Builder<K, V> implements io.helidon.common.Builder<LruCache<K, V>> {
220223
private int capacity = DEFAULT_CAPACITY;
221224

@@ -241,6 +244,7 @@ public Builder<K, V> config(Config config) {
241244
* @param capacity maximal number of records in the cache before the oldest one is removed
242245
* @return updated builder instance
243246
*/
247+
@ConfiguredOption("10000")
244248
public Builder<K, V> capacity(int capacity) {
245249
this.capacity = capacity;
246250
return this;

common/configurable/src/main/java/io/helidon/common/configurable/Resource.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2021 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,6 +27,9 @@
2727

2828
import io.helidon.config.Config;
2929
import io.helidon.config.ConfigException;
30+
import io.helidon.config.DeprecatedConfig;
31+
import io.helidon.config.metadata.Configured;
32+
import io.helidon.config.metadata.ConfiguredOption;
3033

3134
/**
3235
* A representation of a resource that can be
@@ -41,6 +44,7 @@
4144
* there is an option: call {@link #cacheBytes()} before accessing it by other threads.
4245
* Note that this stores all the bytes in memory, so use with care!!!
4346
*/
47+
@Configured
4448
public interface Resource {
4549
/**
4650
* Load resource from URI provided.
@@ -102,6 +106,7 @@ static Resource create(Path fsPath) {
102106
* @param bytes raw bytes of this resource
103107
* @return resource instance
104108
*/
109+
@ConfiguredOption(key = "content", description = "Base64 encoded content of the resource")
105110
static Resource create(String description, byte[] bytes) {
106111
Objects.requireNonNull(bytes, "Resource bytes must not be null");
107112
return new ResourceImpl(Source.BINARY_CONTENT, description, bytes);
@@ -150,10 +155,20 @@ static Resource create(String description, InputStream inputStream) {
150155
* @return a resource ready to load from one of the locations
151156
* @throws io.helidon.config.ConfigException in case this config does not define a resource configuration
152157
*/
158+
@ConfiguredOption(key = "resource-path", description = "Classpath location of the resource.")
159+
@ConfiguredOption(key = "path", description = "File system path to the resource.")
160+
@ConfiguredOption(key = "content-plain", description = "Plain text content of the resource")
161+
@ConfiguredOption(key = "uri", type = URI.class, description = "URI of the resource.")
162+
@ConfiguredOption(key = "proxy-host", description = "Host of the proxy when using url.")
163+
@ConfiguredOption(key = "proxy-port", type = Integer.class, description = "Port of the proxy when using url.")
164+
@ConfiguredOption(key = "use-proxy",
165+
type = Boolean.class,
166+
description = "Whether to use proxy. Only used if proxy-host is defined as well.",
167+
value = "true")
153168
static Resource create(Config resourceConfig) {
154169
return ResourceUtil.fromConfigPath(resourceConfig.get("path"))
155170
.or(() -> ResourceUtil.fromConfigResourcePath(resourceConfig.get("resource-path")))
156-
.or(() -> ResourceUtil.fromConfigUrl(resourceConfig.get("url")))
171+
.or(() -> ResourceUtil.fromConfigUrl(DeprecatedConfig.get(resourceConfig, "uri", "url")))
157172
.or(() -> ResourceUtil.fromConfigContent(resourceConfig.get("content-plain")))
158173
.or(() -> ResourceUtil.fromConfigB64Content(resourceConfig.get("content")))
159174
.orElseThrow(() -> new ConfigException("Config is not a resource configuration on key: " + resourceConfig.key()

common/configurable/src/main/java/io/helidon/common/configurable/ScheduledThreadPoolSupplier.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
2+
* Copyright (c) 2018, 2021 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.
@@ -26,6 +26,8 @@
2626
import io.helidon.common.LazyValue;
2727
import io.helidon.common.context.Contexts;
2828
import io.helidon.config.Config;
29+
import io.helidon.config.metadata.Configured;
30+
import io.helidon.config.metadata.ConfiguredOption;
2931

3032
/**
3133
* Supplier of a custom scheduled thread pool.
@@ -117,6 +119,7 @@ public ScheduledExecutorService get() {
117119
/**
118120
* A fluent API builder for {@link ScheduledThreadPoolSupplier}.
119121
*/
122+
@Configured
120123
public static final class Builder implements io.helidon.common.Builder<ScheduledThreadPoolSupplier> {
121124
private int corePoolSize = EXECUTOR_DEFAULT_CORE_POOL_SIZE;
122125
private boolean isDaemon = EXECUTOR_DEFAULT_IS_DAEMON;
@@ -137,6 +140,7 @@ public ScheduledThreadPoolSupplier build() {
137140
* @param corePoolSize see {@link ThreadPoolExecutor#getCorePoolSize()}
138141
* @return updated builder instance
139142
*/
143+
@ConfiguredOption("16")
140144
public Builder corePoolSize(int corePoolSize) {
141145
this.corePoolSize = corePoolSize;
142146
return this;
@@ -148,6 +152,7 @@ public Builder corePoolSize(int corePoolSize) {
148152
* @param daemon whether the threads are daemon threads
149153
* @return updated builder instance
150154
*/
155+
@ConfiguredOption(key = "is-daemon", value = "true")
151156
public Builder daemon(boolean daemon) {
152157
isDaemon = daemon;
153158
return this;
@@ -159,6 +164,7 @@ public Builder daemon(boolean daemon) {
159164
* @param threadNamePrefix prefix of a thread name
160165
* @return updated builder instance
161166
*/
167+
@ConfiguredOption("helidon-")
162168
public Builder threadNamePrefix(String threadNamePrefix) {
163169
this.threadNamePrefix = threadNamePrefix;
164170
return this;
@@ -170,6 +176,7 @@ public Builder threadNamePrefix(String threadNamePrefix) {
170176
* @param prestart whether to prestart the threads
171177
* @return updated builder instance
172178
*/
179+
@ConfiguredOption(key = "should-prestart", value = "true")
173180
public Builder prestart(boolean prestart) {
174181
this.prestart = prestart;
175182
return this;

common/configurable/src/main/java/io/helidon/common/configurable/ThreadPoolSupplier.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import io.helidon.common.LazyValue;
2727
import io.helidon.common.context.Contexts;
2828
import io.helidon.config.Config;
29+
import io.helidon.config.metadata.Configured;
30+
import io.helidon.config.metadata.ConfiguredOption;
2931

3032
/**
3133
* Supplier of a custom thread pool.
@@ -146,6 +148,7 @@ public int corePoolSize() {
146148
/**
147149
* A fluent API builder for {@link ThreadPoolSupplier}.
148150
*/
151+
@Configured
149152
public static final class Builder implements io.helidon.common.Builder<ThreadPoolSupplier> {
150153
private int corePoolSize = DEFAULT_CORE_POOL_SIZE;
151154
private int maxPoolSize = DEFAULT_MAX_POOL_SIZE;
@@ -189,6 +192,7 @@ public ThreadPoolSupplier build() {
189192
* @param corePoolSize see {@link ThreadPoolExecutor#getCorePoolSize()}
190193
* @return updated builder instance
191194
*/
195+
@ConfiguredOption("10")
192196
public Builder corePoolSize(int corePoolSize) {
193197
this.corePoolSize = corePoolSize;
194198
return this;
@@ -200,6 +204,7 @@ public Builder corePoolSize(int corePoolSize) {
200204
* @param maxPoolSize see {@link ThreadPoolExecutor#getMaximumPoolSize()}
201205
* @return updated builder instance
202206
*/
207+
@ConfiguredOption("50")
203208
public Builder maxPoolSize(int maxPoolSize) {
204209
this.maxPoolSize = maxPoolSize;
205210
return this;
@@ -211,6 +216,7 @@ public Builder maxPoolSize(int maxPoolSize) {
211216
* @param keepAliveMinutes see {@link ThreadPoolExecutor#getKeepAliveTime(TimeUnit)}
212217
* @return updated builder instance
213218
*/
219+
@ConfiguredOption("3")
214220
public Builder keepAliveMinutes(int keepAliveMinutes) {
215221
this.keepAliveMinutes = keepAliveMinutes;
216222
return this;
@@ -222,6 +228,7 @@ public Builder keepAliveMinutes(int keepAliveMinutes) {
222228
* @param queueCapacity capacity of the queue backing the executor
223229
* @return updated builder instance
224230
*/
231+
@ConfiguredOption("10000")
225232
public Builder queueCapacity(int queueCapacity) {
226233
this.queueCapacity = queueCapacity;
227234
return this;
@@ -233,6 +240,7 @@ public Builder queueCapacity(int queueCapacity) {
233240
* @param daemon whether the threads are daemon threads
234241
* @return updated builder instance
235242
*/
243+
@ConfiguredOption(key = "is-daemon", value = "true")
236244
public Builder daemon(boolean daemon) {
237245
isDaemon = daemon;
238246
return this;
@@ -255,6 +263,7 @@ public Builder name(String name) {
255263
* @param growthThreshold the growth threshold
256264
* @return updated builder instance
257265
*/
266+
@ConfiguredOption("256")
258267
Builder growthThreshold(int growthThreshold) {
259268
this.growthThreshold = growthThreshold;
260269
return this;
@@ -274,6 +283,7 @@ Builder growthThreshold(int growthThreshold) {
274283
* @param growthRate the growth rate
275284
* @return updated builder instance
276285
*/
286+
@ConfiguredOption("5")
277287
Builder growthRate(int growthRate) {
278288
this.growthRate = growthRate;
279289
return this;
@@ -296,6 +306,7 @@ public Builder rejectionHandler(ThreadPool.RejectionHandler rejectionHandler) {
296306
* @param threadNamePrefix prefix of a thread name
297307
* @return updated builder instance
298308
*/
309+
@ConfiguredOption("helidon-")
299310
public Builder threadNamePrefix(String threadNamePrefix) {
300311
this.threadNamePrefix = threadNamePrefix;
301312
return this;
@@ -307,6 +318,7 @@ public Builder threadNamePrefix(String threadNamePrefix) {
307318
* @param prestart whether to prestart the threads
308319
* @return updated builder instance
309320
*/
321+
@ConfiguredOption(key = "should-prestart", value = "true")
310322
public Builder prestart(boolean prestart) {
311323
this.prestart = prestart;
312324
return this;
@@ -433,6 +445,7 @@ private void warnExperimental(String key) {
433445
* @return updated builder instance
434446
* @see #virtualIfAvailable(boolean)
435447
*/
448+
@ConfiguredOption(value = "false", experimental = true)
436449
public Builder virtualEnforced(boolean enforceVirtualThreads) {
437450
this.virtualThreadsEnforced = enforceVirtualThreads;
438451
return this;
@@ -448,6 +461,7 @@ public Builder virtualEnforced(boolean enforceVirtualThreads) {
448461
* @param useVirtualThreads whether to use virtual threads or not, defaults to {@code false}
449462
* @return updated builder instance
450463
*/
464+
@ConfiguredOption(key = "virtual-threads", value = "false", experimental = true)
451465
public Builder virtualIfAvailable(boolean useVirtualThreads) {
452466
this.useVirtualThreads = useVirtualThreads;
453467
return this;

common/configurable/src/main/java/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525
requires transitive io.helidon.config;
2626
requires io.helidon.common;
2727
requires io.helidon.common.context;
28+
requires static io.helidon.config.metadata;
29+
2830
exports io.helidon.common.configurable;
2931
}

common/key-util/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
<groupId>io.helidon.common</groupId>
3535
<artifactId>helidon-common-configurable</artifactId>
3636
</dependency>
37+
<dependency>
38+
<groupId>io.helidon.config</groupId>
39+
<artifactId>helidon-config-metadata</artifactId>
40+
<scope>provided</scope>
41+
<optional>true</optional>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.helidon.config</groupId>
45+
<artifactId>helidon-config-metadata-processor</artifactId>
46+
<scope>provided</scope>
47+
<optional>true</optional>
48+
</dependency>
3749
<dependency>
3850
<groupId>io.helidon.bundles</groupId>
3951
<artifactId>helidon-bundles-config</artifactId>

common/key-util/src/main/java/io/helidon/common/pki/DerUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import java.security.spec.KeySpec;
2222
import java.security.spec.RSAPrivateCrtKeySpec;
2323

24-
import sun.security.util.DerInputStream;
25-
import sun.security.util.DerValue;
26-
2724
final class DerUtils {
2825
private DerUtils() {
2926
}
@@ -43,8 +40,9 @@ static void checkEnabled() {
4340

4441
static KeySpec pkcs1RsaKeySpec(byte[] bytes) {
4542
try {
46-
DerInputStream derReader = new DerInputStream(bytes);
47-
DerValue[] seq = derReader.getSequence(0);
43+
// fully qualified class names allow us to compile this without failure
44+
sun.security.util.DerInputStream derReader = new sun.security.util.DerInputStream(bytes);
45+
sun.security.util.DerValue[] seq = derReader.getSequence(0);
4846
// skip version seq[0];
4947
BigInteger modulus = seq[1].getBigInteger();
5048
BigInteger publicExp = seq[2].getBigInteger();

0 commit comments

Comments
 (0)