Java Code Examples for io.quarkus.runtime.annotations.ConfigPhase#RUN_TIME

The following examples show how to use io.quarkus.runtime.annotations.ConfigPhase#RUN_TIME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigBuildStep.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
BeanRegistrarBuildItem registerConfigRootsAsBeans(ConfigurationBuildItem configItem) {
    return new BeanRegistrarBuildItem(new BeanRegistrar() {
        @Override
        public void register(RegistrationContext context) {
            for (RootDefinition rootDefinition : configItem.getReadResult().getAllRoots()) {
                if (rootDefinition.getConfigPhase() == ConfigPhase.BUILD_AND_RUN_TIME_FIXED
                        || rootDefinition.getConfigPhase() == ConfigPhase.RUN_TIME) {
                    Class<?> configRootClass = rootDefinition.getConfigurationClass();
                    context.configure(configRootClass).types(configRootClass)
                            .scope(Dependent.class).creator(mc -> {
                                // e.g. return Config.ApplicationConfig
                                ResultHandle configRoot = mc.readStaticField(rootDefinition.getDescriptor());
                                // BUILD_AND_RUN_TIME_FIXED roots are always set before the container is started (in the static initializer of the generated Config class)
                                // However, RUN_TIME roots may be not be set when the bean instance is created 
                                mc.ifNull(configRoot).trueBranch().throwException(CreationException.class,
                                        String.format("Config root [%s] with config phase [%s] not initialized yet.",
                                                configRootClass.getName(), rootDefinition.getConfigPhase().name()));
                                mc.returnValue(configRoot);
                            }).done();
                }
            }
        }
    });
}
 
Example 2
Source File: QuarkusConfigRootProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the Quarkus @ConfigRoot(phase=...) value.
 * 
 * @param configRootAnnotation
 * @return the Quarkus @ConfigRoot(phase=...) value.
 */
private static ConfigPhase getConfigPhase(PsiAnnotation configRootAnnotation) {
	String value = AnnotationUtils.getAnnotationMemberValue(configRootAnnotation, QuarkusConstants.CONFIG_ROOT_ANNOTATION_PHASE);
	if (value != null) {
		if (value.endsWith(ConfigPhase.RUN_TIME.name())) {
			return ConfigPhase.RUN_TIME;
		}
		if (value.endsWith(ConfigPhase.BUILD_AND_RUN_TIME_FIXED.name())) {
			return ConfigPhase.BUILD_AND_RUN_TIME_FIXED;
		}
	}
	return ConfigPhase.BUILD_TIME;
}
 
Example 3
Source File: QuarkusConfigRootProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the Quarkus extension name according the
 * <code>configRootClassSimpleName</code>, <code>configRootAnnotationName</code>
 * and <code>configPhase</code>.
 * 
 * @param configRootClassSimpleName the simple class name where ConfigRoot is
 *                                  declared.
 * @param configRootAnnotationName  the name declared in the ConfigRoot
 *                                  annotation.
 * @param configPhase               the config phase.
 * @see <a href="https://github.com/quarkusio/quarkus/blob/master/core/deployment/src/main/java/io/quarkus/deployment/configuration/ConfigDefinition.java#L173">
 *      (registerConfigRoot)</a>
 * @return the Quarkus extension name according the
 *         <code>configRootClassSimpleName</code>,
 *         <code>configRootAnnotationName</code> and <code>configPhase</code>.
 */
private static String getExtensionName(String configRootClassSimpleName, String configRootAnnotationName,
		ConfigPhase configPhase) {
	// See
	// https://github.com/quarkusio/quarkus/blob/master/core/deployment/src/main/java/io/quarkus/deployment/configuration/ConfigDefinition.java#L173
	// registerConfigRoot
	String rootName = configRootAnnotationName;
	final List<String> segments = toList(camelHumpsIterator(configRootClassSimpleName));
	final List<String> trimmedSegments;
	if (configPhase == ConfigPhase.RUN_TIME) {
		trimmedSegments = withoutSuffix(
				withoutSuffix(
						withoutSuffix(
								withoutSuffix(withoutSuffix(withoutSuffix(segments, "Runtime", "Configuration"),
										"Runtime", "Config"), "Run", "Time", "Configuration"),
								"Run", "Time", "Config"),
						"Configuration"),
				"Config");
	} else if (configPhase == ConfigPhase.BOOTSTRAP) {
		trimmedSegments = withoutSuffix(withoutSuffix(
				withoutSuffix(withoutSuffix(segments, "Bootstrap", "Configuration"), "Bootstrap", "Config"),
				"Configuration"), "Config");
	} else {
		trimmedSegments = withoutSuffix(withoutSuffix(
				withoutSuffix(withoutSuffix(segments, "Build", "Time", "Configuration"), "Build", "Time", "Config"),
				"Configuration"), "Config");
	}
	if (rootName.equals(ConfigItem.PARENT)) {
		rootName = "";
	} else if (rootName.equals(ConfigItem.ELEMENT_NAME)) {
		rootName = String.join("", (Iterable<String>) () -> lowerCaseFirst(trimmedSegments.iterator()));
	} else if (rootName.equals(ConfigItem.HYPHENATED_ELEMENT_NAME)) {
		rootName = String.join("-", (Iterable<String>) () -> lowerCase(trimmedSegments.iterator()));
	}
	return rootName;
}
 
Example 4
Source File: RootDefinition.java    From quarkus with Apache License 2.0 4 votes vote down vote up
RootDefinition(final Builder builder) {
    super(builder);
    this.configPhase = builder.configPhase;
    String rootName = builder.rootName;
    final Class<?> configClass = getConfigurationClass();
    final List<String> segments = toList(camelHumpsIterator(configClass.getSimpleName()));
    final List<String> trimmedSegments;
    if (configPhase == ConfigPhase.RUN_TIME) {
        trimmedSegments = withoutSuffix(
                withoutSuffix(
                        withoutSuffix(
                                withoutSuffix(
                                        withoutSuffix(
                                                withoutSuffix(
                                                        segments,
                                                        "Runtime", "Configuration"),
                                                "Runtime", "Config"),
                                        "Run", "Time", "Configuration"),
                                "Run", "Time", "Config"),
                        "Configuration"),
                "Config");
    } else if (configPhase == ConfigPhase.BOOTSTRAP) {
        trimmedSegments = withoutSuffix(
                withoutSuffix(
                        withoutSuffix(
                                withoutSuffix(
                                        segments,
                                        "Bootstrap", "Configuration"),
                                "Bootstrap", "Config"),
                        "Configuration"),
                "Config");
    } else {
        trimmedSegments = withoutSuffix(
                withoutSuffix(
                        withoutSuffix(
                                withoutSuffix(
                                        segments,
                                        "Build", "Time", "Configuration"),
                                "Build", "Time", "Config"),
                        "Configuration"),
                "Config");
    }
    if (rootName.equals(ConfigItem.PARENT)) {
        rootName = "";
    } else if (rootName.equals(ConfigItem.ELEMENT_NAME)) {
        rootName = String.join("", (Iterable<String>) () -> lowerCaseFirst(trimmedSegments.iterator()));
    } else if (rootName.equals(ConfigItem.HYPHENATED_ELEMENT_NAME)) {
        rootName = String.join("-", (Iterable<String>) () -> lowerCase(trimmedSegments.iterator()));
    }
    this.rootName = rootName;
    this.descriptor = FieldDescriptor.of(CONFIG_CLASS_NAME, String.join("", segments), Object.class);
}