diff --git a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java index bf31b3436e..8c84ef577e 100644 --- a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java +++ b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java @@ -53,6 +53,8 @@ import java.util.jar.JarFile; import io.quarkus.agroal.spi.JdbcDataSourceBuildItem; import io.quarkus.deployment.IsDevelopment; +import io.quarkus.deployment.IsNormal; +import io.quarkus.deployment.IsTest; import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; @@ -265,11 +267,16 @@ class KeycloakProcessor { * * @param configSources */ - @BuildStep + @BuildStep(onlyIf = IsNormal.class) void configureConfigSources(BuildProducer configSources) { configSources.produce(new StaticInitConfigSourceProviderBuildItem(KeycloakConfigSourceProvider.class.getName())); } + @BuildStep(onlyIf = IsTest.class) + void prepareTestEnvironment(BuildProducer configSources) { + configSources.produce(new StaticInitConfigSourceProviderBuildItem("org.keycloak.quarkus.runtime.configuration.test.TestKeycloakConfigSourceProvider")); + } + /** *

Make the build time configuration available at runtime so that the server can run without having to specify some of * the properties again. diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java index 97814d25e5..54db629362 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java @@ -18,7 +18,6 @@ package org.keycloak.quarkus.runtime.configuration; import static java.util.Arrays.asList; -import static org.keycloak.quarkus.runtime.Environment.isTestLaunchMode; import static org.keycloak.quarkus.runtime.cli.Picocli.ARG_SHORT_PREFIX; import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION_LONG; import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION_SHORT; @@ -58,16 +57,13 @@ public class ConfigArgsConfigSource extends PropertiesConfigSource { private static final ConfigArgsConfigSource INSTANCE = new ConfigArgsConfigSource(); private static List IGNORED_ARGS; - private final boolean alwaysParseArgs; - public static ConfigArgsConfigSource getInstance() { return INSTANCE; } - ConfigArgsConfigSource() { + protected ConfigArgsConfigSource() { // higher priority over default Quarkus config sources super(parseArgument(), "CliConfigSource", 500); - alwaysParseArgs = isTestLaunchMode(); } public static void setCliArgs(String[] args) { @@ -96,11 +92,6 @@ public class ConfigArgsConfigSource extends PropertiesConfigSource { @Override public String getValue(String propertyName) { Map properties = getProperties(); - - if (alwaysParseArgs) { - properties = parseArgument(); - } - String value = properties.get(propertyName); if (value != null) { diff --git a/quarkus/tests/integration/src/main/java/org/keycloak/quarkus/runtime/configuration/test/TestConfigArgsConfigSource.java b/quarkus/tests/integration/src/main/java/org/keycloak/quarkus/runtime/configuration/test/TestConfigArgsConfigSource.java new file mode 100644 index 0000000000..6c6d599eb7 --- /dev/null +++ b/quarkus/tests/integration/src/main/java/org/keycloak/quarkus/runtime/configuration/test/TestConfigArgsConfigSource.java @@ -0,0 +1,24 @@ +/* + * Copyright 2021 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.quarkus.runtime.configuration.test; + +import org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource; + +public class TestConfigArgsConfigSource extends ConfigArgsConfigSource { + +} diff --git a/quarkus/tests/integration/src/main/java/org/keycloak/quarkus/runtime/configuration/test/TestKeycloakConfigSourceProvider.java b/quarkus/tests/integration/src/main/java/org/keycloak/quarkus/runtime/configuration/test/TestKeycloakConfigSourceProvider.java new file mode 100644 index 0000000000..4153e7046b --- /dev/null +++ b/quarkus/tests/integration/src/main/java/org/keycloak/quarkus/runtime/configuration/test/TestKeycloakConfigSourceProvider.java @@ -0,0 +1,49 @@ +/* + * Copyright 2021 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.quarkus.runtime.configuration.test; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; +import org.eclipse.microprofile.config.spi.ConfigSource; +import org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource; +import org.keycloak.quarkus.runtime.configuration.KeycloakConfigSourceProvider; + +public class TestKeycloakConfigSourceProvider extends KeycloakConfigSourceProvider { + + private static final Map, Supplier> REPLACEABLE_CONFIG_SOURCES = new HashMap<>(); + + static { + REPLACEABLE_CONFIG_SOURCES.put(ConfigArgsConfigSource.class, TestConfigArgsConfigSource::new); + } + + @Override + public Iterable getConfigSources(ClassLoader forClassLoader) { + reload(); + return StreamSupport.stream(super.getConfigSources(forClassLoader).spliterator(), false) + .map(new Function() { + @Override + public ConfigSource apply(ConfigSource configSource) { + return REPLACEABLE_CONFIG_SOURCES.getOrDefault(configSource.getClass(), () -> configSource).get(); + } + }).collect(Collectors.toList()); + } +} \ No newline at end of file