diff --git a/core-client/src/main/java/module-info.java b/core-client/src/main/java/module-info.java index 1174c16590..ee94e3aa3d 100644 --- a/core-client/src/main/java/module-info.java +++ b/core-client/src/main/java/module-info.java @@ -30,6 +30,7 @@ exports org.glassfish.jersey.client.inject; exports org.glassfish.jersey.client.spi; exports org.glassfish.jersey.client.internal; + exports org.glassfish.jersey.client.internal.inject to org.glassfish.jersey.incubator.cdi.inject.weld; exports org.glassfish.jersey.client.innate to org.glassfish.jersey.apache5.connector, diff --git a/core-common/src/main/java/module-info.java b/core-common/src/main/java/module-info.java index 96d99e16b5..5020acdc14 100644 --- a/core-common/src/main/java/module-info.java +++ b/core-common/src/main/java/module-info.java @@ -61,7 +61,8 @@ org.glassfish.jersey.container.servlet, org.glassfish.jersey.container.jetty.http, org.glassfish.jersey.netty.connector, - org.glassfish.jersey.ext.mp.rest.client; + org.glassfish.jersey.ext.mp.rest.client, + org.glassfish.jersey.incubator.cdi.inject.weld; exports org.glassfish.jersey.innate.inject to org.glassfish.jersey.inject.hk2, org.glassfish.jersey.inject.cdi2.se, @@ -80,6 +81,7 @@ org.glassfish.jersey.ext.entity.filtering, org.glassfish.jersey.ext.metainf.services, org.glassfish.jersey.ext.mvc, + org.glassfish.jersey.incubator.cdi.inject.weld, org.glassfish.jersey.gf.ejb, org.glassfish.jersey.security.oauth1.signature; exports org.glassfish.jersey.innate.virtual to org.glassfish.jersey.container.grizzly2.http, @@ -104,6 +106,7 @@ opens org.glassfish.jersey.innate.spi to org.glassfish.jersey.media.multipart; opens org.glassfish.jersey.internal; + opens org.glassfish.jersey.internal.util.collection; opens org.glassfish.jersey.message.internal; opens org.glassfish.jersey.spi; @@ -111,7 +114,6 @@ uses jakarta.ws.rs.container.DynamicFeature; uses jakarta.ws.rs.ext.RuntimeDelegate; - uses org.glassfish.jersey.innate.BootstrapPreinitialization; uses org.glassfish.jersey.innate.spi.EntityPartBuilderProvider; uses org.glassfish.jersey.internal.ServiceFinder; uses org.glassfish.jersey.internal.inject.InjectionManagerFactory; diff --git a/core-server/src/main/java/module-info.java b/core-server/src/main/java/module-info.java index 187c595f95..de75462cb3 100644 --- a/core-server/src/main/java/module-info.java +++ b/core-server/src/main/java/module-info.java @@ -47,7 +47,10 @@ exports org.glassfish.jersey.server.wadl.internal.generators.resourcedoc; exports org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model; exports org.glassfish.jersey.server.filter; - exports org.glassfish.jersey.server.filter.internal to org.glassfish.hk2.locator, org.glassfish.hk2.utilities; + exports org.glassfish.jersey.server.filter.internal to + org.glassfish.hk2.locator, + org.glassfish.hk2.utilities, + org.glassfish.jersey.incubator.cdi.inject.weld; exports org.glassfish.jersey.server.monitoring; exports org.glassfish.jersey.server.internal; @@ -76,11 +79,18 @@ opens org.glassfish.jersey.server; opens org.glassfish.jersey.server.filter; - opens org.glassfish.jersey.server.internal to org.glassfish.hk2.utilities; + opens org.glassfish.jersey.server.filter.internal to + org.glassfish.hk2.locator, + org.glassfish.hk2.utilities, + weld.core.impl; + opens org.glassfish.jersey.server.internal to org.glassfish.hk2.utilities, weld.core.impl; opens org.glassfish.jersey.server.internal.inject; opens org.glassfish.jersey.server.internal.monitoring to org.glassfish.hk2.utilities; opens org.glassfish.jersey.server.internal.monitoring.jmx to org.glassfish.hk2.utilities; - opens org.glassfish.jersey.server.internal.process to org.glassfish.hk2.locator, org.glassfish.hk2.utilities; + opens org.glassfish.jersey.server.internal.process to + org.glassfish.hk2.locator, + org.glassfish.hk2.utilities, + weld.core.impl; opens org.glassfish.jersey.server.internal.routing to org.glassfish.hk2.utilities; opens org.glassfish.jersey.server.model; opens org.glassfish.jersey.server.wadl.processor; diff --git a/incubator/cdi-inject-weld/pom.xml b/incubator/cdi-inject-weld/pom.xml index 2a68ef1e92..e9123c8204 100644 --- a/incubator/cdi-inject-weld/pom.xml +++ b/incubator/cdi-inject-weld/pom.xml @@ -32,6 +32,16 @@ CDI InjectionManager implementation + + + + --add-exports org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld.binder.client=org.glassfish.jersey.core.common + --add-exports org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld.binder.client=weld.core.impl + --add-exports org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld=weld.core.impl + --add-opens org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld.binder.client=weld.core.impl + + + org.glassfish.jersey.core @@ -73,7 +83,7 @@ org.glassfish.jersey.containers jersey-container-grizzly2-http ${project.version} - provided + test @@ -81,12 +91,28 @@ jakarta.enterprise.cdi-api provided + + org.jboss.weld + weld-api + provided + + + org.jboss.weld + weld-spi + ${weld.api.version} + provided + + + org.jboss.weld + weld-core-impl + ${weld.version} + provided + org.jboss.weld.se weld-se-core - provided + test - org.junit.jupiter junit-jupiter @@ -140,7 +166,6 @@ org.glassfish.jersey.inject.weld.managed.*;version=${project.version} - jakarta.servlet.*;version="[6.0,7.0)", sun.misc.*;resolution:=optional, ${jakarta.annotation.osgi.version}, ${cdi.osgi.version}, diff --git a/incubator/cdi-inject-weld/src/main/java/module-info.txt b/incubator/cdi-inject-weld/src/main/java/module-info.java similarity index 50% rename from incubator/cdi-inject-weld/src/main/java/module-info.txt rename to incubator/cdi-inject-weld/src/main/java/module-info.java index 136324dc95..3bbb797fa5 100644 --- a/incubator/cdi-inject-weld/src/main/java/module-info.txt +++ b/incubator/cdi-inject-weld/src/main/java/module-info.java @@ -19,39 +19,33 @@ requires jakarta.cdi; requires jakarta.inject; requires jakarta.interceptor; - requires jakarta.servlet; -// requires jakarta.persistence; requires jakarta.ws.rs; requires java.logging; requires weld.api; - requires weld.spi; requires weld.core.impl; - requires weld.se.core; - requires weld.probe.core; - requires org.glassfish.grizzly.http.server; + requires weld.spi; requires org.glassfish.jersey.core.common; requires org.glassfish.jersey.core.client; requires org.glassfish.jersey.core.server; - requires org.glassfish.jersey.container.servlet; - - opens org.glassfish.jersey.inject.weld.internal.data; - opens org.glassfish.jersey.inject.weld.internal.bean; - opens org.glassfish.jersey.inject.weld.internal.inject; - opens org.glassfish.jersey.inject.weld.internal.managed; - opens org.glassfish.jersey.inject.weld.internal.scope; - opens org.glassfish.jersey.inject.weld.internal.type; - opens org.glassfish.jersey.inject.weld.spi; - opens org.glassfish.jersey.inject.weld.managed; - - exports org.glassfish.jersey.inject.weld.internal.data; - exports org.glassfish.jersey.inject.weld.internal.bean; - exports org.glassfish.jersey.inject.weld.internal.inject; - exports org.glassfish.jersey.inject.weld.internal.managed; - exports org.glassfish.jersey.inject.weld.internal.scope; - exports org.glassfish.jersey.inject.weld.internal.type; - exports org.glassfish.jersey.inject.weld.spi; - exports org.glassfish.jersey.inject.weld.managed; + + exports org.glassfish.jersey.inject.weld.internal.managed to + org.glassfish.jersey.core.common, + weld.core.impl; + exports org.glassfish.jersey.inject.weld.managed to org.glassfish.jersey.core.common; + + opens org.glassfish.jersey.inject.weld.internal.managed to weld.core.impl; + opens org.glassfish.jersey.inject.weld.internal.scope to weld.core.impl; + opens org.glassfish.jersey.inject.weld.managed to weld.core.impl; + opens org.glassfish.jersey.inject.weld.internal.injector to weld.core.impl; + + uses org.glassfish.jersey.innate.BootstrapPreinitialization; + + provides jakarta.enterprise.inject.spi.Extension with + org.glassfish.jersey.inject.weld.internal.managed.BinderRegisterExtension; + + provides org.glassfish.jersey.internal.inject.InjectionManagerFactory with + org.glassfish.jersey.inject.weld.managed.CdiInjectionManagerFactory; } \ No newline at end of file diff --git a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/JerseyBean.java b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/JerseyBean.java index deaa049223..1d9a9e3e39 100644 --- a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/JerseyBean.java +++ b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/JerseyBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -41,7 +41,7 @@ import org.glassfish.jersey.internal.inject.PerLookup; import org.glassfish.jersey.internal.inject.PerThread; -import org.jboss.weld.environment.se.contexts.ThreadScoped; +//import org.jboss.weld.environment.se.contexts.ThreadScoped; /** * Jersey-specific abstract class which implements {@link Bean} interface. Class particularly contains default implementations @@ -88,7 +88,7 @@ protected static Class transformScope(Class extends BasicInjectionTarget { + private static final Logger LOGGER = Logger.getLogger(JerseyInjectionTarget.class.getName()); + private final Bean bean; private final Class clazz; private final LazyValue> injector; @@ -78,6 +81,7 @@ public class JerseyInjectionTarget extends BasicInjectionTarget { private BasicInjectionTarget delegate; // for managed beans the initializeAfterBeanDiscovery is called for it private final Instantiator instantiator; + /** * Creates a new injection target which is able to delegate an injection to {@code delegate injection target} and inject * the fields that are Jersey-specific. The resolvers must be set later on. CDI will select its own constructor. @@ -156,8 +160,7 @@ public void inject(T instance, CreationalContext ctx) { } catch (WebApplicationException wae) { throw wae; } catch (Throwable cause) { - throw new InjectionException( - "Exception occurred during Jersey/JAX-RS annotations processing in the class: " + clazz, cause); + throw injectionException(LocalizationMessages.IT_PROCESSING_ANNOTATION_EXCEPTION(clazz.getName()), cause); } /* @@ -194,7 +197,7 @@ public void initializeAfterBeanDiscovery(EnhancedAnnotatedType annotatedType) if (hasNonConstructorInterceptors || hasDecorators) { if (!(getInstantiator() instanceof DefaultInstantiator)) { - throw new IllegalStateException("Unexpected instantiator " + getInstantiator()); + throw illegalStateException(LocalizationMessages.IT_UNEXPECTED_INSTANTIATOR(getInstantiator())); } /* @@ -232,16 +235,16 @@ private void checkNoArgsConstructor(EnhancedAnnotatedType type) { } EnhancedAnnotatedConstructor constructor = type.getNoArgsEnhancedConstructor(); if (constructor == null) { - throw BeanLogger.LOG.decoratedHasNoNoargsConstructor(this); + throw deploymentException(LocalizationMessages.IT_DECORATED_HAS_NO_NOARGS_CONSTRUCTOR(type)); } else if (constructor.isPrivate()) { - throw BeanLogger.LOG - .decoratedNoargsConstructorIsPrivate(this, Formats.formatAsStackTraceElement(constructor.getJavaMember())); + String stackTraceElement = Formats.formatAsStackTraceElement(constructor.getJavaMember()); + throw deploymentException(LocalizationMessages.IT_DECORATED_NOARGS_CONSTRUCTOR_PRIVATE(type, stackTraceElement)); } } private void checkDecoratedMethods(EnhancedAnnotatedType type, List> decorators) { if (type.isFinal()) { - throw BeanLogger.LOG.finalBeanClassWithDecoratorsNotAllowed(this); + throw deploymentException(LocalizationMessages.IT_FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED(type)); } checkNoArgsConstructor(type); for (Decorator decorator : decorators) { @@ -253,13 +256,13 @@ private void checkDecoratedMethods(EnhancedAnnotatedType type, List) { decoratorClass = ((CustomDecoratorWrapper) decorator).getEnhancedAnnotated(); } else { - throw BeanLogger.LOG.nonContainerDecorator(decorator); + throw illegalStateException(LocalizationMessages.IT_NON_CONTAINER_DECORATOR(decorator)); } for (EnhancedAnnotatedMethod decoratorMethod : decoratorClass.getEnhancedMethods()) { EnhancedAnnotatedMethod method = type.getEnhancedMethod(decoratorMethod.getSignature()); if (method != null && !method.isStatic() && !method.isPrivate() && method.isFinal()) { - throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(this); + throw deploymentException(LocalizationMessages.IT_FINAL_BEAN_CLASS_WITH_INTERCEPTORS_NOT_ALLOWED(type)); } } } @@ -292,6 +295,21 @@ private boolean isInterceptionCandidate() { return !isInterceptor() && !isDecorator() && !Modifier.isAbstract(getType().getJavaClass().getModifiers()); } + private static IllegalStateException illegalStateException(String message) { + LOGGER.warning(message); + return new IllegalStateException(message); + } + + private static DeploymentException deploymentException(String message) { + LOGGER.warning(message); + return new DeploymentException(message); + } + + private static InjectionException injectionException(String message, Throwable cause) { + LOGGER.warning(message); + return new InjectionException(message, cause); + } + @Override public T produce(CreationalContext ctx) { T instance; diff --git a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/BinderRegisterExtension.java b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/BinderRegisterExtension.java index a8692e455d..505bd73c16 100644 --- a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/BinderRegisterExtension.java +++ b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/BinderRegisterExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -33,6 +33,7 @@ import java.util.TreeMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; +import java.util.logging.Logger; import java.util.stream.Collectors; import jakarta.annotation.Priority; @@ -105,7 +106,9 @@ * CDI extension that handles CDI bootstrap events and registers Jersey's internally used components and components registered * using {@link Application}. */ -class BinderRegisterExtension implements Extension { +public class BinderRegisterExtension implements Extension { + + private static final Logger LOGGER = Logger.getLogger(BinderRegisterExtension.class.getName()); private final AtomicBoolean registrationDone = new AtomicBoolean(false); private Supplier beanManagerSupplier; @@ -679,6 +682,7 @@ public T createAndInitialize(Class createMe) { Constructor constructor = createMe.getConstructor(); return constructor.newInstance(); } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { + LOGGER.warning(e.getMessage()); return null; } } diff --git a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java index c0a31f67c7..522533f6d2 100644 --- a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java +++ b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -44,6 +44,7 @@ import org.glassfish.jersey.inject.weld.internal.inject.InitializableSupplierInstanceBinding; import org.glassfish.jersey.inject.weld.internal.bean.JerseyBean; import org.glassfish.jersey.inject.weld.internal.inject.MatchableBinding; +import org.glassfish.jersey.inject.weld.internal.l10n.LocalizationMessages; import org.glassfish.jersey.inject.weld.managed.CdiInjectionManagerFactory; import org.glassfish.jersey.innate.inject.InternalBinding; import org.glassfish.jersey.innate.inject.Bindings; diff --git a/incubator/cdi-inject-weld/src/main/resources/org/glassfish/jersey/inject/weld/internal/l10n/localization.properties b/incubator/cdi-inject-weld/src/main/resources/org/glassfish/jersey/inject/weld/internal/l10n/localization.properties new file mode 100644 index 0000000000..47ea08ca44 --- /dev/null +++ b/incubator/cdi-inject-weld/src/main/resources/org/glassfish/jersey/inject/weld/internal/l10n/localization.properties @@ -0,0 +1,27 @@ +# +# Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +# {0} - full classname +cdi2.provider.not.registrable=Provider registered to CdiInjectionManager cannot be process because of incompatible type: {0}. +it.processing.annotation.exception=Exception occurred during Jersey/JAX-RS annotations processing in the class: {0}. +it.unexpected.instantiator=Unexpected instantiator {0}. +it.decorated.has.no.noargs.constructor=Bean class which has decorators must have a public constructor without parameters: {0} +it.decorated.noargs.constructor.private=Constructor without parameters cannot be private in bean class which has decorators: {0} at {1} StackTrace. +it.final.bean.class.with.decorators.not.allowed=Bean class which has decorators cannot be declared final: {0}. +it.non.container.decorator=Cannot operate on non container provided decorator {0}. +it.final.bean.class.with.interceptors.not.allowed=Bean class which has interceptors cannot be declared final: {0}. + + diff --git a/incubator/cdi-inject-weld/src/main/resources/org/glassfish/jersey/inject/weld/internal/managed/localization.properties b/incubator/cdi-inject-weld/src/main/resources/org/glassfish/jersey/inject/weld/internal/managed/localization.properties deleted file mode 100644 index 8716ee6bb8..0000000000 --- a/incubator/cdi-inject-weld/src/main/resources/org/glassfish/jersey/inject/weld/internal/managed/localization.properties +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0, which is available at -# http://www.eclipse.org/legal/epl-2.0. -# -# This Source Code may also be made available under the following Secondary -# Licenses when the conditions for such availability set forth in the -# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, -# version 2 with the GNU Classpath Exception, which is available at -# https://www.gnu.org/software/classpath/license.html. -# -# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 -# - -# {0} - full classname -cdi2.provider.not.registrable=Provider registered to CdiInjectionManager cannot be process because of incompatible type: {0}. diff --git a/incubator/cdi-inject-weld/src/test/java/module-info.txt b/incubator/cdi-inject-weld/src/test/java/module-info.java.txt similarity index 70% rename from incubator/cdi-inject-weld/src/test/java/module-info.txt rename to incubator/cdi-inject-weld/src/test/java/module-info.java.txt index e9c2e19a6f..b1b05ebdd2 100644 --- a/incubator/cdi-inject-weld/src/test/java/module-info.txt +++ b/incubator/cdi-inject-weld/src/test/java/module-info.java.txt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,18 +14,23 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -open module org.glassfish.jersey.incubator.cdi.inject.weld { +open module org.glassfish.jersey.incubator.cdi.inject.weld.test { requires jakarta.annotation; requires jakarta.cdi; + requires jakarta.cdi.el; + requires jakarta.el; requires jakarta.inject; requires jakarta.ws.rs; requires java.logging; - - requires junit; + requires org.jboss.logging; + requires org.junit.jupiter.api; requires org.glassfish.jersey.core.common; requires org.glassfish.jersey.core.client; requires org.glassfish.jersey.core.server; + requires org.glassfish.jersey.incubator.cdi.inject.weld; requires org.hamcrest; + + exports org.glassfish.jersey.inject.weld.binder.client to org.glassfish.jersey.core.common; } \ No newline at end of file diff --git a/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/SingleArchiveDiscoveryStrategy.java b/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/SingleArchiveDiscoveryStrategy.java new file mode 100644 index 0000000000..52e9d86ca0 --- /dev/null +++ b/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/SingleArchiveDiscoveryStrategy.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.inject.weld; + +import org.jboss.weld.bootstrap.api.Bootstrap; +import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode; +import org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive; +import org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy; +import org.jboss.weld.environment.deployment.discovery.ReflectionDiscoveryStrategy; +import org.jboss.weld.resources.spi.ResourceLoader; + +import java.lang.annotation.Annotation; +import java.util.Set; + +/** + * Prevent loading the archives multiple times, once from the classpath, once from the module path. + * Done by Thread.currentThread().getContextClassLoader().getResource("META-INF/beans.xml") + */ +public class SingleArchiveDiscoveryStrategy extends ReflectionDiscoveryStrategy implements DiscoveryStrategy { + + public SingleArchiveDiscoveryStrategy(){ + super(null, null, null, null); + } + + public SingleArchiveDiscoveryStrategy(ResourceLoader resourceLoader, + Bootstrap bootstrap, + Set> initialBeanDefiningAnnotations, + BeanDiscoveryMode emptyBeansXmlDiscoveryMode) { + super(resourceLoader, bootstrap, initialBeanDefiningAnnotations, emptyBeansXmlDiscoveryMode); + } + + @Override + public Set performDiscovery() { + if (scanner == null) { + scanner = new SingleArchiveScanner(resourceLoader, bootstrap, BeanDiscoveryMode.ANNOTATED); + } + return super.performDiscovery(); + } +} diff --git a/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/SingleArchiveScanner.java b/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/SingleArchiveScanner.java new file mode 100644 index 0000000000..29816a2f68 --- /dev/null +++ b/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/SingleArchiveScanner.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.inject.weld; + +import org.jboss.weld.bootstrap.api.Bootstrap; +import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode; +import org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner; +import org.jboss.weld.resources.spi.ResourceLoader; + +import java.util.HashSet; +import java.util.List; +import java.util.Locale; + +class SingleArchiveScanner extends DefaultBeanArchiveScanner { + /** + * + * @param resourceLoader + * @param bootstrap + * @param emptyBeansXmlDiscoveryMode + */ + public SingleArchiveScanner(ResourceLoader resourceLoader, + Bootstrap bootstrap, + BeanDiscoveryMode emptyBeansXmlDiscoveryMode) { + super(resourceLoader, bootstrap, emptyBeansXmlDiscoveryMode); + } + + @Override + public List scan() { + HashSet beanArchives = new HashSet<>(); + return super.scan().stream() + .filter(scanResult -> !beanArchives.contains(scanResult.getBeanArchiveRef().toLowerCase(Locale.ROOT))) + .peek(scanResult -> beanArchives.add(scanResult.getBeanArchiveRef().toLowerCase(Locale.ROOT))) + .toList(); + } +} diff --git a/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/internal/managed/TestParent.java b/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/internal/managed/TestParent.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/incubator/cdi-inject-weld/src/test/resources/META-INF/beans.xml b/incubator/cdi-inject-weld/src/test/resources/META-INF/beans.xml index 678e3dc042..89484ca8b1 100644 --- a/incubator/cdi-inject-weld/src/test/resources/META-INF/beans.xml +++ b/incubator/cdi-inject-weld/src/test/resources/META-INF/beans.xml @@ -1,7 +1,7 @@ - - + + \ No newline at end of file diff --git a/incubator/cdi-inject-weld/src/test/resources/META-INF/services/org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy b/incubator/cdi-inject-weld/src/test/resources/META-INF/services/org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy new file mode 100644 index 0000000000..1d2ac45a75 --- /dev/null +++ b/incubator/cdi-inject-weld/src/test/resources/META-INF/services/org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy @@ -0,0 +1 @@ +org.glassfish.jersey.inject.weld.SingleArchiveDiscoveryStrategy \ No newline at end of file diff --git a/tests/e2e-inject/cdi-inject-weld/pom.xml b/tests/e2e-inject/cdi-inject-weld/pom.xml index a53512cc0d..2c9c334aa0 100644 --- a/tests/e2e-inject/cdi-inject-weld/pom.xml +++ b/tests/e2e-inject/cdi-inject-weld/pom.xml @@ -32,11 +32,24 @@ Jersey E2E Inject CDI SE tests + + + --add-reads org.jboss.logging=weld.core.impl + --add-reads org.jboss.logging=weld.se.core + --add-reads org.jboss.logging=weld.environment.common + + + jakarta.enterprise jakarta.enterprise.cdi-api + + org.jboss.weld + weld-api + provided + org.jboss.weld.se weld-se-core diff --git a/tests/e2e-inject/cdi-inject-weld/src/main/java/module-info.java b/tests/e2e-inject/cdi-inject-weld/src/main/java/module-info.java new file mode 100644 index 0000000000..71baa3be97 --- /dev/null +++ b/tests/e2e-inject/cdi-inject-weld/src/main/java/module-info.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +module org.glassfish.jersey.tests.e2e.inject.cdi.inject.weld.main { + requires jakarta.annotation; + requires jakarta.cdi; + requires jakarta.inject; + requires jakarta.interceptor; + requires jakarta.ws.rs; + requires org.glassfish.jersey.core.common; + requires org.glassfish.jersey.core.server; + requires weld.api; + + exports org.glassfish.jersey.tests.e2e.inject.cdi.weld; + exports org.glassfish.jersey.tests.e2e.inject.cdi.weld.scopes; + exports org.glassfish.jersey.tests.e2e.inject.cdi.weld.subresources; + + opens org.glassfish.jersey.tests.e2e.inject.cdi.weld to + org.glassfish.jersey.incubator.cdi.inject.weld, + weld.core.impl; + opens org.glassfish.jersey.tests.e2e.inject.cdi.weld.scopes to + org.glassfish.jersey.incubator.cdi.inject.weld, + weld.core.impl; + opens org.glassfish.jersey.tests.e2e.inject.cdi.weld.subresources to weld.core.impl; +} \ No newline at end of file diff --git a/tests/e2e-inject/cdi-inject-weld/src/test/java/module-info.java b/tests/e2e-inject/cdi-inject-weld/src/test/java/module-info.java new file mode 100644 index 0000000000..684bbe0a65 --- /dev/null +++ b/tests/e2e-inject/cdi-inject-weld/src/test/java/module-info.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +open module org.glassfish.jersey.tests.e2e.inject.cdi.inject.weld.test { + requires jakarta.cdi; + requires jakarta.ws.rs; + requires java.logging; + requires org.glassfish.jersey.core.common; + requires org.glassfish.jersey.core.server; + requires org.glassfish.jersey.inject.hk2; + requires org.glassfish.jersey.tests.e2e.inject.cdi.inject.weld.main; + requires org.glassfish.jersey.tests.framework.core; + requires org.junit.jupiter.api; + requires weld.core.impl; +} \ No newline at end of file diff --git a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/EventsTest.java b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/EventsTest.java similarity index 92% rename from tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/EventsTest.java rename to tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/EventsTest.java index c93a71de12..e423f7cab1 100644 --- a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/EventsTest.java +++ b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/EventsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.jersey.tests.e2e.inject.cdi.weld; +package org.glassfish.jersey.tests.e2e.inject.cdi.weld.test; import jakarta.ws.rs.client.Entity; import jakarta.ws.rs.core.Application; @@ -24,6 +24,7 @@ import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.AccountResource; import org.jboss.weld.environment.se.Weld; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assumptions; diff --git a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/InterceptorDecoratorTest.java b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/InterceptorDecoratorTest.java similarity index 90% rename from tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/InterceptorDecoratorTest.java rename to tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/InterceptorDecoratorTest.java index f789edcb75..0d91f4ca2f 100644 --- a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/InterceptorDecoratorTest.java +++ b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/InterceptorDecoratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.jersey.tests.e2e.inject.cdi.weld; +package org.glassfish.jersey.tests.e2e.inject.cdi.weld.test; import jakarta.ws.rs.core.Application; import jakarta.ws.rs.core.Response; @@ -23,6 +23,8 @@ import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.HelloResource; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.NameService; import org.jboss.weld.environment.se.Weld; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assumptions; diff --git a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/RequestContextBuilder.java b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/RequestContextBuilder.java similarity index 98% rename from tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/RequestContextBuilder.java rename to tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/RequestContextBuilder.java index 5eb8dd2105..d48cf0ff7f 100644 --- a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/RequestContextBuilder.java +++ b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/RequestContextBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.jersey.tests.e2e.inject.cdi.weld; +package org.glassfish.jersey.tests.e2e.inject.cdi.weld.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/scopes/ScopesTest.java b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/scopes/ScopesTest.java similarity index 90% rename from tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/scopes/ScopesTest.java rename to tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/scopes/ScopesTest.java index f88b1e2501..6c6a7c8186 100644 --- a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/scopes/ScopesTest.java +++ b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/scopes/ScopesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,11 +14,13 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.jersey.tests.e2e.inject.cdi.weld.scopes; +package org.glassfish.jersey.tests.e2e.inject.cdi.weld.test.scopes; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.scopes.RequestScopedResource; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.scopes.SingletonScopedResource; import org.jboss.weld.environment.se.Weld; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/subresources/ModelProcessorScopeTest.java b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/subresources/ModelProcessorScopeTest.java similarity index 92% rename from tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/subresources/ModelProcessorScopeTest.java rename to tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/subresources/ModelProcessorScopeTest.java index 58d2e5bbd6..f4b4872c51 100644 --- a/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/subresources/ModelProcessorScopeTest.java +++ b/tests/e2e-inject/cdi-inject-weld/src/test/java/org/glassfish/jersey/tests/e2e/inject/cdi/weld/test/subresources/ModelProcessorScopeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,14 +14,17 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.jersey.tests.e2e.inject.cdi.weld.subresources; +package org.glassfish.jersey.tests.e2e.inject.cdi.weld.test.subresources; import java.util.concurrent.ExecutionException; import org.glassfish.jersey.server.ApplicationHandler; import org.glassfish.jersey.server.ContainerResponse; import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.tests.e2e.inject.cdi.weld.RequestContextBuilder; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.subresources.ModelProcessorFeature; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.subresources.RootResource; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.subresources.RootSingletonResource; +import org.glassfish.jersey.tests.e2e.inject.cdi.weld.test.RequestContextBuilder; import org.jboss.weld.environment.se.Weld; import org.junit.jupiter.api.AfterEach;