Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration annotation processor. #3250

Merged
merged 10 commits into from
Oct 4, 2021
10 changes: 10 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@
<artifactId>helidon-config-mp</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata-processor</artifactId>
<version>${helidon.version}</version>
</dependency>
<!-- security -->
<dependency>
<groupId>io.helidon.security</groupId>
Expand Down
12 changes: 12 additions & 0 deletions common/configurable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata-processor</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-service-loader</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.function.Supplier;

import io.helidon.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

/**
* Least recently used cache.
Expand Down Expand Up @@ -216,6 +218,7 @@ V directGet(K key) {
* @param <K> type of keys
* @param <V> type of values
*/
@Configured
public static class Builder<K, V> implements io.helidon.common.Builder<LruCache<K, V>> {
private int capacity = DEFAULT_CAPACITY;

Expand All @@ -241,6 +244,7 @@ public Builder<K, V> config(Config config) {
* @param capacity maximal number of records in the cache before the oldest one is removed
* @return updated builder instance
*/
@ConfiguredOption("10000")
public Builder<K, V> capacity(int capacity) {
this.capacity = capacity;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
* Copyright (c) 2017, 2021 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,9 @@

import io.helidon.config.Config;
import io.helidon.config.ConfigException;
import io.helidon.config.DeprecatedConfig;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

/**
* A representation of a resource that can be
Expand All @@ -41,6 +44,7 @@
* there is an option: call {@link #cacheBytes()} before accessing it by other threads.
* Note that this stores all the bytes in memory, so use with care!!!
*/
@Configured
public interface Resource {
/**
* Load resource from URI provided.
Expand Down Expand Up @@ -102,6 +106,7 @@ static Resource create(Path fsPath) {
* @param bytes raw bytes of this resource
* @return resource instance
*/
@ConfiguredOption(key = "content", description = "Base64 encoded content of the resource")
static Resource create(String description, byte[] bytes) {
Objects.requireNonNull(bytes, "Resource bytes must not be null");
return new ResourceImpl(Source.BINARY_CONTENT, description, bytes);
Expand Down Expand Up @@ -150,10 +155,20 @@ static Resource create(String description, InputStream inputStream) {
* @return a resource ready to load from one of the locations
* @throws io.helidon.config.ConfigException in case this config does not define a resource configuration
*/
@ConfiguredOption(key = "resource-path", description = "Classpath location of the resource.")
@ConfiguredOption(key = "path", description = "File system path to the resource.")
@ConfiguredOption(key = "content-plain", description = "Plain text content of the resource")
@ConfiguredOption(key = "uri", type = URI.class, description = "URI of the resource.")
@ConfiguredOption(key = "proxy-host", description = "Host of the proxy when using url.")
@ConfiguredOption(key = "proxy-port", type = Integer.class, description = "Port of the proxy when using url.")
@ConfiguredOption(key = "use-proxy",
type = Boolean.class,
description = "Whether to use proxy. Only used if proxy-host is defined as well.",
value = "true")
static Resource create(Config resourceConfig) {
return ResourceUtil.fromConfigPath(resourceConfig.get("path"))
.or(() -> ResourceUtil.fromConfigResourcePath(resourceConfig.get("resource-path")))
.or(() -> ResourceUtil.fromConfigUrl(resourceConfig.get("url")))
.or(() -> ResourceUtil.fromConfigUrl(DeprecatedConfig.get(resourceConfig, "uri", "url")))
.or(() -> ResourceUtil.fromConfigContent(resourceConfig.get("content-plain")))
.or(() -> ResourceUtil.fromConfigB64Content(resourceConfig.get("content")))
.orElseThrow(() -> new ConfigException("Config is not a resource configuration on key: " + resourceConfig.key()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
* Copyright (c) 2018, 2021 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,8 @@
import io.helidon.common.LazyValue;
import io.helidon.common.context.Contexts;
import io.helidon.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

/**
* Supplier of a custom scheduled thread pool.
Expand Down Expand Up @@ -117,6 +119,7 @@ public ScheduledExecutorService get() {
/**
* A fluent API builder for {@link ScheduledThreadPoolSupplier}.
*/
@Configured
public static final class Builder implements io.helidon.common.Builder<ScheduledThreadPoolSupplier> {
private int corePoolSize = EXECUTOR_DEFAULT_CORE_POOL_SIZE;
private boolean isDaemon = EXECUTOR_DEFAULT_IS_DAEMON;
Expand All @@ -137,6 +140,7 @@ public ScheduledThreadPoolSupplier build() {
* @param corePoolSize see {@link ThreadPoolExecutor#getCorePoolSize()}
* @return updated builder instance
*/
@ConfiguredOption("16")
public Builder corePoolSize(int corePoolSize) {
this.corePoolSize = corePoolSize;
return this;
Expand All @@ -148,6 +152,7 @@ public Builder corePoolSize(int corePoolSize) {
* @param daemon whether the threads are daemon threads
* @return updated builder instance
*/
@ConfiguredOption(key = "is-daemon", value = "true")
public Builder daemon(boolean daemon) {
isDaemon = daemon;
return this;
Expand All @@ -159,6 +164,7 @@ public Builder daemon(boolean daemon) {
* @param threadNamePrefix prefix of a thread name
* @return updated builder instance
*/
@ConfiguredOption("helidon-")
public Builder threadNamePrefix(String threadNamePrefix) {
this.threadNamePrefix = threadNamePrefix;
return this;
Expand All @@ -170,6 +176,7 @@ public Builder threadNamePrefix(String threadNamePrefix) {
* @param prestart whether to prestart the threads
* @return updated builder instance
*/
@ConfiguredOption(key = "should-prestart", value = "true")
public Builder prestart(boolean prestart) {
this.prestart = prestart;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.helidon.common.LazyValue;
import io.helidon.common.context.Contexts;
import io.helidon.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

/**
* Supplier of a custom thread pool.
Expand Down Expand Up @@ -146,6 +148,7 @@ public int corePoolSize() {
/**
* A fluent API builder for {@link ThreadPoolSupplier}.
*/
@Configured
public static final class Builder implements io.helidon.common.Builder<ThreadPoolSupplier> {
private int corePoolSize = DEFAULT_CORE_POOL_SIZE;
private int maxPoolSize = DEFAULT_MAX_POOL_SIZE;
Expand Down Expand Up @@ -189,6 +192,7 @@ public ThreadPoolSupplier build() {
* @param corePoolSize see {@link ThreadPoolExecutor#getCorePoolSize()}
* @return updated builder instance
*/
@ConfiguredOption("10")
public Builder corePoolSize(int corePoolSize) {
this.corePoolSize = corePoolSize;
return this;
Expand All @@ -200,6 +204,7 @@ public Builder corePoolSize(int corePoolSize) {
* @param maxPoolSize see {@link ThreadPoolExecutor#getMaximumPoolSize()}
* @return updated builder instance
*/
@ConfiguredOption("50")
public Builder maxPoolSize(int maxPoolSize) {
this.maxPoolSize = maxPoolSize;
return this;
Expand All @@ -211,6 +216,7 @@ public Builder maxPoolSize(int maxPoolSize) {
* @param keepAliveMinutes see {@link ThreadPoolExecutor#getKeepAliveTime(TimeUnit)}
* @return updated builder instance
*/
@ConfiguredOption("3")
public Builder keepAliveMinutes(int keepAliveMinutes) {
this.keepAliveMinutes = keepAliveMinutes;
return this;
Expand All @@ -222,6 +228,7 @@ public Builder keepAliveMinutes(int keepAliveMinutes) {
* @param queueCapacity capacity of the queue backing the executor
* @return updated builder instance
*/
@ConfiguredOption("10000")
public Builder queueCapacity(int queueCapacity) {
this.queueCapacity = queueCapacity;
return this;
Expand All @@ -233,6 +240,7 @@ public Builder queueCapacity(int queueCapacity) {
* @param daemon whether the threads are daemon threads
* @return updated builder instance
*/
@ConfiguredOption(key = "is-daemon", value = "true")
public Builder daemon(boolean daemon) {
isDaemon = daemon;
return this;
Expand All @@ -255,6 +263,7 @@ public Builder name(String name) {
* @param growthThreshold the growth threshold
* @return updated builder instance
*/
@ConfiguredOption("256")
Builder growthThreshold(int growthThreshold) {
this.growthThreshold = growthThreshold;
return this;
Expand All @@ -274,6 +283,7 @@ Builder growthThreshold(int growthThreshold) {
* @param growthRate the growth rate
* @return updated builder instance
*/
@ConfiguredOption("5")
Builder growthRate(int growthRate) {
this.growthRate = growthRate;
return this;
Expand All @@ -296,6 +306,7 @@ public Builder rejectionHandler(ThreadPool.RejectionHandler rejectionHandler) {
* @param threadNamePrefix prefix of a thread name
* @return updated builder instance
*/
@ConfiguredOption("helidon-")
public Builder threadNamePrefix(String threadNamePrefix) {
this.threadNamePrefix = threadNamePrefix;
return this;
Expand All @@ -307,6 +318,7 @@ public Builder threadNamePrefix(String threadNamePrefix) {
* @param prestart whether to prestart the threads
* @return updated builder instance
*/
@ConfiguredOption(key = "should-prestart", value = "true")
public Builder prestart(boolean prestart) {
this.prestart = prestart;
return this;
Expand Down Expand Up @@ -433,6 +445,7 @@ private void warnExperimental(String key) {
* @return updated builder instance
* @see #virtualIfAvailable(boolean)
*/
@ConfiguredOption(value = "false", experimental = true)
public Builder virtualEnforced(boolean enforceVirtualThreads) {
this.virtualThreadsEnforced = enforceVirtualThreads;
return this;
Expand All @@ -448,6 +461,7 @@ public Builder virtualEnforced(boolean enforceVirtualThreads) {
* @param useVirtualThreads whether to use virtual threads or not, defaults to {@code false}
* @return updated builder instance
*/
@ConfiguredOption(key = "virtual-threads", value = "false", experimental = true)
public Builder virtualIfAvailable(boolean useVirtualThreads) {
this.useVirtualThreads = useVirtualThreads;
return this;
Expand Down
2 changes: 2 additions & 0 deletions common/configurable/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
requires transitive io.helidon.config;
requires io.helidon.common;
requires io.helidon.common.context;
requires static io.helidon.config.metadata;

exports io.helidon.common.configurable;
}
12 changes: 12 additions & 0 deletions common/key-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-configurable</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata-processor</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.bundles</groupId>
<artifactId>helidon-bundles-config</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import java.security.spec.KeySpec;
import java.security.spec.RSAPrivateCrtKeySpec;

import sun.security.util.DerInputStream;
import sun.security.util.DerValue;

final class DerUtils {
private DerUtils() {
}
Expand All @@ -43,8 +40,9 @@ static void checkEnabled() {

static KeySpec pkcs1RsaKeySpec(byte[] bytes) {
try {
DerInputStream derReader = new DerInputStream(bytes);
DerValue[] seq = derReader.getSequence(0);
// fully qualified class names allow us to compile this without failure
sun.security.util.DerInputStream derReader = new sun.security.util.DerInputStream(bytes);
sun.security.util.DerValue[] seq = derReader.getSequence(0);
// skip version seq[0];
BigInteger modulus = seq[1].getBigInteger();
BigInteger publicExp = seq[2].getBigInteger();
Expand Down
Loading