Skip to content

Commit

Permalink
fix config-related cleanups quarkusio#5388
Browse files Browse the repository at this point in the history
  • Loading branch information
Simulant87 committed Jan 18, 2020
1 parent fd73233 commit 3cbd4e4
Show file tree
Hide file tree
Showing 38 changed files with 156 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ static class JniConfig {
/**
* Enable JNI support.
*/
@ConfigItem(defaultValue = "false")
boolean enable = false;
@ConfigItem
boolean enable;
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ public class NativeConfig {
/**
* If the HTTPS url handler should be enabled, allowing you to do URL.openConnection() for HTTPS URLs
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean enableHttpsUrlHandler;

/**
* If all security services should be added to the native image
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean enableAllSecurityServices;

/**
* If JNI should be enabled
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean enableJni;

/**
* If all character sets should be added to the native image. This increases image size
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean addAllCharsets;

/**
Expand All @@ -68,14 +68,14 @@ public class NativeConfig {
/**
* If debug symbols should be included
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean debugSymbols;

/**
* If the native image build should wait for a debugger to be attached before running. This is an advanced option
* and is generally only intended for those familiar with Substrate internals
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean debugBuildProcess;

/**
Expand All @@ -87,7 +87,7 @@ public class NativeConfig {
/**
* If the native image server should be restarted
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean cleanupServer;

/**
Expand All @@ -100,33 +100,33 @@ public class NativeConfig {
* If a JVM based 'fallback image' should be created if native image fails. This is not recommended, as this is
* functionally the same as just running the application in a JVM
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean enableFallbackImages;

/**
* If the native image server should be used. This can speed up compilation but can result in changes not always
* being picked up due to cache invalidation not working 100%
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean enableServer;

/**
* If all META-INF/services entries should be automatically registered
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean autoServiceLoaderRegistration;

/**
* If the bytecode of all proxies should be dumped for inspection
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean dumpProxies;

/**
* If this build should be done using a container runtime. If this is set docker will be used by default,
* unless container-runtime is also set.
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean containerBuild;

/**
Expand All @@ -151,7 +151,7 @@ public class NativeConfig {
/**
* If the resulting image should allow VM introspection
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean enableVmInspection;

/**
Expand All @@ -163,7 +163,7 @@ public class NativeConfig {
/**
* If reporting on call paths should be enabled
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean enableReports;

/**
Expand All @@ -176,6 +176,6 @@ public class NativeConfig {
* If errors should be reported at runtime. This is a more relaxed setting, however it is not recommended as it means
* your application may fail at runtime if an unsupported feature is used by accident.
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean reportErrorsAtRuntime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PackageConfig {
/**
* If the java runner should be packed as an uberjar
*/
@ConfigItem(defaultValue = "false")
@ConfigItem
public boolean uberJar;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ThreadPoolConfig {
* threads beyond the core size should be created as aggressively as threads within it; a value of {@code 1.0f}
* implies that threads beyond the core size should never be created.
*/
@ConfigItem(defaultValue = "0")
@ConfigItem
public float growthResistance;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ConsoleConfig {
* Note that this value will be ignored if an extension is present that takes
* control of console formatting (e.g. an XML or JSON-format extension).
*/
@ConfigItem(defaultValue = "0")
@ConfigItem
int darken;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ void checkConfig() {
throw new IllegalStateException(
"buildTimeConfig.optLongValue != 1234567893L; " + buildTimeConfig.allValues.optLongValue.getAsLong());
}
if (buildTimeConfig.allValues.optionalLongValue.get() != 1234567894L) {
if (buildTimeConfig.allValues.optionalLongValue.getAsLong() != 1234567894L) {
throw new IllegalStateException("buildTimeConfig.allValues.optionalLongValue != 1234567894L; "
+ buildTimeConfig.allValues.optionalLongValue.get());
+ buildTimeConfig.allValues.optionalLongValue.getAsLong());
}
if (buildTimeConfig.allValues.nestedConfigMap.size() != 2) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public void validateBuildTimeConfig() {
throw new IllegalStateException(
"buildTimeConfig.optLongValue != 1234567893L; " + buildTimeConfig.allValues.optLongValue.getAsLong());
}
if (buildTimeConfig.allValues.optionalLongValue.get() != 1234567894L) {
if (buildTimeConfig.allValues.optionalLongValue.getAsLong() != 1234567894L) {
throw new IllegalStateException("buildTimeConfig.allValues.optionalLongValue != 1234567894L; "
+ buildTimeConfig.allValues.optionalLongValue.get());
+ buildTimeConfig.allValues.optionalLongValue.getAsLong());
}
if (buildTimeConfig.allValues.nestedConfigMap.size() != 2) {
throw new IllegalStateException(
Expand Down Expand Up @@ -141,17 +141,17 @@ public void validateRuntimeConfig() {
//quarkus.rt.all-values.ovo=configPart1+configPart2
Assertions.assertEquals(new ObjectValueOf("configPart1", "configPart2"), runTimeConfig.allValues.ovo);
// quarkus.rt.all-values.long-primitive=12345678911
Assertions.assertEquals(12345678911l, runTimeConfig.allValues.longPrimitive);
Assertions.assertEquals(12345678911L, runTimeConfig.allValues.longPrimitive);
// quarkus.rt.all-values.long-value=12345678921
Assertions.assertEquals(12345678921l, runTimeConfig.allValues.longValue.longValue());
Assertions.assertEquals(12345678921L, runTimeConfig.allValues.longValue.longValue());
// quarkus.rt.all-values.opt-long-value=12345678931
Assertions.assertTrue(runTimeConfig.allValues.optLongValue.isPresent(),
"runTimeConfig.allValues.optLongValue.isPresent");
Assertions.assertEquals(12345678931l, runTimeConfig.allValues.optLongValue.getAsLong());
Assertions.assertEquals(12345678931L, runTimeConfig.allValues.optLongValue.getAsLong());
// quarkus.rt.all-values.optional-long-value=12345678941
Assertions.assertTrue(runTimeConfig.allValues.optionalLongValue.isPresent(),
"runTimeConfig.allValues.optionalLongValue.isPresent");
Assertions.assertEquals(12345678941l, runTimeConfig.allValues.optionalLongValue.get().longValue());
Assertions.assertEquals(12345678941L, runTimeConfig.allValues.optionalLongValue.getAsLong());
// quarkus.btrt.all-values.double-primitive=3.1415926535897932384
Assertions.assertEquals(3.1415926535897932384, runTimeConfig.allValues.doublePrimitive, 0.00000001);
// quarkus.btrt.all-values.opt-double-value=3.1415926535897932384
Expand Down Expand Up @@ -228,7 +228,7 @@ public void testRuntimeXmlConfigService() throws Exception {
// From config.xml
Socket socket = new Socket("localhost", 12345);
OutputStream os = socket.getOutputStream();
os.write("testRuntimeXmlConfigService\n".getBytes("UTF-8"));
os.write("testRuntimeXmlConfigService\n".getBytes(StandardCharsets.UTF_8));
os.flush();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalLong;

Expand Down Expand Up @@ -30,7 +29,7 @@ public class AllValuesConfig {
public OptionalDouble optDoubleValue;
/** an optional long value */
@ConfigItem
public Optional<Long> optionalLongValue;
public OptionalLong optionalLongValue;
/** A config object with a static of(String) method */
@ConfigItem
public ObjectOfValue oov;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public AgroalDataSource createDataSource(String dataSourceName,
// Pool size configuration:
poolConfiguration.minSize(dataSourceRuntimeConfig.minSize);
poolConfiguration.maxSize(dataSourceRuntimeConfig.maxSize);
if (dataSourceRuntimeConfig.initialSize.isPresent() && dataSourceRuntimeConfig.initialSize.get() > 0) {
poolConfiguration.initialSize(dataSourceRuntimeConfig.initialSize.get());
if (dataSourceRuntimeConfig.initialSize.isPresent() && dataSourceRuntimeConfig.initialSize.getAsInt() > 0) {
poolConfiguration.initialSize(dataSourceRuntimeConfig.initialSize.getAsInt());
}

// Connection management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.Duration;
import java.util.Optional;
import java.util.OptionalInt;

import io.agroal.api.configuration.AgroalConnectionFactoryConfiguration;
import io.quarkus.runtime.annotations.ConfigGroup;
Expand Down Expand Up @@ -51,12 +52,12 @@ public class DataSourceRuntimeConfig {
* of the connections on boot, while being able to sustain a minimal pool size after boot.
*/
@ConfigItem
public Optional<Integer> initialSize;
public OptionalInt initialSize;

/**
* The datasource pool minimum size
*/
@ConfigItem(defaultValue = "0")
@ConfigItem
public int minSize;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private void validateNettyClientConfig(NettyHttpClientConfig asyncClient) {
"quarkus.dynamodb.async-client.max-pending-connection-acquires may not be negative or zero.");
}
if (asyncClient.eventLoop.override) {
if (asyncClient.eventLoop.numberOfThreads.isPresent() && asyncClient.eventLoop.numberOfThreads.get() <= 0) {
if (asyncClient.eventLoop.numberOfThreads.isPresent() && asyncClient.eventLoop.numberOfThreads.getAsInt() <= 0) {
throw new RuntimeConfigurationError(
"quarkus.dynamodb.async-client.event-loop.number-of-threads may not be negative or zero.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;

import io.netty.handler.ssl.SslProvider;
import io.quarkus.runtime.annotations.ConfigGroup;
Expand Down Expand Up @@ -94,7 +95,7 @@ public class NettyHttpClientConfig {
* <p>
* 0 means unlimited.
*/
@ConfigItem(defaultValue = "0")
@ConfigItem
public int maxHttp2Streams;

/**
Expand Down Expand Up @@ -139,7 +140,7 @@ public static class SdkEventLoopGroupConfig {
* `io.netty.eventLoopThreads` system property is set.
*/
@ConfigItem
public Optional<Integer> numberOfThreads;
public OptionalInt numberOfThreads;

/**
* The thread name prefix for threads created by this thread factory used by event loop group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -146,10 +139,10 @@ private Collection<String> getMigrationLocations(DataSourceInitializedBuildItem
Collection<String> dataSourceNames = DataSourceInitializedBuildItem.dataSourceNamesOf(dataSourceInitializedBuildItem);
Collection<String> migrationLocations = dataSourceNames.stream()
.map(flywayBuildConfig::getConfigForDataSourceName)
.flatMap(config -> config.locations.stream())
.flatMap(config -> Stream.of(config.locations.get()))
.collect(Collectors.toCollection(LinkedHashSet::new));
if (DataSourceInitializedBuildItem.isDefaultDataSourcePresent(dataSourceInitializedBuildItem)) {
migrationLocations.addAll(flywayBuildConfig.defaultDataSource.locations);
migrationLocations.addAll(Arrays.asList(flywayBuildConfig.defaultDataSource.locations.get()));
}
return migrationLocations;
}
Expand All @@ -162,7 +155,7 @@ private List<String> discoverApplicationMigrations(Collection<String> locations)
for (String location : locations) {
// Strip any 'classpath:' protocol prefixes because they are assumed
// but not recognized by ClassLoader.getResources()
if (location != null && location.startsWith(CLASSPATH_APPLICATION_MIGRATIONS_PROTOCOL + ':')) {
if (location.startsWith(CLASSPATH_APPLICATION_MIGRATIONS_PROTOCOL + ':')) {
location = location.substring(CLASSPATH_APPLICATION_MIGRATIONS_PROTOCOL.length() + 1);
}
Enumeration<URL> migrations = Thread.currentThread().getContextClassLoader().getResources(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

class FlywayCreator {

private static final String[] EMPTY_ARRAY = new String[0];

private final FlywayDataSourceRuntimeConfig flywayRuntimeConfig;
private final FlywayDataSourceBuildTimeConfig flywayBuildTimeConfig;

Expand All @@ -21,16 +19,32 @@ public FlywayCreator(FlywayDataSourceRuntimeConfig flywayRuntimeConfig,
public Flyway createFlyway(DataSource dataSource) {
FluentConfiguration configure = Flyway.configure();
configure.dataSource(dataSource);
flywayRuntimeConfig.connectRetries.ifPresent(configure::connectRetries);
flywayRuntimeConfig.schemas.ifPresent(list -> configure.schemas(list.toArray(EMPTY_ARRAY)));
flywayRuntimeConfig.table.ifPresent(configure::table);
configure.locations(flywayBuildTimeConfig.locations.toArray(EMPTY_ARRAY));
flywayRuntimeConfig.sqlMigrationPrefix.ifPresent(configure::sqlMigrationPrefix);
flywayRuntimeConfig.repeatableSqlMigrationPrefix.ifPresent(configure::repeatableSqlMigrationPrefix);
if (flywayRuntimeConfig.connectRetries.isPresent()) {
configure.connectRetries(flywayRuntimeConfig.connectRetries.getAsInt());
}
if (flywayRuntimeConfig.schemas.isPresent()) {
configure.schemas(flywayRuntimeConfig.schemas.get());
}
if (flywayRuntimeConfig.table.isPresent()) {
configure.table(flywayRuntimeConfig.table.get());
}
if (flywayBuildTimeConfig.locations.isPresent()) {
configure.locations(flywayBuildTimeConfig.locations.get());
}
if (flywayRuntimeConfig.sqlMigrationPrefix.isPresent()) {
configure.sqlMigrationPrefix(flywayRuntimeConfig.sqlMigrationPrefix.get());
}
if (flywayRuntimeConfig.repeatableSqlMigrationPrefix.isPresent()) {
configure.repeatableSqlMigrationPrefix(flywayRuntimeConfig.repeatableSqlMigrationPrefix.get());
}
if (flywayRuntimeConfig.baselineVersion.isPresent()) {
configure.baselineVersion(flywayRuntimeConfig.baselineVersion.get());
}
if (flywayRuntimeConfig.baselineDescription.isPresent()) {
configure.baselineDescription(flywayRuntimeConfig.baselineDescription.get());
}
configure.baselineOnMigrate(flywayRuntimeConfig.baselineOnMigrate);
configure.validateOnMigrate(flywayRuntimeConfig.validateOnMigrate);
flywayRuntimeConfig.baselineVersion.ifPresent(configure::baselineVersion);
flywayRuntimeConfig.baselineDescription.ifPresent(configure::baselineDescription);
return configure.load();
}
}
Loading

0 comments on commit 3cbd4e4

Please sign in to comment.