Merge pull request #6086 from seakider/impro_quarkus_try_resource

Improvement - quarkus should make an attempt to read config file using Thread's ContextClassLoader
pull/6089/head
Nikita Koksharov 6 months ago committed by GitHub
commit 5ec516a0d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -34,7 +34,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -57,27 +57,24 @@ public class RedissonClientProducer {
@Singleton @Singleton
@DefaultBean @DefaultBean
public RedissonClient create() throws IOException { public RedissonClient create() throws IOException {
InputStream configStream; String config = null;
Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class); Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class);
if (configFile.isPresent()) { String configFileName = configFile.orElse("redisson.yaml");
configStream = getClass().getResourceAsStream(configFile.get()); try (InputStream configStream = Optional.ofNullable(getClass().getResourceAsStream(configFileName))
if (configStream == null) { .orElse(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFileName))
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile.get()); ) {
if (configStream != null) {
byte[] array = new byte[configStream.available()];
if (configStream.read(array) != -1) {
config = new String(array, StandardCharsets.UTF_8);
}
} }
} else {
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml");
} }
String config; if (config == null) {
if (configStream != null) {
byte[] array = new byte[configStream.available()];
configStream.read(array);
config = new String(array, StandardCharsets.UTF_8);
} else {
Stream<String> s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false); Stream<String> s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false);
String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { config = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> {
return ConfigProvider.getConfig().getValue(prop, String.class); return ConfigProvider.getConfig().getValue(prop, String.class);
}, false); }, false);
config = yaml;
} }
ConfigSupport support = new ConfigSupport() { ConfigSupport support = new ConfigSupport() {

@ -57,27 +57,24 @@ public class RedissonClientProducer {
@Singleton @Singleton
@DefaultBean @DefaultBean
public RedissonClient create() throws IOException { public RedissonClient create() throws IOException {
InputStream configStream; String config = null;
Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class); Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class);
if (configFile.isPresent()) { String configFileName = configFile.orElse("redisson.yaml");
configStream = getClass().getResourceAsStream(configFile.get()); try (InputStream configStream = Optional.ofNullable(getClass().getResourceAsStream(configFileName))
if (configStream == null) { .orElse(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFileName))
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile.get()); ) {
if (configStream != null) {
byte[] array = new byte[configStream.available()];
if (configStream.read(array) != -1) {
config = new String(array, StandardCharsets.UTF_8);
}
} }
} else {
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml");
} }
String config; if (config == null) {
if (configStream != null) {
byte[] array = new byte[configStream.available()];
configStream.read(array);
config = new String(array, StandardCharsets.UTF_8);
} else {
Stream<String> s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false); Stream<String> s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false);
String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { config = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> {
return ConfigProvider.getConfig().getValue(prop, String.class); return ConfigProvider.getConfig().getValue(prop, String.class);
}, false); }, false);
config = yaml;
} }
ConfigSupport support = new ConfigSupport() { ConfigSupport support = new ConfigSupport() {

@ -57,27 +57,24 @@ public class RedissonClientProducer {
@Singleton @Singleton
@DefaultBean @DefaultBean
public RedissonClient create() throws IOException { public RedissonClient create() throws IOException {
InputStream configStream; String config = null;
Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class); Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class);
if (configFile.isPresent()) { String configFileName = configFile.orElse("redisson.yaml");
configStream = getClass().getResourceAsStream(configFile.get()); try (InputStream configStream = Optional.ofNullable(getClass().getResourceAsStream(configFileName))
if (configStream == null) { .orElse(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFileName))
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile.get()); ) {
if (configStream != null) {
byte[] array = new byte[configStream.available()];
if (configStream.read(array) != -1) {
config = new String(array, StandardCharsets.UTF_8);
}
} }
} else {
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml");
} }
String config; if (config == null) {
if (configStream != null) {
byte[] array = new byte[configStream.available()];
configStream.read(array);
config = new String(array, StandardCharsets.UTF_8);
} else {
Stream<String> s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false); Stream<String> s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false);
String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { config = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> {
return ConfigProvider.getConfig().getValue(prop, String.class); return ConfigProvider.getConfig().getValue(prop, String.class);
}, false); }, false);
config = yaml;
} }
ConfigSupport support = new ConfigSupport() { ConfigSupport support = new ConfigSupport() {

Loading…
Cancel
Save