From 8d82838da20495fc9e8ccc440b9f4082a845d023 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Tue, 23 Feb 2021 17:04:12 +0100 Subject: [PATCH] ArC - remove build items deprecated in 1.11 --- docs/src/main/asciidoc/cdi-integration.adoc | 11 ++- .../quarkus/arc/deployment/ArcProcessor.java | 22 +---- .../BeanDeploymentValidatorBuildItem.java | 27 ------ .../deployment/BeanRegistrarBuildItem.java | 28 ------ .../arc/deployment/ConfigBuildStep.java | 40 ++++----- .../deployment/ContextRegistrarBuildItem.java | 61 ------------- .../arc/deployment/CustomScopeBuildItem.java | 6 ++ .../ObserverRegistrarBuildItem.java | 29 ------ .../ObserverValidationProcessor.java | 57 +++++------- .../arc/deployment/StartupBuildSteps.java | 3 - .../test/observer/SyntheticObserverTest.java | 34 +++---- ...xiableBeanWithoutNoArgConstructorTest.java | 32 +++---- .../jta/deployment/NarayanaJtaProcessor.java | 22 ++--- .../deployment/RestClientProcessor.java | 90 +++++++++---------- .../deployment/SecurityProcessor.java | 36 +++----- 15 files changed, 151 insertions(+), 347 deletions(-) delete mode 100644 extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanDeploymentValidatorBuildItem.java delete mode 100644 extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanRegistrarBuildItem.java delete mode 100644 extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ContextRegistrarBuildItem.java delete mode 100644 extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverRegistrarBuildItem.java diff --git a/docs/src/main/asciidoc/cdi-integration.adoc b/docs/src/main/asciidoc/cdi-integration.adoc index a95693544c8e2..d76ae7261a850 100644 --- a/docs/src/main/asciidoc/cdi-integration.adoc +++ b/docs/src/main/asciidoc/cdi-integration.adoc @@ -341,10 +341,13 @@ IMPORTANT: A build step that consumes the `ObserverRegistrationPhaseBuildItem` s void syntheticObserver(ObserverRegistrationPhaseBuildItem observerRegistrationPhase, BuildProducer myBuildItem, BuildProducer observerConfigurators) { - observerConfigurators.produce(new ObserverConfiguratorBuildItem(observerRegistrationPhase.getContext().configure().observedType(String.class) - .notify(mc -> { - // do some gizmo bytecode generation... - }).done(); + observerConfigurators.produce(new ObserverConfiguratorBuildItem(observerRegistrationPhase.getContext() + .configure() + .beanClass(DotName.createSimple(MyBuildStep.class.getName())) + .observedType(String.class) + .notify(mc -> { + // do some gizmo bytecode generation... + }))); myBuildItem.produce(new MyBuildItem()); } ---- diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java index c2e48114dcf0f..3fc32765d97e4 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java @@ -142,10 +142,6 @@ public ContextRegistrationPhaseBuildItem initialize( List additionalStereotypeBuildItems, List applicationClassPredicates, List additionalBeans, - List beanRegistrars, - List observerRegistrars, - List contextRegistrars, - List beanDeploymentValidators, List resourceAnnotations, List additionalBeanDefiningAnnotations, Optional testClassPredicate, @@ -251,18 +247,6 @@ public void transform(TransformationContext transformationContext) { for (QualifierRegistrarBuildItem registrar : qualifierRegistrars) { builder.addQualifierRegistrar(registrar.getQualifierRegistrar()); } - for (BeanRegistrarBuildItem item : beanRegistrars) { - builder.addBeanRegistrar(item.getBeanRegistrar()); - } - for (ObserverRegistrarBuildItem item : observerRegistrars) { - builder.addObserverRegistrar(item.getObserverRegistrar()); - } - for (ContextRegistrarBuildItem item : contextRegistrars) { - builder.addContextRegistrar(item.getContextRegistrar()); - } - for (BeanDeploymentValidatorBuildItem item : beanDeploymentValidators) { - builder.addBeanDeploymentValidator(item.getBeanDeploymentValidator()); - } builder.setRemoveUnusedBeans(arcConfig.shouldEnableBeanRemoval()); if (arcConfig.shouldOnlyKeepAppBeans()) { builder.addRemovalExclusion(new AbstractCompositeApplicationClassesPredicate( @@ -533,12 +517,8 @@ AdditionalBeanBuildItem loggerProducer() { } @BuildStep - CustomScopeAnnotationsBuildItem exposeCustomScopeNames(List contextBuildItems, - List customScopes) { + CustomScopeAnnotationsBuildItem exposeCustomScopeNames(List customScopes) { Set names = new HashSet<>(); - for (ContextRegistrarBuildItem item : contextBuildItems) { - names.addAll(item.getAnnotationNames()); - } for (CustomScopeBuildItem customScope : customScopes) { names.add(customScope.getAnnotationName()); } diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanDeploymentValidatorBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanDeploymentValidatorBuildItem.java deleted file mode 100644 index b56e1d6afe533..0000000000000 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanDeploymentValidatorBuildItem.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.quarkus.arc.deployment; - -import io.quarkus.arc.processor.BeanDeploymentValidator; -import io.quarkus.builder.item.MultiBuildItem; - -/** - * Register a custom {@link BeanDeploymentValidator} which can either perform additional validation or enforce - * validation skip for certain components. - * - * This build item will be removed at some point post Quarkus 1.11. - * - * @deprecated Use {@link ValidationPhaseBuildItem} instead - */ -@Deprecated -public final class BeanDeploymentValidatorBuildItem extends MultiBuildItem { - - private final BeanDeploymentValidator beanDeploymentValidator; - - public BeanDeploymentValidatorBuildItem(BeanDeploymentValidator beanDeploymentValidator) { - this.beanDeploymentValidator = beanDeploymentValidator; - } - - public BeanDeploymentValidator getBeanDeploymentValidator() { - return beanDeploymentValidator; - } - -} diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanRegistrarBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanRegistrarBuildItem.java deleted file mode 100644 index 3fca5fa6085c9..0000000000000 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanRegistrarBuildItem.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.quarkus.arc.deployment; - -import io.quarkus.arc.processor.BeanRegistrar; -import io.quarkus.builder.item.MultiBuildItem; - -/** - * Used for registration of a synthetic bean; grants access to {@link BeanRegistrar} which is an API allowing to - * specify a synthetic bean through series of configuration methods (scope, type, qualifiers, ...). - * - * This is a build time alternative to CDI BeanConfigurator API. - * - * This build item will be removed at some point post Quarkus 1.11. - * - * @deprecated Use {@link SyntheticBeanBuildItem} instead - */ -@Deprecated -public final class BeanRegistrarBuildItem extends MultiBuildItem { - - private final BeanRegistrar beanRegistrar; - - public BeanRegistrarBuildItem(BeanRegistrar beanRegistrar) { - this.beanRegistrar = beanRegistrar; - } - - public BeanRegistrar getBeanRegistrar() { - return beanRegistrar; - } -} diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java index ac647bf54fadf..dc5d10e7a70d2 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java @@ -30,7 +30,6 @@ import org.jboss.jandex.Type.Kind; import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem; -import io.quarkus.arc.processor.BeanRegistrar; import io.quarkus.arc.processor.DotNames; import io.quarkus.arc.processor.InjectionPointInfo; import io.quarkus.arc.runtime.ConfigBeanCreator; @@ -165,29 +164,24 @@ void validateConfigProperties(ConfigRecorder recorder, List 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(); - } - } + void registerConfigRootsAsBeans(ConfigurationBuildItem configItem, BuildProducer syntheticBeans) { + for (RootDefinition rootDefinition : configItem.getReadResult().getAllRoots()) { + if (rootDefinition.getConfigPhase() == ConfigPhase.BUILD_AND_RUN_TIME_FIXED + || rootDefinition.getConfigPhase() == ConfigPhase.RUN_TIME) { + Class configRootClass = rootDefinition.getConfigurationClass(); + syntheticBeans.produce(SyntheticBeanBuildItem.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()); } - }); + } } @BuildStep diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ContextRegistrarBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ContextRegistrarBuildItem.java deleted file mode 100644 index d3e0210797e3b..0000000000000 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ContextRegistrarBuildItem.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.quarkus.arc.deployment; - -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -import org.jboss.jandex.DotName; -import org.jboss.logging.Logger; - -import io.quarkus.arc.processor.ContextRegistrar; -import io.quarkus.builder.item.MultiBuildItem; - -/** - * Make it possible to register one or more custom CDI contexts. - * If you are registering a new context, you also pass in the respective annotation value into the constructor either in - * {@link DotName} form, or as {@code Class}. - * - * This information is then leveraged in {@link CustomScopeAnnotationsBuildItem} which allows consumers to browse - * all known custom scoped within deployment even early in the build process. - * - * This build item will be removed at some point post Quarkus 1.11. - * - * @deprecated User {@link ContextRegistrationPhaseBuildItem} instead - */ -@Deprecated -public final class ContextRegistrarBuildItem extends MultiBuildItem { - - private static final Logger LOGGER = Logger.getLogger(ContextRegistrarBuildItem.class); - - private final ContextRegistrar contextRegistrar; - private final Collection annotationNames; - - public ContextRegistrarBuildItem(ContextRegistrar contextRegistrar, DotName... annotationsNames) { - this.contextRegistrar = contextRegistrar; - if (annotationsNames.length == 0) { - // log info level - usually you want to pass in annotation name as well - LOGGER.infof("A ContextRegistrarBuildItem was created but no annotation name/class was specified." + - "This information can be later on consumed by other extensions via CustomScopeAnnotationsBuildItem, " + - "please consider adding it."); - } - Collection names = new ArrayList<>(annotationsNames.length); - for (DotName name : annotationsNames) { - names.add(name); - } - this.annotationNames = names; - } - - public ContextRegistrarBuildItem(ContextRegistrar contextRegistrar, Class... annotationsClasses) { - this(contextRegistrar, Arrays.stream(annotationsClasses).map(Class::getName) - .map(DotName::createSimple).toArray(DotName[]::new)); - } - - public ContextRegistrar getContextRegistrar() { - return contextRegistrar; - } - - public Collection getAnnotationNames() { - return annotationNames; - } -} diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/CustomScopeBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/CustomScopeBuildItem.java index ace06a08b42c9..478b8a3913c65 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/CustomScopeBuildItem.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/CustomScopeBuildItem.java @@ -1,5 +1,7 @@ package io.quarkus.arc.deployment; +import java.lang.annotation.Annotation; + import org.jboss.jandex.DotName; import io.quarkus.builder.item.MultiBuildItem; @@ -15,6 +17,10 @@ public final class CustomScopeBuildItem extends MultiBuildItem { private final DotName annotationName; + public CustomScopeBuildItem(Class scope) { + this(DotName.createSimple(scope.getName())); + } + public CustomScopeBuildItem(DotName annotationName) { this.annotationName = annotationName; } diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverRegistrarBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverRegistrarBuildItem.java deleted file mode 100644 index c2ccd193dd19a..0000000000000 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverRegistrarBuildItem.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.quarkus.arc.deployment; - -import io.quarkus.arc.processor.ObserverRegistrar; -import io.quarkus.builder.item.MultiBuildItem; - -/** - * Used for registration of a synthetic observer; grants access to {@link ObserverRegistrar} which is an API allowing to - * specify a synthetic observer through series of configuration methods. - * - * This is a build time alternative to CDI ObserverMethodConfigurator API. - * - * This build item will be removed at some point post Quarkus 1.11. - * - * @deprecated Use {@link ObserverRegistrationPhaseBuildItem} instead - */ -@Deprecated -public final class ObserverRegistrarBuildItem extends MultiBuildItem { - - private final ObserverRegistrar observerRegistrar; - - public ObserverRegistrarBuildItem(ObserverRegistrar observerRegistrar) { - this.observerRegistrar = observerRegistrar; - } - - public ObserverRegistrar getObserverRegistrar() { - return observerRegistrar; - } - -} diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverValidationProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverValidationProcessor.java index c4f6d1fc3813d..79011c3c53674 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverValidationProcessor.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ObserverValidationProcessor.java @@ -1,14 +1,13 @@ package io.quarkus.arc.deployment; -import java.util.Collection; - import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; import org.jboss.logging.Logger; +import io.quarkus.arc.deployment.ValidationPhaseBuildItem.ValidationErrorBuildItem; import io.quarkus.arc.processor.Annotations; -import io.quarkus.arc.processor.BeanDeploymentValidator; +import io.quarkus.arc.processor.BuildExtension; import io.quarkus.arc.processor.BuiltinScope; import io.quarkus.arc.processor.DotNames; import io.quarkus.arc.processor.ObserverInfo; @@ -26,38 +25,30 @@ public class ObserverValidationProcessor { @BuildStep public void validateApplicationObserver(ApplicationArchivesBuildItem applicationArchivesBuildItem, - BuildProducer validators) { + ValidationPhaseBuildItem validationPhase, BuildProducer errors) { // an index of all root archive classes (usually src/main/classes) IndexView applicationClassesIndex = applicationArchivesBuildItem.getRootArchive().getIndex(); - - validators.produce(new BeanDeploymentValidatorBuildItem(new BeanDeploymentValidator() { - - @Override - public void validate(ValidationContext context) { - Collection allObservers = context.get(Key.OBSERVERS); - // do the validation for each observer that can be found within application classes - for (ObserverInfo observer : allObservers) { - if (observer.isSynthetic()) { - // Skip synthetic observers - continue; - } - DotName declaringBeanDotName = observer.getDeclaringBean().getBeanClass(); - AnnotationInstance instance = Annotations.getParameterAnnotation(observer.getObserverMethod(), - DotNames.INITIALIZED); - if (applicationClassesIndex.getClassByName(declaringBeanDotName) != null && instance != null && - instance.value().asClass().name().equals(BuiltinScope.APPLICATION.getName())) { - // found an observer for @Initialized(ApplicationScoped.class) - // log a warning and recommend to use StartupEvent instead - final String observerWarning = "The method %s#%s is an observer for " + - "@Initialized(ApplicationScoped.class). Observer notification for this event may " + - "vary between JVM and native modes! We strongly recommend to observe StartupEvent " + - "instead as that one is consistently delivered in both modes once the container is " + - "running."; - LOGGER.warnf(observerWarning, observer.getDeclaringBean().getImplClazz(), - observer.getObserverMethod().name()); - } - } + // do the validation for each observer that can be found within application classes + for (ObserverInfo observer : validationPhase.getContext().get(BuildExtension.Key.OBSERVERS)) { + if (observer.isSynthetic()) { + // Skip synthetic observers + continue; + } + DotName declaringBeanDotName = observer.getDeclaringBean().getBeanClass(); + AnnotationInstance instance = Annotations.getParameterAnnotation(observer.getObserverMethod(), + DotNames.INITIALIZED); + if (applicationClassesIndex.getClassByName(declaringBeanDotName) != null && instance != null && + instance.value().asClass().name().equals(BuiltinScope.APPLICATION.getName())) { + // found an observer for @Initialized(ApplicationScoped.class) + // log a warning and recommend to use StartupEvent instead + final String observerWarning = "The method %s#%s is an observer for " + + "@Initialized(ApplicationScoped.class). Observer notification for this event may " + + "vary between JVM and native modes! We strongly recommend to observe StartupEvent " + + "instead as that one is consistently delivered in both modes once the container is " + + "running."; + LOGGER.warnf(observerWarning, observer.getDeclaringBean().getImplClazz(), + observer.getObserverMethod().name()); } - })); + } } } diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/StartupBuildSteps.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/StartupBuildSteps.java index d215861b37a5b..3fc42d9158fcd 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/StartupBuildSteps.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/StartupBuildSteps.java @@ -7,7 +7,6 @@ import org.jboss.jandex.AnnotationTarget.Kind; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.DotName; -import org.jboss.logging.Logger; import io.quarkus.arc.Arc; import io.quarkus.arc.ArcContainer; @@ -45,8 +44,6 @@ public class StartupBuildSteps { static final MethodDescriptor CONTEXTUAL_DESTROY = MethodDescriptor.ofMethod(Contextual.class, "destroy", void.class, Object.class, CreationalContext.class); - private static final Logger LOGGER = Logger.getLogger(StartupBuildSteps.class); - @BuildStep AutoAddScopeBuildItem addScope(CustomScopeAnnotationsBuildItem customScopes) { // Class with no built-in scope annotation but with @Startup method diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/observer/SyntheticObserverTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/observer/SyntheticObserverTest.java index 24583e5471241..e784c3dc94176 100644 --- a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/observer/SyntheticObserverTest.java +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/observer/SyntheticObserverTest.java @@ -10,14 +10,15 @@ import javax.enterprise.event.Observes; import javax.inject.Singleton; +import org.jboss.jandex.DotName; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.arc.Arc; -import io.quarkus.arc.deployment.ObserverRegistrarBuildItem; -import io.quarkus.arc.processor.ObserverRegistrar; +import io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem; +import io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem.ObserverConfiguratorBuildItem; import io.quarkus.builder.BuildChainBuilder; import io.quarkus.builder.BuildContext; import io.quarkus.builder.BuildStep; @@ -43,21 +44,22 @@ public void accept(BuildChainBuilder builder) { @Override public void execute(BuildContext context) { - context.produce(new ObserverRegistrarBuildItem(new ObserverRegistrar() { - @Override - public void register(RegistrationContext context) { - context.configure().observedType(String.class).notify(mc -> { - ResultHandle events = mc - .readStaticField(FieldDescriptor.of(MyObserver.class, "EVENTS", List.class)); - mc.invokeInterfaceMethod( - MethodDescriptor.ofMethod(List.class, "add", boolean.class, Object.class), - events, mc.load("synthetic")); - mc.returnValue(null); - }).done(); - } - })); + ObserverRegistrationPhaseBuildItem observerRegistrationPhase = context + .consume(ObserverRegistrationPhaseBuildItem.class); + context.produce(new ObserverConfiguratorBuildItem( + observerRegistrationPhase.getContext().configure() + .beanClass(DotName.createSimple(SyntheticObserverTest.class.getName())) + .observedType(String.class).notify(mc -> { + ResultHandle events = mc + .readStaticField( + FieldDescriptor.of(MyObserver.class, "EVENTS", List.class)); + mc.invokeInterfaceMethod( + MethodDescriptor.ofMethod(List.class, "add", boolean.class, Object.class), + events, mc.load("synthetic")); + mc.returnValue(null); + }))); } - }).produces(ObserverRegistrarBuildItem.class).build(); + }).consumes(ObserverRegistrationPhaseBuildItem.class).produces(ObserverConfiguratorBuildItem.class).build(); } }; } diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unproxyable/SynthProxiableBeanWithoutNoArgConstructorTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unproxyable/SynthProxiableBeanWithoutNoArgConstructorTest.java index cb9f1a0fb0a16..da72411db6389 100644 --- a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unproxyable/SynthProxiableBeanWithoutNoArgConstructorTest.java +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unproxyable/SynthProxiableBeanWithoutNoArgConstructorTest.java @@ -15,8 +15,7 @@ import io.quarkus.arc.Arc; import io.quarkus.arc.InstanceHandle; -import io.quarkus.arc.deployment.BeanRegistrarBuildItem; -import io.quarkus.arc.processor.BeanRegistrar; +import io.quarkus.arc.deployment.SyntheticBeanBuildItem; import io.quarkus.builder.BuildChainBuilder; import io.quarkus.builder.BuildContext; import io.quarkus.builder.BuildStep; @@ -41,24 +40,19 @@ public void accept(BuildChainBuilder builder) { @Override public void execute(BuildContext context) { - context.produce(new BeanRegistrarBuildItem(new BeanRegistrar() { - @Override - public void register(RegistrationContext context) { - context.configure(SynthBean.class) - .scope(ApplicationScoped.class) - .types(SynthBean.class) - .unremovable() - .creator(mc -> { - ResultHandle ret = mc.newInstance( - MethodDescriptor.ofConstructor(SynthBean.class, String.class), - mc.load("foo")); - mc.returnValue(ret); - }) - .done(); - } - })); + context.produce(SyntheticBeanBuildItem.configure(SynthBean.class) + .scope(ApplicationScoped.class) + .types(SynthBean.class) + .unremovable() + .creator(mc -> { + ResultHandle ret = mc.newInstance( + MethodDescriptor.ofConstructor(SynthBean.class, String.class), + mc.load("foo")); + mc.returnValue(ret); + }) + .done()); } - }).produces(BeanRegistrarBuildItem.class).build(); + }).produces(SyntheticBeanBuildItem.class).build(); } }; } diff --git a/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java b/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java index 1d3fdb5a9d8be..9636f826fa5a5 100644 --- a/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java +++ b/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java @@ -21,11 +21,12 @@ import com.arjuna.common.util.propertyservice.PropertiesFactory; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; -import io.quarkus.arc.deployment.ContextRegistrarBuildItem; +import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem; +import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem; +import io.quarkus.arc.deployment.CustomScopeBuildItem; import io.quarkus.arc.deployment.GeneratedBeanBuildItem; import io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor; import io.quarkus.arc.deployment.UnremovableBeanBuildItem; -import io.quarkus.arc.processor.ContextRegistrar; import io.quarkus.deployment.Capability; import io.quarkus.deployment.Feature; import io.quarkus.deployment.IsTest; @@ -136,15 +137,14 @@ void testTx(BuildProducer generatedBeanBuildItemBuildPro } @BuildStep - public void transactionContext( - BuildProducer contextRegistry) { - - contextRegistry.produce(new ContextRegistrarBuildItem(new ContextRegistrar() { - @Override - public void register(RegistrationContext registrationContext) { - registrationContext.configure(TransactionScoped.class).normal().contextClass(TransactionContext.class).done(); - } - }, TransactionScoped.class)); + public ContextConfiguratorBuildItem transactionContext(ContextRegistrationPhaseBuildItem contextRegistrationPhase) { + return new ContextConfiguratorBuildItem(contextRegistrationPhase.getContext() + .configure(TransactionScoped.class).normal().contextClass(TransactionContext.class)); + } + + @BuildStep + public CustomScopeBuildItem registerScope() { + return new CustomScopeBuildItem(TransactionScoped.class); } @BuildStep diff --git a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java index e5903c814d783..41407fe791457 100644 --- a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java +++ b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java @@ -50,9 +50,8 @@ import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem; import io.quarkus.arc.deployment.BeanContainerListenerBuildItem; -import io.quarkus.arc.deployment.BeanRegistrarBuildItem; -import io.quarkus.arc.processor.BeanConfigurator; -import io.quarkus.arc.processor.BeanRegistrar; +import io.quarkus.arc.deployment.SyntheticBeanBuildItem; +import io.quarkus.arc.deployment.SyntheticBeanBuildItem.ExtendedBeanConfigurator; import io.quarkus.arc.processor.BuiltinScope; import io.quarkus.arc.processor.ScopeInfo; import io.quarkus.deployment.Capabilities; @@ -174,7 +173,7 @@ void processInterfaces( BuildProducer proxyDefinition, BuildProducer reflectiveClass, BuildProducer reflectiveHierarchy, - BuildProducer beanRegistrars, + BuildProducer syntheticBeans, BuildProducer serviceProvider, BuildProducer restClient) { @@ -223,51 +222,46 @@ void processInterfaces( .build()); } - beanRegistrars.produce(new BeanRegistrarBuildItem(new BeanRegistrar() { - - @Override - public void register(RegistrationContext registrationContext) { - final Config config = ConfigProvider.getConfig(); - - for (Map.Entry entry : interfaces.entrySet()) { - DotName restClientName = entry.getKey(); - BeanConfigurator configurator = registrationContext.configure(restClientName); - // The spec is not clear whether we should add superinterfaces too - let's keep aligned with SmallRye for now - configurator.addType(restClientName); - configurator.addQualifier(REST_CLIENT); - final String configPrefix = computeConfigPrefix(restClientName.toString(), entry.getValue()); - final ScopeInfo scope = computeDefaultScope(capabilities, config, entry, configPrefix); - final List> annotationProviders = checkAnnotationProviders(entry.getValue(), - restClientAnnotationProviders); - configurator.scope(scope); - configurator.creator(m -> { - // return new RestClientBase(proxyType, baseUri).create(); - ResultHandle interfaceHandle = m.loadClass(restClientName.toString()); - ResultHandle baseUriHandle = m.load(getAnnotationParameter(entry.getValue(), "baseUri")); - ResultHandle configPrefixHandle = m.load(configPrefix); - ResultHandle annotationProvidersHandle = null; - if (!annotationProviders.isEmpty()) { - annotationProvidersHandle = m.newArray(Class.class, annotationProviders.size()); - for (int i = 0; i < annotationProviders.size(); i++) { - m.writeArrayValue(annotationProvidersHandle, i, m.loadClass(annotationProviders.get(i))); - } - } else { - annotationProvidersHandle = m.loadNull(); - } - ResultHandle baseHandle = m.newInstance( - MethodDescriptor.ofConstructor(RestClientBase.class, Class.class, String.class, - String.class, - Class[].class), - interfaceHandle, baseUriHandle, configPrefixHandle, annotationProvidersHandle); - ResultHandle ret = m.invokeVirtualMethod( - MethodDescriptor.ofMethod(RestClientBase.class, "create", Object.class), baseHandle); - m.returnValue(ret); - }); - configurator.destroyer(BeanDestroyer.CloseableDestroyer.class); - configurator.done(); + final Config config = ConfigProvider.getConfig(); + + for (Map.Entry entry : interfaces.entrySet()) { + DotName restClientName = entry.getKey(); + ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem.configure(restClientName); + // The spec is not clear whether we should add superinterfaces too - let's keep aligned with SmallRye for now + configurator.addType(restClientName); + configurator.addQualifier(REST_CLIENT); + final String configPrefix = computeConfigPrefix(restClientName.toString(), entry.getValue()); + final ScopeInfo scope = computeDefaultScope(capabilities, config, entry, configPrefix); + final List> annotationProviders = checkAnnotationProviders(entry.getValue(), + restClientAnnotationProviders); + configurator.scope(scope); + configurator.creator(m -> { + // return new RestClientBase(proxyType, baseUri).create(); + ResultHandle interfaceHandle = m.loadClass(restClientName.toString()); + ResultHandle baseUriHandle = m.load(getAnnotationParameter(entry.getValue(), "baseUri")); + ResultHandle configPrefixHandle = m.load(configPrefix); + ResultHandle annotationProvidersHandle = null; + if (!annotationProviders.isEmpty()) { + annotationProvidersHandle = m.newArray(Class.class, annotationProviders.size()); + for (int i = 0; i < annotationProviders.size(); i++) { + m.writeArrayValue(annotationProvidersHandle, i, m.loadClass(annotationProviders.get(i))); + } + } else { + annotationProvidersHandle = m.loadNull(); } - } - })); + ResultHandle baseHandle = m.newInstance( + MethodDescriptor.ofConstructor(RestClientBase.class, Class.class, String.class, + String.class, + Class[].class), + interfaceHandle, baseUriHandle, configPrefixHandle, annotationProvidersHandle); + ResultHandle ret = m.invokeVirtualMethod( + MethodDescriptor.ofMethod(RestClientBase.class, "create", Object.class), baseHandle); + m.returnValue(ret); + }); + configurator.destroyer(BeanDestroyer.CloseableDestroyer.class); + + syntheticBeans.produce(configurator.done()); + } } private static List> checkAnnotationProviders(ClassInfo classInfo, diff --git a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java index a07ddc8bc1bca..e0a23311ca1ca 100644 --- a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java +++ b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java @@ -18,6 +18,8 @@ import java.util.Set; import java.util.function.Function; +import javax.enterprise.context.ApplicationScoped; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.ClassInfo; @@ -29,11 +31,8 @@ import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem; import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem; -import io.quarkus.arc.deployment.BeanRegistrarBuildItem; import io.quarkus.arc.deployment.InterceptorBindingRegistrarBuildItem; -import io.quarkus.arc.processor.BeanConfigurator; -import io.quarkus.arc.processor.BeanRegistrar; -import io.quarkus.arc.processor.BuiltinScope; +import io.quarkus.arc.deployment.SyntheticBeanBuildItem; import io.quarkus.deployment.Capability; import io.quarkus.deployment.Feature; import io.quarkus.deployment.annotations.BuildProducer; @@ -228,7 +227,7 @@ void transformSecurityAnnotations(BuildProducer @BuildStep @Record(ExecutionTime.STATIC_INIT) - void gatherSecurityChecks(BuildProducer beanRegistrars, + void gatherSecurityChecks(BuildProducer syntheticBeans, BeanArchiveIndexBuildItem beanArchiveBuildItem, BuildProducer classPredicate, List additionalSecuredClasses, @@ -266,25 +265,14 @@ void gatherSecurityChecks(BuildProducer beanRegistrars, } recorder.create(builder); - beanRegistrars.produce(new BeanRegistrarBuildItem(new BeanRegistrar() { - - @Override - public void register(RegistrationContext registrationContext) { - - DotName name = DotName.createSimple(SecurityCheckStorage.class.getName()); - - BeanConfigurator configurator = registrationContext.configure(name); - configurator.addType(name); - configurator.scope(BuiltinScope.APPLICATION.getInfo()); - configurator.creator(creator -> { - ResultHandle ret = creator.invokeStaticMethod( - MethodDescriptor.ofMethod(SecurityCheckRecorder.class, "getStorage", - SecurityCheckStorage.class)); - creator.returnValue(ret); - }); - configurator.done(); - } - })); + syntheticBeans.produce( + SyntheticBeanBuildItem.configure(SecurityCheckStorage.class) + .scope(ApplicationScoped.class) + .creator(creator -> { + ResultHandle ret = creator.invokeStaticMethod(MethodDescriptor.ofMethod(SecurityCheckRecorder.class, + "getStorage", SecurityCheckStorage.class)); + creator.returnValue(ret); + }).done()); } private Map gatherSecurityAnnotations(