Search in sources :

Example 11 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class CLusteringBuildSteps method configureInfinispan.

@Consume(KeycloakSessionFactoryPreInitBuildItem.class)
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
void configureInfinispan(KeycloakRecorder recorder, BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItems, ShutdownContextBuildItem shutdownContext) {
    String configFile = getConfigValue("kc.spi-connections-infinispan-quarkus-config-file").getValue();
    if (configFile != null) {
        Path configPath = Paths.get(configFile);
        String path;
        if (configPath.toFile().exists()) {
            path = configPath.toFile().getAbsolutePath();
        } else {
            path = configPath.getFileName().toString();
        }
        InputStream url = FileLookupFactory.newInstance().lookupFile(path, KeycloakProcessor.class.getClassLoader());
        if (url == null) {
            throw new IllegalArgumentException("Could not load cluster configuration file at [" + configPath + "]");
        }
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(url))) {
            String config = reader.lines().collect(Collectors.joining("\n"));
            syntheticBeanBuildItems.produce(SyntheticBeanBuildItem.configure(CacheManagerFactory.class).scope(ApplicationScoped.class).unremovable().setRuntimeInit().runtimeValue(recorder.createCacheInitializer(config, shutdownContext)).done());
        } catch (Exception cause) {
            throw new RuntimeException("Failed to read clustering configuration from [" + url + "]", cause);
        }
    } else {
        throw new IllegalArgumentException("Option 'configFile' needs to be specified");
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Consume(io.quarkus.deployment.annotations.Consume) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)11 Record (io.quarkus.deployment.annotations.Record)4 JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)2 Consume (io.quarkus.deployment.annotations.Consume)2 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)2 HotDeploymentWatchedFileBuildItem (io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem)2 IndexDependencyBuildItem (io.quarkus.deployment.builditem.IndexDependencyBuildItem)2 StaticInitConfigSourceProviderBuildItem (io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem)2 ResteasyDeploymentCustomizerBuildItem (io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentCustomizerBuildItem)2 LaunchMode (io.quarkus.runtime.LaunchMode)2 SmallRyeHealthHandler (io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler)2 FilterBuildItem (io.quarkus.vertx.http.deployment.FilterBuildItem)2 ConfigValue (io.smallrye.config.ConfigValue)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)2