WIP: use extra buildstep and configprovider for tests
This commit is contained in:
parent
6cc674a875
commit
dad5639b4e
4 changed files with 82 additions and 11 deletions
|
@ -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<StaticInitConfigSourceProviderBuildItem> configSources) {
|
||||
configSources.produce(new StaticInitConfigSourceProviderBuildItem(KeycloakConfigSourceProvider.class.getName()));
|
||||
}
|
||||
|
||||
@BuildStep(onlyIf = IsTest.class)
|
||||
void prepareTestEnvironment(BuildProducer<StaticInitConfigSourceProviderBuildItem> configSources) {
|
||||
configSources.produce(new StaticInitConfigSourceProviderBuildItem("org.keycloak.quarkus.runtime.configuration.test.TestKeycloakConfigSourceProvider"));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Make the build time configuration available at runtime so that the server can run without having to specify some of
|
||||
* the properties again.
|
||||
|
|
|
@ -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<String> 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<String, String> properties = getProperties();
|
||||
|
||||
if (alwaysParseArgs) {
|
||||
properties = parseArgument();
|
||||
}
|
||||
|
||||
String value = properties.get(propertyName);
|
||||
|
||||
if (value != null) {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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<Class<? extends ConfigSource>, Supplier<? extends ConfigSource>> REPLACEABLE_CONFIG_SOURCES = new HashMap<>();
|
||||
|
||||
static {
|
||||
REPLACEABLE_CONFIG_SOURCES.put(ConfigArgsConfigSource.class, TestConfigArgsConfigSource::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {
|
||||
reload();
|
||||
return StreamSupport.stream(super.getConfigSources(forClassLoader).spliterator(), false)
|
||||
.map(new Function<ConfigSource, ConfigSource>() {
|
||||
@Override
|
||||
public ConfigSource apply(ConfigSource configSource) {
|
||||
return REPLACEABLE_CONFIG_SOURCES.getOrDefault(configSource.getClass(), () -> configSource).get();
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue