Rework build steps in KeycloakProcessor
Signed-off-by: vramik <vramik@redhat.com> Closes #24099
This commit is contained in:
parent
926be135e8
commit
6d7a99dc6f
4 changed files with 19 additions and 125 deletions
|
@ -45,7 +45,7 @@ public class CacheBuildSteps {
|
|||
|
||||
@Consume(KeycloakSessionFactoryPreInitBuildItem.class)
|
||||
@Record(ExecutionTime.RUNTIME_INIT)
|
||||
@BuildStep(onlyIf = IsLegacyStoreEnabled.class)
|
||||
@BuildStep
|
||||
void configureInfinispan(KeycloakRecorder recorder, BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItems, ShutdownContextBuildItem shutdownContext) {
|
||||
String configFile = getConfigValue("kc.spi-connections-infinispan-quarkus-config-file").getValue();
|
||||
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright 2022 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.deployment;
|
||||
|
||||
import static org.keycloak.config.StorageOptions.STORAGE;
|
||||
import static org.keycloak.quarkus.runtime.configuration.Configuration.getOptionalValue;
|
||||
import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import org.keycloak.config.StorageOptions;
|
||||
|
||||
/***
|
||||
* Checks if JPA is enabled either for the legacy or the new store.
|
||||
*
|
||||
* Returns true if the legacy store is used or the new store is used with storage==jpa
|
||||
*/
|
||||
public class IsJpaStoreEnabled implements BooleanSupplier {
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
Optional<String> storage = getOptionalValue(NS_KEYCLOAK_PREFIX.concat(STORAGE.getKey()));
|
||||
|
||||
if (storage.isEmpty()) {
|
||||
// legacy store
|
||||
return true;
|
||||
}
|
||||
|
||||
return StorageOptions.StorageType.jpa.name().equals(storage.orElse(null));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright 2022 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.deployment;
|
||||
|
||||
import static org.keycloak.config.StorageOptions.STORAGE;
|
||||
import static org.keycloak.quarkus.runtime.configuration.Configuration.getOptionalValue;
|
||||
import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
* Checks if the legacy store is enabled. returns true if no storage=... is set. Returns false otherwise.
|
||||
*/
|
||||
public class IsLegacyStoreEnabled implements BooleanSupplier {
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return getOptionalValue(NS_KEYCLOAK_PREFIX.concat(STORAGE.getKey())).isEmpty();
|
||||
}
|
||||
|
||||
}
|
|
@ -68,7 +68,6 @@ import org.keycloak.common.crypto.FipsMode;
|
|||
import org.keycloak.common.util.StreamUtil;
|
||||
import org.keycloak.config.DatabaseOptions;
|
||||
import org.keycloak.config.SecurityOptions;
|
||||
import org.keycloak.config.StorageOptions;
|
||||
import org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory;
|
||||
import org.keycloak.connections.jpa.JpaConnectionProvider;
|
||||
import org.keycloak.connections.jpa.JpaConnectionSpi;
|
||||
|
@ -236,7 +235,7 @@ class KeycloakProcessor {
|
|||
*
|
||||
* @param ignore used for changing build items execution order with regards to AgroalProcessor
|
||||
*/
|
||||
@BuildStep(onlyIf = IsJpaStoreEnabled.class)
|
||||
@BuildStep
|
||||
@Produce(CheckJdbcBuildStep.class)
|
||||
void checkJdbcDriver(BuildProducer<JdbcDriverBuildItem> ignore) {
|
||||
final Optional<String> dbDriver = Configuration.getOptionalValue("quarkus.datasource.jdbc.driver");
|
||||
|
@ -256,8 +255,7 @@ class KeycloakProcessor {
|
|||
/**
|
||||
* <p>Configures the persistence unit for Quarkus.
|
||||
*
|
||||
* <p>The main reason we have this build step is because we re-use the same persistence unit from {@code keycloak-model-jpa}
|
||||
* module, the same used by the Wildfly distribution. The {@code hibernate-orm} extension expects that the dialect is statically
|
||||
* <p>The {@code hibernate-orm} extension expects that the dialect is statically
|
||||
* set to the persistence unit if there is any from the classpath and we use this method to obtain the dialect from the configuration
|
||||
* file so that we can build the application with whatever dialect we want. In addition to the dialect, we should also be
|
||||
* allowed to set any additional defaults that we think that makes sense.
|
||||
|
@ -265,7 +263,7 @@ class KeycloakProcessor {
|
|||
* @param config
|
||||
* @param descriptors
|
||||
*/
|
||||
@BuildStep(onlyIf = {IsJpaStoreEnabled.class})
|
||||
@BuildStep
|
||||
@Record(ExecutionTime.RUNTIME_INIT)
|
||||
void configurePersistenceUnits(HibernateOrmConfig config,
|
||||
List<PersistenceXmlDescriptorBuildItem> descriptors,
|
||||
|
@ -301,20 +299,11 @@ class KeycloakProcessor {
|
|||
configureDefaultPersistenceUnitEntities(defaultUnitDescriptor, indexBuildItem, userManagedEntities);
|
||||
}
|
||||
|
||||
@BuildStep(onlyIf = IsJpaStoreEnabled.class)
|
||||
@BuildStep
|
||||
@Consume(CheckJdbcBuildStep.class)
|
||||
void produceDefaultPersistenceUnit(BuildProducer<PersistenceXmlDescriptorBuildItem> producer) {
|
||||
String storage = Configuration.getRawValue(
|
||||
NS_KEYCLOAK_PREFIX.concat(StorageOptions.STORAGE.getKey()));
|
||||
ParsedPersistenceXmlDescriptor descriptor;
|
||||
|
||||
if (storage == null) {
|
||||
descriptor = PersistenceXmlParser.locateIndividualPersistenceUnit(
|
||||
ParsedPersistenceXmlDescriptor descriptor = PersistenceXmlParser.locateIndividualPersistenceUnit(
|
||||
Thread.currentThread().getContextClassLoader().getResource("default-persistence.xml"));
|
||||
} else {
|
||||
descriptor = PersistenceXmlParser.locateIndividualPersistenceUnit(
|
||||
Thread.currentThread().getContextClassLoader().getResource("default-map-jpa-persistence.xml"));
|
||||
}
|
||||
|
||||
producer.produce(new PersistenceXmlDescriptorBuildItem(descriptor));
|
||||
}
|
||||
|
@ -336,9 +325,6 @@ class KeycloakProcessor {
|
|||
unitProperties.setProperty(AvailableSettings.JAKARTA_TRANSACTION_TYPE, PersistenceUnitTransactionType.JTA.name());
|
||||
descriptor.setTransactionType(PersistenceUnitTransactionType.JTA);
|
||||
|
||||
final Optional<String> lockTimeoutConfigValue = getOptionalValue("spi-map-storage-jpa-lock-timeout");
|
||||
lockTimeoutConfigValue.ifPresent(v -> unitProperties.setProperty(AvailableSettings.JAKARTA_LOCK_TIMEOUT, v));
|
||||
|
||||
unitProperties.setProperty(AvailableSettings.QUERY_STARTUP_CHECKING, Boolean.FALSE.toString());
|
||||
|
||||
String dbKind = defaultDataSource.getDbKind();
|
||||
|
@ -431,7 +417,7 @@ class KeycloakProcessor {
|
|||
// make sure theme resources are loaded using a flat classpath. if no resources are available the provider is not registered
|
||||
factories.computeIfAbsent(spi, key -> new HashMap<>()).computeIfAbsent(spi.getProviderClass(), aClass -> new HashMap<>()).put(FlatClasspathThemeResourceProviderFactory.ID, FlatClasspathThemeResourceProviderFactory.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to install default theme resource provider", e);
|
||||
}
|
||||
}
|
||||
|
@ -442,16 +428,13 @@ class KeycloakProcessor {
|
|||
descriptors.stream()
|
||||
.map(PersistenceXmlDescriptorBuildItem::getDescriptor)
|
||||
.map(ParsedPersistenceXmlDescriptor::getName)
|
||||
.filter(Predicate.not("keycloak-default"::equals)).forEach(new Consumer<String>() {
|
||||
@Override
|
||||
public void accept(String unitName) {
|
||||
.filter(Predicate.not("keycloak-default"::equals)).forEach((String unitName) -> {
|
||||
NamedJpaConnectionProviderFactory factory = new NamedJpaConnectionProviderFactory();
|
||||
|
||||
factory.setUnitName(unitName);
|
||||
|
||||
factories.get(spi).get(JpaConnectionProvider.class).put(unitName, NamedJpaConnectionProviderFactory.class);
|
||||
preConfiguredProviders.put(unitName, factory);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -579,15 +562,9 @@ class KeycloakProcessor {
|
|||
indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-services"));
|
||||
}
|
||||
|
||||
@BuildStep(onlyIf = IsJpaStoreEnabled.class, onlyIfNot = IsLegacyStoreEnabled.class)
|
||||
@BuildStep
|
||||
@Consume(CheckJdbcBuildStep.class)
|
||||
void indexNewJpaStore(BuildProducer<IndexDependencyBuildItem> indexDependencyBuildItemBuildProducer) {
|
||||
indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-model-map-jpa"));
|
||||
}
|
||||
|
||||
@BuildStep(onlyIf = IsLegacyStoreEnabled.class)
|
||||
@Consume(CheckJdbcBuildStep.class)
|
||||
void indexLegacyJpaStore(BuildProducer<IndexDependencyBuildItem> indexDependencyBuildItemBuildProducer) {
|
||||
void indexJpaStore(BuildProducer<IndexDependencyBuildItem> indexDependencyBuildItemBuildProducer) {
|
||||
indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-model-jpa"));
|
||||
}
|
||||
|
||||
|
@ -816,8 +793,8 @@ class KeycloakProcessor {
|
|||
if (!scope.getBoolean("enabled", true)) {
|
||||
return false;
|
||||
}
|
||||
if (factory instanceof EnvironmentDependentProviderFactory) {
|
||||
return ((EnvironmentDependentProviderFactory) factory).isSupported(scope);
|
||||
if (factory instanceof EnvironmentDependentProviderFactory environmentDependentProviderFactory) {
|
||||
return environmentDependentProviderFactory.isSupported(scope);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue