Skip to content

Commit

Permalink
ArC - remove build items deprecated in 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Feb 23, 2021
1 parent 8f5fede commit 8d82838
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 347 deletions.
11 changes: 7 additions & 4 deletions docs/src/main/asciidoc/cdi-integration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,13 @@ IMPORTANT: A build step that consumes the `ObserverRegistrationPhaseBuildItem` s
void syntheticObserver(ObserverRegistrationPhaseBuildItem observerRegistrationPhase,
BuildProducer<MyBuildItem> myBuildItem,
BuildProducer<ObserverConfiguratorBuildItem> 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());
}
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ public ContextRegistrationPhaseBuildItem initialize(
List<AdditionalStereotypeBuildItem> additionalStereotypeBuildItems,
List<ApplicationClassPredicateBuildItem> applicationClassPredicates,
List<AdditionalBeanBuildItem> additionalBeans,
List<BeanRegistrarBuildItem> beanRegistrars,
List<ObserverRegistrarBuildItem> observerRegistrars,
List<ContextRegistrarBuildItem> contextRegistrars,
List<BeanDeploymentValidatorBuildItem> beanDeploymentValidators,
List<ResourceAnnotationBuildItem> resourceAnnotations,
List<BeanDefiningAnnotationBuildItem> additionalBeanDefiningAnnotations,
Optional<TestClassPredicateBuildItem> testClassPredicate,
Expand Down Expand Up @@ -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<BeanInfo>(
Expand Down Expand Up @@ -533,12 +517,8 @@ AdditionalBeanBuildItem loggerProducer() {
}

@BuildStep
CustomScopeAnnotationsBuildItem exposeCustomScopeNames(List<ContextRegistrarBuildItem> contextBuildItems,
List<CustomScopeBuildItem> customScopes) {
CustomScopeAnnotationsBuildItem exposeCustomScopeNames(List<CustomScopeBuildItem> customScopes) {
Set<DotName> names = new HashSet<>();
for (ContextRegistrarBuildItem item : contextBuildItems) {
names.addAll(item.getAnnotationNames());
}
for (CustomScopeBuildItem customScope : customScopes) {
names.add(customScope.getAnnotationName());
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,29 +164,24 @@ void validateConfigProperties(ConfigRecorder recorder, List<ConfigPropertyBuildI
}

@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();
}
}
void registerConfigRootsAsBeans(ConfigurationBuildItem configItem, BuildProducer<SyntheticBeanBuildItem> 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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +17,10 @@ public final class CustomScopeBuildItem extends MultiBuildItem {

private final DotName annotationName;

public CustomScopeBuildItem(Class<? extends Annotation> scope) {
this(DotName.createSimple(scope.getName()));
}

public CustomScopeBuildItem(DotName annotationName) {
this.annotationName = annotationName;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,38 +25,30 @@ public class ObserverValidationProcessor {

@BuildStep
public void validateApplicationObserver(ApplicationArchivesBuildItem applicationArchivesBuildItem,
BuildProducer<BeanDeploymentValidatorBuildItem> validators) {
ValidationPhaseBuildItem validationPhase, BuildProducer<ValidationErrorBuildItem> 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<ObserverInfo> 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());
}
}));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 8d82838

Please sign in to comment.