Search in sources :

Example 1 with GeneratedResourceBuildItem

use of io.quarkus.deployment.builditem.GeneratedResourceBuildItem in project keycloak by keycloak.

the class KeycloakProcessor method persistBuildTimeProperties.

/**
 * <p>Make the build time configuration available at runtime so that the server can run without having to specify some of
 * the properties again.
 */
@BuildStep(onlyIf = IsReAugmentation.class)
void persistBuildTimeProperties(BuildProducer<GeneratedResourceBuildItem> resources) {
    Properties properties = new Properties();
    for (String name : getPropertyNames()) {
        PropertyMapper mapper = PropertyMappers.getMapper(name);
        ConfigValue value = null;
        if (mapper == null) {
            if (name.startsWith(NS_QUARKUS)) {
                value = Configuration.getConfigValue(name);
                if (!QuarkusPropertiesConfigSource.isSameSource(value)) {
                    continue;
                }
            }
        } else if (mapper.isBuildTime()) {
            name = mapper.getFrom();
            value = Configuration.getConfigValue(name);
        }
        if (value != null && value.getValue() != null) {
            properties.put(name, value.getValue());
        }
    }
    for (File jar : getProviderFiles().values()) {
        properties.put(String.format("kc.provider.file.%s.last-modified", jar.getName()), String.valueOf(jar.lastModified()));
    }
    String profile = Environment.getProfile();
    if (profile != null) {
        properties.put(Environment.PROFILE, profile);
        properties.put(ProfileManager.QUARKUS_PROFILE_PROP, profile);
    }
    properties.put(QUARKUS_PROPERTY_ENABLED, String.valueOf(QuarkusPropertiesConfigSource.getConfigurationFile() != null));
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        properties.store(outputStream, " Auto-generated, DO NOT change this file");
        resources.produce(new GeneratedResourceBuildItem(PersistedConfigSource.PERSISTED_PROPERTIES, outputStream.toByteArray()));
    } catch (Exception cause) {
        throw new RuntimeException("Failed to persist configuration", cause);
    }
}
Also used : ConfigValue(io.smallrye.config.ConfigValue) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) File(java.io.File) JarFile(java.util.jar.JarFile) IOException(java.io.IOException) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)1 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)1 ConfigValue (io.smallrye.config.ConfigValue)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1 PropertyMapper (org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)1