Skip to content

Commit

Permalink
ArC - rework the way the build profile producer beans are disabled
Browse files Browse the repository at this point in the history
- resolves quarkusio#17583
  • Loading branch information
mkouba committed Jun 17, 2021
1 parent ea6c9b4 commit 1b5a102
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
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 {
}

0 comments on commit 1b5a102

Please sign in to comment.