Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Hibernate Search extension to @ConfigMapping #32276

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ final public class Constants {
public static final String ANNOTATION_CONFIG_DOC_MAP_KEY = "io.quarkus.runtime.annotations.ConfigDocMapKey";
public static final String ANNOTATION_CONFIG_DOC_SECTION = "io.quarkus.runtime.annotations.ConfigDocSection";
public static final String ANNOTATION_CONFIG_DOC_ENUM_VALUE = "io.quarkus.runtime.annotations.ConfigDocEnumValue";
public static final String ANNOTATION_CONFIG_DOC_DEFAULT = "io.quarkus.runtime.annotations.ConfigDocDefault";

public static final String ANNOTATION_CONFIG_WITH_NAME = "io.smallrye.config.WithName";
public static final String ANNOTATION_CONFIG_WITH_PARENT_NAME = "io.smallrye.config.WithParentName";
public static final String ANNOTATION_CONFIG_WITH_DEFAULT = "io.smallrye.config.WithDefault";

public static final Set<String> SUPPORTED_ANNOTATIONS_TYPES = Set.of(ANNOTATION_BUILD_STEP, ANNOTATION_CONFIG_GROUP,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.quarkus.annotation.processor.generate_doc;

import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_DEFAULT;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_ENUM_VALUE;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_MAP_KEY;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_SECTION;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_ITEM;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_DEFAULT;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_NAME;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_PARENT_NAME;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONVERT_WITH;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_DEFAULT_CONVERTER;
import static io.quarkus.annotation.processor.Constants.DOT;
Expand Down Expand Up @@ -223,14 +225,14 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r
}

// Mappings
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror
.getElementValues().entrySet()) {
Object value = entry.getValue().getValue();
if (annotationName.equals(ANNOTATION_CONFIG_WITH_NAME)) {
name = parentName + DOT + value;
} else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT)) {
defaultValue = value.toString();
}
if (annotationName.equals(ANNOTATION_CONFIG_WITH_NAME)) {
name = parentName + DOT + annotationMirror.getElementValues().values().iterator().next().getValue();
} else if (annotationName.equals(ANNOTATION_CONFIG_WITH_PARENT_NAME)) {
name = parentName;
} else if (annotationName.equals(ANNOTATION_CONFIG_DOC_DEFAULT)) {
defaultValueDoc = annotationMirror.getElementValues().values().iterator().next().getValue().toString();
} else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT)) {
defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString();
}
}

Expand All @@ -244,13 +246,9 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r
if (name == null) {
name = parentName + DOT + hyphenatedFieldName;
}

if (NO_DEFAULT.equals(defaultValue)) {
defaultValue = EMPTY;
}
if (EMPTY.equals(defaultValue)) {
defaultValue = defaultValueDoc;
}

if (isConfigGroup(type)) {
List<ConfigDocItem> groupConfigItems = readConfigGroupItems(configPhase, rootName, name, type,
Expand Down Expand Up @@ -321,10 +319,14 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r

type = simpleTypeToString(realTypeMirror);
if (isEnumType(realTypeMirror)) {
if (useHyphenateEnumValue) {
defaultValue = Arrays.stream(defaultValue.split(COMMA))
.map(defaultEnumValue -> hyphenateEnumValue(defaultEnumValue.trim()))
.collect(Collectors.joining(COMMA));
if (defaultValueDoc.isBlank()) {
if (useHyphenateEnumValue) {
defaultValue = Arrays.stream(defaultValue.split(COMMA))
.map(defaultEnumValue -> hyphenateEnumValue(defaultEnumValue.trim()))
.collect(Collectors.joining(COMMA));
}
} else {
defaultValue = defaultValueDoc;
}
acceptedValues = extractEnumValues(realTypeMirror, useHyphenateEnumValue,
clazz.getQualifiedName().toString());
Expand All @@ -333,15 +335,18 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r
}
} else {
type = simpleTypeToString(declaredType);
if (isEnumType(declaredType)) {
if (useHyphenateEnumValue) {

if (defaultValueDoc.isBlank()) {
if (isEnumType(declaredType)) {
defaultValue = hyphenateEnumValue(defaultValue);
acceptedValues = extractEnumValues(declaredType, useHyphenateEnumValue,
clazz.getQualifiedName().toString());
configDocKey.setEnum(true);
} else if (isDurationType(declaredType) && !defaultValue.isEmpty()) {
defaultValue = DocGeneratorUtil.normalizeDurationValue(defaultValue);
}
acceptedValues = extractEnumValues(declaredType, useHyphenateEnumValue,
clazz.getQualifiedName().toString());
configDocKey.setEnum(true);
} else if (isDurationType(declaredType) && !defaultValue.isEmpty()) {
defaultValue = DocGeneratorUtil.normalizeDurationValue(defaultValue);
} else {
defaultValue = defaultValueDoc;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.runtime.annotations;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import io.smallrye.config.ConfigMapping;

/**
* Specifies a default value for the documentation.
* <p>
* Replaces defaultValueForDocumentation for the {@link ConfigMapping} approach.
*/
@Documented
@Retention(SOURCE)
@Target({ FIELD, PARAMETER, METHOD })
public @interface ConfigDocDefault {

String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private boolean isUsingOutboxPolling(HibernateSearchElasticsearchPersistenceUnit
if (puConfig == null) {
return false;
}
Optional<String> configuredStrategy = puConfig.coordination.strategy;
Optional<String> configuredStrategy = puConfig.coordination().strategy();
return configuredStrategy.isPresent()
&& configuredStrategy.get().equals(HibernateOrmMapperOutboxPollingSettings.COORDINATION_STRATEGY_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener(
HibernateSearchOutboxPollingRuntimeConfig runtimeConfig, String persistenceUnitName) {
HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit puConfig = PersistenceUnitUtil
.isDefaultPersistenceUnit(persistenceUnitName)
? runtimeConfig.defaultPersistenceUnit
: runtimeConfig.persistenceUnits.get(persistenceUnitName);
? runtimeConfig.defaultPersistenceUnit()
: runtimeConfig.persistenceUnits().get(persistenceUnitName);
return new RuntimeInitListener(puConfig);
}

Expand All @@ -40,9 +40,9 @@ public void contributeRuntimeProperties(BiConsumer<String, Object> propertyColle
return;
}

contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination.defaults);
contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination().defaults());

for (Entry<String, AgentsConfig> tenantEntry : runtimeConfig.coordination.tenants.entrySet()) {
for (Entry<String, AgentsConfig> tenantEntry : runtimeConfig.coordination().tenants().entrySet()) {
contributeCoordinationRuntimeProperties(propertyCollector, tenantEntry.getKey(), tenantEntry.getValue());
}
}
Expand All @@ -51,41 +51,41 @@ private void contributeCoordinationRuntimeProperties(BiConsumer<String, Object>
AgentsConfig agentsConfig) {
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_ENABLED,
agentsConfig.eventProcessor.enabled);
agentsConfig.eventProcessor().enabled());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_SHARDS_TOTAL_COUNT,
agentsConfig.eventProcessor.shards.totalCount);
agentsConfig.eventProcessor().shards().totalCount());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_SHARDS_ASSIGNED,
agentsConfig.eventProcessor.shards.assigned);
agentsConfig.eventProcessor().shards().assigned());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_POLLING_INTERVAL,
agentsConfig.eventProcessor.pollingInterval.toMillis());
agentsConfig.eventProcessor().pollingInterval().toMillis());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_PULSE_INTERVAL,
agentsConfig.eventProcessor.pulseInterval.toMillis());
agentsConfig.eventProcessor().pulseInterval().toMillis());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_PULSE_EXPIRATION,
agentsConfig.eventProcessor.pulseExpiration.toMillis());
agentsConfig.eventProcessor().pulseExpiration().toMillis());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_BATCH_SIZE,
agentsConfig.eventProcessor.batchSize);
agentsConfig.eventProcessor().batchSize());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_TRANSACTION_TIMEOUT,
agentsConfig.eventProcessor.transactionTimeout, Optional::isPresent, d -> d.get().toSeconds());
agentsConfig.eventProcessor().transactionTimeout(), Optional::isPresent, d -> d.get().toSeconds());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_RETRY_DELAY,
agentsConfig.eventProcessor.retryDelay.toSeconds());
agentsConfig.eventProcessor().retryDelay().toSeconds());

addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_POLLING_INTERVAL,
agentsConfig.massIndexer.pollingInterval.toMillis());
agentsConfig.massIndexer().pollingInterval().toMillis());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_PULSE_INTERVAL,
agentsConfig.massIndexer.pulseInterval.toMillis());
agentsConfig.massIndexer().pulseInterval().toMillis());
addCoordinationConfig(propertyCollector, tenantId,
HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_PULSE_EXPIRATION,
agentsConfig.massIndexer.pulseExpiration.toMillis());
agentsConfig.massIndexer().pulseExpiration().toMillis());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithParentName;

@ConfigRoot(name = "hibernate-search-orm", phase = ConfigPhase.RUN_TIME)
public class HibernateSearchOutboxPollingRuntimeConfig {
@ConfigMapping(prefix = "quarkus.hibernate-search-orm")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface HibernateSearchOutboxPollingRuntimeConfig {

/**
* Configuration for the default persistence unit.
*/
@ConfigItem(name = ConfigItem.PARENT)
public HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit defaultPersistenceUnit;
@WithParentName
HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit defaultPersistenceUnit();

/**
* Configuration for additional named persistence units.
*/
@ConfigDocSection
@ConfigDocMapKey("persistence-unit-name")
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit> persistenceUnits;
@WithParentName
Map<String, HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit> persistenceUnits();

}
Loading