Skip to content
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
8 changes: 0 additions & 8 deletions .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ jobs:
incontainer-tests:
name: "Weld In-container Tests - JDK ${{matrix.java.name}}"
runs-on: ubuntu-latest
# Disabled until baseline WFLY supports EE 11 due to BeanManager#getELResolver calls
if: false
needs: initial-build
timeout-minutes: 120
strategy:
Expand Down Expand Up @@ -150,8 +148,6 @@ jobs:
CDI-TCK:
name: "CDI TCK - JDK ${{matrix.java.name}}"
runs-on: ubuntu-latest
# Disabled until baseline WFLY supports EE 11 due to BeanManager#getELResolver calls
if: false
needs: initial-build
timeout-minutes: 120
strategy:
Expand Down Expand Up @@ -220,8 +216,6 @@ jobs:
relaxed-mode-test:
name: "Relaxed mode testing - JDK ${{matrix.java.name}}"
runs-on: ubuntu-latest
# Disabled until baseline WFLY supports EE 11 due to BeanManager#getELResolver calls
if: false
needs: initial-build
timeout-minutes: 120
strategy:
Expand Down Expand Up @@ -346,8 +340,6 @@ jobs:
name: "Weld Examples build and test - JDK 17}"
runs-on: ubuntu-latest
needs: initial-build
# Disabled until baseline WFLY supports EE 11 due to BeanManager#getELResolver calls
if: false
timeout-minutes: 120
steps:
- uses: actions/checkout@v5
Expand Down
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</developers>

<properties>
<weld.api.bom.version>7.0.Alpha2</weld.api.bom.version>
<weld.api.bom.version>7.0.Alpha3</weld.api.bom.version>
<gpg.plugin.version>3.2.8</gpg.plugin.version>
<nexus.staging.plugin.version>1.7.0</nexus.staging.plugin.version>
<jboss.releases.repo.url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.injection.CurrentInjectionPoint;
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.serialization.spi.BeanIdentifier;
import org.jboss.weld.util.Beans;
Expand Down Expand Up @@ -225,9 +226,24 @@ public Integer getPriority() {
return explicitPriority;
}

// requires initialized getAnnotated() hence subclasses need to invoke this manually
protected void processExplicitPriority() {
/**
* Searches for {@code @Priority} annotation declared either directly on the producer or via its stereotypes.
* <p>
* Requires initialized {@code getAnnotated()} hence subclasses need to invoke this manually.
*/
protected void processPriority() {
Priority annotation = getAnnotated() == null ? null : getAnnotated().getAnnotation(Priority.class);
this.explicitPriority = annotation == null ? null : annotation.value();

// no explicit priority, try searching through stereotypes
if (explicitPriority == null) {
Beans.AnnotationSearchResult annotationSearchResult = Beans.annotationSearch(getAnnotated());
// multiple priorities within stereotypes are an error
if (annotationSearchResult.getPriorities().size() > 1) {
throw BootstrapLogger.LOG.multiplePriorityValuesDeclared(getAnnotated());
} else if (annotationSearchResult.getPriorities().size() == 1) {
this.explicitPriority = annotationSearchResult.getPriorities().iterator().next();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Bean<T> getBean() {
return ProducerField.this;
}
});
processExplicitPriority();
processPriority();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Bean<T> getBean() {
return ProducerMethod.this;
}
});
processExplicitPriority();
processPriority();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static class BeanAttributesBuilder<T> {

private MergedStereotypes<T, ?> mergedStereotypes;
private boolean alternative;
private boolean reserve;
private String name;
private Set<Annotation> qualifiers;
private Set<Type> types;
Expand All @@ -79,6 +80,7 @@ public BeanAttributesBuilder(EnhancedAnnotated<T, ?> annotated, Set<Type> types,
this.annotated = annotated;
initStereotypes(annotated, manager);
initAlternative(annotated);
initReserve(annotated);
initName(annotated);
initQualifiers(annotated);
initScope(annotated);
Expand All @@ -97,6 +99,10 @@ protected void initAlternative(EnhancedAnnotated<T, ?> annotated) {
this.alternative = Beans.isAlternative(annotated, mergedStereotypes);
}

protected void initReserve(EnhancedAnnotated<T, ?> annotated) {
this.reserve = Beans.isReserve(annotated, mergedStereotypes);
}

/**
* Initializes the name
*/
Expand Down Expand Up @@ -234,8 +240,8 @@ protected boolean initScopeFromStereotype() {
}

public BeanAttributes<T> build() {
return new ImmutableBeanAttributes<T>(mergedStereotypes.getStereotypes(), alternative, name, qualifiers, types,
scope);
return new ImmutableBeanAttributes<T>(mergedStereotypes.getStereotypes(), alternative, reserve, name,
qualifiers, types, scope);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ExternalBeanAttributesFactory() {
public static <T> BeanAttributes<T> of(BeanAttributes<T> source, BeanManager manager) {
validateBeanAttributes(source, manager);
BeanAttributes<T> attributes = new ImmutableBeanAttributes<T>(defensiveCopy(source.getStereotypes()),
source.isAlternative(), source.getName(),
source.isAlternative(), source.isReserve(), source.getName(),
defensiveCopy(source.getQualifiers()), defensiveCopy(source.getTypes()), source.getScope());
return attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ public class ImmutableBeanAttributes<T> implements BeanAttributes<T> {

private final Set<Class<? extends Annotation>> stereotypes;
private final boolean alternative;
private final boolean reserve;
private final String name;
private final Set<Annotation> qualifiers;
private final Set<Type> types;
private final Class<? extends Annotation> scope;

public ImmutableBeanAttributes(Set<Class<? extends Annotation>> stereotypes, boolean alternative, String name,
Set<Annotation> qualifiers, Set<Type> types,
Class<? extends Annotation> scope) {
public ImmutableBeanAttributes(Set<Class<? extends Annotation>> stereotypes, boolean alternative, boolean reserve,
String name, Set<Annotation> qualifiers, Set<Type> types, Class<? extends Annotation> scope) {
this.stereotypes = stereotypes;
this.alternative = alternative;
this.reserve = reserve;
this.name = name;
this.qualifiers = qualifiers;
this.types = types;
Expand All @@ -55,7 +56,8 @@ public ImmutableBeanAttributes(Set<Class<? extends Annotation>> stereotypes, boo
* Utility constructor used for overriding Bean qualifiers and name for specialization purposes.
*/
public ImmutableBeanAttributes(Set<Annotation> qualifiers, String name, BeanAttributes<T> attributes) {
this(attributes.getStereotypes(), attributes.isAlternative(), name, qualifiers, attributes.getTypes(),
this(attributes.getStereotypes(), attributes.isAlternative(), attributes.isReserve(), name, qualifiers,
attributes.getTypes(),
attributes.getScope());
}

Expand All @@ -69,6 +71,11 @@ public boolean isAlternative() {
return alternative;
}

@Override
public boolean isReserve() {
return reserve;
}

@Override
public String getName() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean isDependentContextOptimizationAllowed() {
protected static class BuiltInBeanAttributes<T> extends ImmutableBeanAttributes<T> {

public BuiltInBeanAttributes(Class<T> type) {
super(Collections.<Class<? extends Annotation>> emptySet(), false, null, Bindings.DEFAULT_QUALIFIERS,
super(Collections.<Class<? extends Annotation>> emptySet(), false, false, null, Bindings.DEFAULT_QUALIFIERS,
ImmutableSet.of(Object.class, type), Dependent.class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public boolean isMatchingEvent(Type eventType, Set<Annotation> eventQualifiers,
return delegate().isMatchingEvent(eventType, eventQualifiers, observedEventType, observedEventQualifiers);
}

@Override
public <T> T unwrapClientProxy(T reference) {
return delegate().unwrapClientProxy(reference);
}

@Override
public Bean<?> getPassivationCapableBean(BeanIdentifier identifier) {
return delegate().getPassivationCapableBean(identifier);
Expand Down
72 changes: 16 additions & 56 deletions impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import java.util.List;
import java.util.Set;

import jakarta.annotation.Priority;
import jakarta.decorator.Decorator;
import jakarta.enterprise.inject.Stereotype;
import jakarta.enterprise.inject.Reserve;
import jakarta.enterprise.inject.spi.AnnotatedType;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.Extension;
Expand Down Expand Up @@ -100,64 +99,21 @@ private <T> SlimAnnotatedTypeContext<T> addIfNotNull(SlimAnnotatedTypeContext<T>
return ctx;
}

/**
* Attempts to find a {@code @Priority} annotation declared on a stereotype(s) of given {@code AnnotatedType}.
* Returns the value in this annotation, or {@code null} if none was found.
*
* If the {@code AnnotatedType} declares more than one stereotype and at least two of them declare different
* {@code @Priority} values, a definition exception is thrown.
*
* If there are multiple {@code @Priority} values in a hierarchy of single stereotype, first annotation value is
* used.
*
* @param type AnnotatedType to be searched
* @return an Integer representing the priority value, null if none was found
*/
private Integer findPriorityInStereotypes(AnnotatedType<?> type) {
// search all annotations
Set<Integer> foundPriorities = new HashSet<>();
for (Annotation annotation : type.getAnnotations()) {
// identify stereotypes
Class<? extends Annotation> annotationClass = annotation.annotationType();
if (annotationClass.getAnnotation(Stereotype.class) != null) {
recursiveStereotypeSearch(annotationClass, foundPriorities);
}
}
// more than one value found, throw exception
if (foundPriorities.size() > 1) {
throw BootstrapLogger.LOG.multiplePriorityValuesDeclared(type);
}
// no priority found
if (foundPriorities.isEmpty()) {
return null;
}
// exactly one value found
return foundPriorities.iterator().next();
}

private void recursiveStereotypeSearch(Class<? extends Annotation> stereotype, Set<Integer> foundPriorities) {
// search each stereotype for priority annotation, store all values found
Priority priorityAnnotation = stereotype.getAnnotation(Priority.class);
if (priorityAnnotation != null) {
// if found, store the value
foundPriorities.add(priorityAnnotation.value());
}
// perform a recursive search for more stereotypes
for (Annotation annotation : stereotype.getAnnotations()) {
Class<? extends Annotation> annotationClass = annotation.annotationType();
if (annotationClass.getAnnotation(Stereotype.class) != null) {
recursiveStereotypeSearch(annotationClass, foundPriorities);
}
}
}

private void processPriority(AnnotatedType<?> type) {
// check if @Priority is declared directly on the AnnotatedType
Object priority = type.getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
Integer value;
Integer value = null;
// search stereotypes for priority/alternative/reserve annotations
Beans.AnnotationSearchResult annSearchResult = Beans.annotationSearch(type);
if (priority == null) {
// if not declared, search in any stereotypes of given AnnotatedType
value = findPriorityInStereotypes(type);
Set<Integer> priorities = annSearchResult.getPriorities();
// more than one value found and no priority on the class itself, throw an exception
if (priorities.size() > 1) {
throw BootstrapLogger.LOG.multiplePriorityValuesDeclared(type);
} else if (priorities.size() == 1) {
// exactly one value, we can use that
value = priorities.iterator().next();
}
} else {
value = annotationApi.getPriority(priority);
}
Expand All @@ -168,6 +124,10 @@ private void processPriority(AnnotatedType<?> type) {
} else if (type.isAnnotationPresent(Decorator.class)) {
globalEnablementBuilder.addDecorator(type.getJavaClass(), value);
} else {
// Validation of a bean being both reserve and alternative happens in Validator for now, possibly register both
if (type.isAnnotationPresent(Reserve.class) || annSearchResult.getReserve() != null) {
globalEnablementBuilder.addReserve(type.getJavaClass(), value);
}
/*
* An alternative may be given a priority for the application by placing the @Priority annotation on the bean
* class that declares the producer method, field or resource.
Expand Down
15 changes: 14 additions & 1 deletion impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ protected void validateGeneralBean(Bean<?> bean, BeanManagerImpl beanManager) {
if (beanManager.isPassivatingScope(bean.getScope()) && !Beans.isPassivationCapableBean(bean)) {
throw ValidatorLogger.LOG.beanWithPassivatingScopeNotPassivationCapable(bean);
}

// a bean cannot be an alternative and a reserve at the same time
if (bean.isAlternative() && bean.isReserve()) {
throw ValidatorLogger.LOG.beanReserveAndAlternative(bean);
}
}

/**
Expand All @@ -189,12 +194,12 @@ protected void validateRIBean(CommonBean<?> bean, BeanManagerImpl beanManager, C
validateInterceptors(beanManager, classBean);
}
}
// for each producer bean validate its disposer method
if (bean instanceof AbstractProducerBean<?, ?, ?>) {
AbstractProducerBean<?, ?, ?> producerBean = Reflections.<AbstractProducerBean<?, ?, ?>> cast(bean);
if (producerBean.getProducer() instanceof AbstractMemberProducer<?, ?>) {
AbstractMemberProducer<?, ?> producer = Reflections.<AbstractMemberProducer<?, ?>> cast(producerBean
.getProducer());
// for each producer bean validate its disposer method
if (producer.getDisposalMethod() != null) {
for (InjectionPoint ip : producer.getDisposalMethod().getInjectionPoints()) {
// pass the producer bean instead of the disposal method bean
Expand All @@ -204,6 +209,14 @@ protected void validateRIBean(CommonBean<?> bean, BeanManagerImpl beanManager, C
validateInjectionPointForDeploymentProblems(ip, null, beanManager);
}
}
// if it's an alternative, declaring bean cannot be a reserve
if (producerBean.isAlternative() && producerBean.getDeclaringBean().isReserve()) {
throw ValidatorLogger.LOG.producedAlternativeOnReserveDeclaringBean(producerBean);
}
// if it's a reserve, declaring bean cannot be alternative
if (producerBean.isReserve() && producerBean.getDeclaringBean().isAlternative()) {
throw ValidatorLogger.LOG.producedReserveOnAlternativeDeclaringBean(producerBean);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public void remove() {
enum ViewType {

ALTERNATIVES("getAlternatives()"),
RESERVES("getReserves()"),
INTERCEPTORS("getInterceptors()"),
DECORATORS("getDecorators()");

Expand Down
Loading
Loading