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

ArC - rework the way the build profile producer beans are disabled #17972

Merged
merged 1 commit into from
Jun 17, 2021
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 @@ -269,9 +269,8 @@ private void transformBean(AnnotationTarget target, TransformationContext ctx, b
// Veto the class
transform.add(DotNames.VETOED);
} else {
// Add @Alternative to the producer
transform.add(DotNames.ALTERNATIVE);
transform.remove(s -> s.name().equals(DotNames.ALTERNATIVE_PRIORITY));
// Veto the producer
transform.add(DotNames.VETOED_PRODUCER);
}
transform.done();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
if (annotationStore.getAnnotations(method).isEmpty()) {
continue;
}
if (annotationStore.hasAnnotation(method, DotNames.PRODUCES)) {
if (annotationStore.hasAnnotation(method, DotNames.PRODUCES)
&& !annotationStore.hasAnnotation(method, DotNames.VETOED_PRODUCER)) {
// Producers are not inherited
producerMethods.add(method);
if (!hasBeanDefiningAnnotation) {
Expand Down Expand Up @@ -874,7 +875,8 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
: null;
}
for (FieldInfo field : beanClass.fields()) {
if (annotationStore.hasAnnotation(field, DotNames.PRODUCES)) {
if (annotationStore.hasAnnotation(field, DotNames.PRODUCES)
&& !annotationStore.hasAnnotation(field, DotNames.VETOED_PRODUCER)) {
if (annotationStore.hasAnnotation(field, DotNames.INJECT)) {
throw new DefinitionException("Injected field cannot be annotated with @Produces: " + field);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.quarkus.arc.InjectableBean;
import io.quarkus.arc.InjectableInstance;
import io.quarkus.arc.Unremovable;
import io.quarkus.arc.VetoedProducer;
import io.quarkus.arc.impl.ComputingCache;
import java.io.Serializable;
import java.lang.annotation.Repeatable;
Expand Down Expand Up @@ -113,6 +114,7 @@ public final class DotNames {
public static final DotName DELEGATE = create(Delegate.class);
public static final DotName SERIALIZABLE = create(Serializable.class);
public static final DotName UNREMOVABLE = create(Unremovable.class);
public static final DotName VETOED_PRODUCER = create(VetoedProducer.class);

public static final DotName BOOLEAN = create(Boolean.class);
public static final DotName BYTE = create(Byte.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.arc;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Denotes a producer method or field that should be vetoed, i.e. ignored during bean discovery.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD })
public @interface VetoedProducer {
}