Skip to content

Commit

Permalink
Merge pull request quarkusio#17972 from mkouba/issue-17583
Browse files Browse the repository at this point in the history
ArC - rework the way the build profile producer beans are disabled
  • Loading branch information
mkouba authored Jun 17, 2021
2 parents 8269fbd + 1b5a102 commit 05b3caa
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 05b3caa

Please sign in to comment.