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

WELD-2765, WELD-2774, dep updates #2911

Merged
merged 4 commits into from
Feb 25, 2024
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
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>6.0.Alpha2</weld.api.bom.version>
<weld.api.bom.version>6.0.Beta2</weld.api.bom.version>
<gpg.plugin.version>3.0.1</gpg.plugin.version>
<jboss.releases.repo.url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/</jboss.releases.repo.url>
<jboss.snapshots.repo.url>https://repository.jboss.org/nexus/content/repositories/snapshots/</jboss.snapshots.repo.url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ public WeldInstance<Object> createInstance() {
return delegate().createInstance();
}

@Override
public boolean isMatchingBean(Set<Type> beanTypes, Set<Annotation> beanQualifiers, Type requiredType,
Set<Annotation> requiredQualifiers) {
return delegate().isMatchingBean(beanTypes, beanQualifiers, requiredType, requiredQualifiers);
}

@Override
public boolean isMatchingEvent(Type eventType, Set<Annotation> eventQualifiers, Type observedEventType,
Set<Annotation> observedEventQualifiers) {
return delegate().isMatchingEvent(eventType, eventQualifiers, observedEventType, observedEventQualifiers);
}

@Override
public Bean<?> getPassivationCapableBean(BeanIdentifier identifier) {
return delegate().getPassivationCapableBean(identifier);
Expand Down
43 changes: 43 additions & 0 deletions impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.exceptions.DeploymentException;
import org.jboss.weld.exceptions.UnproxyableResolutionException;
import org.jboss.weld.inject.WeldInstance;
import org.jboss.weld.injection.producer.AbstractMemberProducer;
import org.jboss.weld.injection.producer.BasicInjectionTarget;
import org.jboss.weld.interceptor.reader.PlainInterceptorFactory;
import org.jboss.weld.interceptor.spi.metadata.InterceptorClassMetadata;
import org.jboss.weld.interceptor.spi.model.InterceptionModel;
import org.jboss.weld.invokable.AbstractInvokerBuilder;
import org.jboss.weld.invokable.ConfiguredLookup;
import org.jboss.weld.literal.DecoratedLiteral;
import org.jboss.weld.literal.InterceptedLiteral;
import org.jboss.weld.logging.BeanLogger;
Expand Down Expand Up @@ -499,6 +502,7 @@ public void validateDeployment(BeanManagerImpl manager, BeanDeployment deploymen
validateDisposalMethods(deployment.getBeanDeployer().getEnvironment());
validateObserverMethods(deployment.getBeanDeployer().getEnvironment().getObservers(), manager);
validateBeanNames(manager);
validateInvokers(manager);
}

public void validateSpecialization(BeanManagerImpl manager) {
Expand Down Expand Up @@ -1030,6 +1034,45 @@ private static void validatePseudoScopedInjectionPoint(InjectionPoint ij, BeanMa
}
}

private void validateInvokers(BeanManagerImpl manager) {
List<DeploymentException> errors = new ArrayList<>();

WeldInstance<Object> instance = manager.createInstance();
for (AbstractInvokerBuilder<?, ?> invoker : manager.getInvokers()) {
Class<?> reflectionBeanClass = invoker.getBeanClass().getJavaClass();
Method reflectionMethod = invoker.getMethod().getReflection();

for (ConfiguredLookup config : invoker.getConfiguredLookups()) {
WeldInstance<Object> lookup = instance.select(config.type, config.qualifiers);
if (lookup.isUnsatisfied()) {
if (config.isInstanceLookup()) {
errors.add(ValidatorLogger.LOG.invokerUnsatisfiedInstanceLookup(
reflectionBeanClass, reflectionMethod));
} else {
errors.add(ValidatorLogger.LOG.invokerUnsatisfiedArgumentLookup(
reflectionBeanClass, reflectionMethod, config.position));
}
} else if (lookup.isAmbiguous()) {
if (config.isInstanceLookup()) {
errors.add(ValidatorLogger.LOG.invokerAmbiguousInstanceLookup(
reflectionBeanClass, reflectionMethod));
} else {
errors.add(ValidatorLogger.LOG.invokerAmbiguousArgumentLookup(
reflectionBeanClass, reflectionMethod, config.position));
}
}
}
}

manager.forgetInvokersAfterValidation();

if (errors.size() == 1) {
throw errors.get(0);
} else if (errors.size() > 1) {
throw new DeploymentException(errors);
}
}

@Override
public void cleanup() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
*/
package org.jboss.weld.bootstrap.events;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;

import jakarta.enterprise.inject.spi.Annotated;
import jakarta.enterprise.inject.spi.AnnotatedMethod;
import jakarta.enterprise.inject.spi.Decorator;
import jakarta.enterprise.inject.spi.Interceptor;
import jakarta.enterprise.inject.spi.ProcessBean;
import jakarta.enterprise.invoke.Invoker;
import jakarta.enterprise.invoke.InvokerBuilder;

import org.jboss.weld.bean.ClassBean;
import org.jboss.weld.exceptions.DeploymentException;
import org.jboss.weld.invokable.InvokerBuilderImpl;
import org.jboss.weld.invokable.TargetMethod;
import org.jboss.weld.manager.BeanManagerImpl;

public abstract class AbstractProcessClassBean<X, B extends ClassBean<X>> extends AbstractDefinitionContainerEvent
Expand All @@ -44,4 +54,31 @@ public B getBean() {
return bean;
}

public InvokerBuilder<Invoker<X, ?>> createInvoker(AnnotatedMethod<? super X> annotatedMethod) {
checkWithinObserverNotification();

ClassBean<X> bean = getBean();
if (bean instanceof Interceptor) {
throw new DeploymentException("Cannot build invoker for an interceptor: " + bean);
}
if (bean instanceof Decorator) {
throw new DeploymentException("Cannot build invoker for a decorator: " + bean);
}

Method method = annotatedMethod.getJavaMember();
if (Modifier.isPrivate(method.getModifiers())) {
throw new DeploymentException("Cannot build invoker for a private method: " + annotatedMethod);
}
if ("java.lang.Object".equals(method.getDeclaringClass().getName())
&& !"toString".equals(method.getName())) {
throw new DeploymentException("Cannot build invoker for a method declared on java.lang.Object: " + annotatedMethod);
}

if (!bean.getAnnotated().getMethods().contains(annotatedMethod)) {
throw new DeploymentException("Method does not belong to bean " + bean + ": " + annotatedMethod);
}

return new InvokerBuilderImpl<>(bean.getAnnotated(), new TargetMethod(annotatedMethod), getBeanManager());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@

import java.lang.reflect.Type;

import jakarta.enterprise.inject.spi.AnnotatedMethod;
import jakarta.enterprise.inject.spi.AnnotatedType;
import jakarta.enterprise.inject.spi.ProcessManagedBean;
import jakarta.enterprise.invoke.Invoker;
import jakarta.enterprise.invoke.InvokerBuilder;

import org.jboss.weld.bean.ManagedBean;
import org.jboss.weld.invokable.InvokerBuilderImpl;
import org.jboss.weld.manager.BeanManagerImpl;

public class ProcessManagedBeanImpl<X> extends AbstractProcessClassBean<X, ManagedBean<X>> implements ProcessManagedBean<X> {
Expand All @@ -46,10 +42,4 @@ public AnnotatedType<X> getAnnotatedBeanClass() {
return getBean().getAnnotated();
}

@Override
public InvokerBuilder<Invoker<X, ?>> createInvoker(AnnotatedMethod<? super X> annotatedMethod) {
checkWithinObserverNotification();
return new InvokerBuilderImpl<>(getBean().getType(), annotatedMethod.getJavaMember(), getBeanManager());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@

import java.lang.reflect.Type;

import jakarta.enterprise.inject.spi.AnnotatedMethod;
import jakarta.enterprise.inject.spi.AnnotatedType;
import jakarta.enterprise.inject.spi.ProcessSessionBean;
import jakarta.enterprise.inject.spi.SessionBeanType;
import jakarta.enterprise.invoke.Invoker;
import jakarta.enterprise.invoke.InvokerBuilder;

import org.jboss.weld.bean.SessionBean;
import org.jboss.weld.invokable.InvokerBuilderImpl;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;

Expand Down Expand Up @@ -67,10 +63,4 @@ public AnnotatedType<Object> getAnnotatedBeanClass() {
return getBean().getAnnotated();
}

@Override
public InvokerBuilder<Invoker<Object, ?>> createInvoker(AnnotatedMethod<? super Object> annotatedMethod) {
checkWithinObserverNotification();
return new InvokerBuilderImpl<>(getBean().getEjbDescriptor().getBeanClass(), annotatedMethod.getJavaMember(),
getBeanManager());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Set;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.spi.BeanAttributes;
import jakarta.enterprise.inject.spi.configurator.BeanAttributesConfigurator;
Expand Down Expand Up @@ -222,7 +221,8 @@ public BeanAttributesConfigurator<T> alternative(boolean alternative) {

@Override
public BeanAttributes<T> complete() {
return new ImmutableBeanAttributes<T>(ImmutableSet.copyOf(stereotypes), isAlternative, name, initQualifiers(qualifiers),
return new ImmutableBeanAttributes<T>(ImmutableSet.copyOf(stereotypes), isAlternative, name,
Bindings.normalizeBeanQualifiers(qualifiers),
ImmutableSet.copyOf(types),
initScope());
}
Expand Down Expand Up @@ -258,27 +258,4 @@ private Class<? extends Annotation> initScope() {
return Dependent.class;
}

private Set<Annotation> initQualifiers(Set<Annotation> qualifiers) {
if (qualifiers.isEmpty()) {
return Bindings.DEFAULT_QUALIFIERS;
}
Set<Annotation> normalized = new HashSet<Annotation>(qualifiers);
normalized.remove(Any.Literal.INSTANCE);
normalized.remove(Default.Literal.INSTANCE);
if (normalized.isEmpty()) {
normalized = Bindings.DEFAULT_QUALIFIERS;
} else {
ImmutableSet.Builder<Annotation> builder = ImmutableSet.builder();
if (normalized.size() == 1) {
if (normalized.iterator().next().annotationType().equals(Named.class)) {
builder.add(Default.Literal.INSTANCE);
}
}
builder.add(Any.Literal.INSTANCE);
builder.addAll(qualifiers);
normalized = builder.build();
}
return normalized;
}

}
Loading
Loading