Skip to content

Commit

Permalink
[WFLY-11186][WFLY-11187] Weld subsystem should declare a capability
Browse files Browse the repository at this point in the history
  • Loading branch information
yersan committed Apr 26, 2019
1 parent b0c412a commit ac53dff
Show file tree
Hide file tree
Showing 67 changed files with 719 additions and 169 deletions.
4 changes: 4 additions & 0 deletions batch-jberet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-weld-spi</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-weld-common</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
package org.wildfly.extension.batch.jberet.deployment;

import static org.jboss.as.server.deployment.Attachments.DEPLOYMENT_COMPLETE_SERVICES;

import javax.enterprise.inject.spi.BeanManager;
import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME;

import org.jberet.repository.JobRepository;
import org.jberet.spi.ArtifactFactory;
Expand All @@ -34,14 +33,14 @@
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ee.weld.WeldDeploymentMarker;
import org.jboss.as.server.Services;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.weld.WeldCapability;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
Expand Down Expand Up @@ -135,10 +134,12 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
final ServiceBuilder<ArtifactFactory> artifactFactoryServiceBuilder = serviceTarget.addService(artifactFactoryServiceName, artifactFactoryService);

// Register the bean manager if this is a CDI deployment
if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
BatchLogger.LOGGER.tracef("Adding BeanManager service dependency for deployment %s", deploymentUnit.getName());
artifactFactoryServiceBuilder.addDependency(BatchServiceNames.beanManagerServiceName(deploymentUnit), BeanManager.class,
artifactFactoryService.getBeanManagerInjector());
if (support.hasCapability(WELD_CAPABILITY_NAME)) {
final WeldCapability api = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get();
if (api.isPartOfWeldDeployment(deploymentUnit)) {
BatchLogger.LOGGER.tracef("Adding BeanManager service dependency for deployment %s", deploymentUnit.getName());
api.addBeanManagerService(deploymentUnit, artifactFactoryServiceBuilder, artifactFactoryService.getBeanManagerInjector());
}
}
artifactFactoryServiceBuilder.install();
serviceBuilder.addDependency(artifactFactoryServiceName, WildFlyArtifactFactory.class, service.getArtifactFactoryInjector());
Expand Down
4 changes: 4 additions & 0 deletions bean-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-naming</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-weld-common</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-elytron</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
*/
package org.jboss.as.ee.beanvalidation;

import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME;

import javax.validation.ValidatorFactory;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentNamingMode;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ee.weld.WeldDeploymentMarker;
import org.jboss.as.naming.ServiceBasedNamingStore;
import org.jboss.as.naming.ValueManagedReferenceFactory;
import org.jboss.as.naming.deployment.ContextNames;
Expand All @@ -38,6 +40,7 @@
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.weld.WeldCapability;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
Expand Down Expand Up @@ -114,7 +117,14 @@ private void bindServices(LazyValidatorFactory factory, ServiceTarget serviceTar
@Override
public void undeploy(DeploymentUnit context) {
ValidatorFactory validatorFactory = context.getAttachment(BeanValidationAttachments.VALIDATOR_FACTORY);
if ((validatorFactory != null) && (!WeldDeploymentMarker.isPartOfWeldDeployment(context))) {
final CapabilityServiceSupport support = context.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);

boolean partOfWeldDeployment = false;
if (support.hasCapability(WELD_CAPABILITY_NAME)) {
partOfWeldDeployment = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class)
.get().isPartOfWeldDeployment(context);
}
if (validatorFactory != null && !partOfWeldDeployment) {
// If the ValidatorFactory is not CDI-enabled, close it here. Otherwise, it's
// closed via CdiValidatorFactoryService before the Weld service is stopped.
validatorFactory.close();
Expand Down
5 changes: 0 additions & 5 deletions ee-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
<artifactId>wildfly-ee</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-weld</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
*
* @author Stuart Douglas
*
* @deprecated Use WeldCapability to get access to the functionality of this class.
*/
@Deprecated
public class WeldDeploymentMarker {

private static final AttachmentKey<Boolean> MARKER = AttachmentKey.create(Boolean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<module name="org.wildfly.extension.request-controller"/>
<module name="org.wildfly.discovery"/>
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.weld"/>
<!-- So we can access its integration API -->
<module name="org.jboss.as.connector"/>
<!-- Need access to org.jboss.as.core.security.ServerSecurityManager -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<module name="org.wildfly.security.elytron-private"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.web-common"/>
<!-- Only used if capability org.wildfly.weld is available -->
<module name="org.jboss.as.weld.common" optional="true"/>
<module name="org.wildfly.extension.undertow"/>
<module name="io.undertow.core"/>
<module name="io.undertow.servlet"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
<module name="org.jboss.metadata.common"/>
<module name="org.jboss.vfs"/>
<module name="org.jboss.weld.core"/>
<!-- Optional; guarded by WeldDeploymentMarker which will not be present
if the weld subsystem isn't.-->
<!-- Only used if capability org.wildfly.weld is available -->
<module name="org.jboss.as.weld.common" optional="true"/>
<module name="org.wildfly.clustering.infinispan.spi"/>
<module name="org.wildfly.transaction.client"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<module name="org.wildfly.security.elytron-private"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.web-common"/>
<module name="org.jboss.as.weld.common"/>
<!-- Only used if capability org.wildfly.weld is available -->
<module name="org.jboss.as.weld.common" optional="true"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.ee"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.jboss.as.controller" />
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/>
<module name="org.wildfly.extension.bean-validation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<property name="jboss.api" value="private"/>
</properties>

<exports>
<exclude path="org/jboss/as/weld/_private"/>
</exports>

<resources>
<artifact name="${org.wildfly:wildfly-weld}"/>
</resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<module name="org.jboss.as.naming"/>
<module name="org.jboss.as.threads"/>
<module name="org.jboss.as.server"/>
<!-- Only used if capability org.wildfly.weld is available -->
<module name="org.jboss.as.weld.common" optional="true"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.ee"/>
<module name="org.jboss.as.naming" />
<!-- Only used if capability org.wildfly.weld is available -->
<module name="org.jboss.as.weld.common" optional="true"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.jboss.as.server" />
<module name="org.jboss.modules"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<module name="org.glassfish.soteria" />
<module name="javax.security.enterprise.api" />
<module name="javax.enterprise.api" />
<module name="org.jboss.as.weld.common" />
<module name="org.jboss.jandex"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.common"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.weld"/>
<!-- Only used if capability org.wildfly.weld is available -->
<module name="org.jboss.as.weld.common" optional="true"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.metadata.common"/>
<module name="org.jboss.modules"/>
Expand All @@ -74,9 +75,7 @@
<module name="org.wildfly.naming-client" services="import" />
<module name="org.jboss.threads"/>
<module name="org.wildfly.clustering.spi"/>
<module name="org.jboss.weld.api" />
<module name="org.jboss.weld.core"/>
<module name="org.jboss.weld.spi" />
<!-- org.jboss.xnio is required only if http-acceptor are used -->
<module name="org.jboss.xnio" optional="true" />
<!-- org.jboss.xnio.netty.netty-xnio-transport is required only if http-acceptor are used -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
<module name="org.jboss.logging"/>
<module name="org.jboss.vfs"/>
<module name="org.eclipse.microprofile.health.api"/>
<module name="org.jboss.as.weld" />
<module name="org.jboss.as.ee" />
<module name="org.jboss.as.weld.common" />
<module name="javax.enterprise.api" />
<module name="javax.annotation.api" />
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
<feature spec="subsystem.jsf"/>
<feature spec="subsystem.jaxrs"/>
<feature spec="subsystem.jdr"/>
<feature spec="subsystem.weld"/>
<feature spec="subsystem.microprofile-config-smallrye"/>
<feature spec="subsystem.microprofile-opentracing-smallrye"/>
<feature spec="subsystem.pojo"/>
<feature spec="subsystem.sar"/>
<feature-group name="mail"/>
<feature-group name="webservices"/>
<feature spec="subsystem.weld"/>
<feature-group name="security-manager"/>
</feature-group-spec>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<dependencies>
<layer name="web-server"/>
<layer name="management"/>
<layer name="cdi"/>
</dependencies>
<feature-group name="health"/>
<feature-group name="metrics"/>
Expand Down
5 changes: 5 additions & 0 deletions jaxrs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<artifactId>wildfly-web-common</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-weld-common</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-undertow</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion jaxrs/src/main/java/org/jboss/as/jaxrs/JaxrsSubsystemAdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
package org.jboss.as.jaxrs;


import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME;

import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.jaxrs.deployment.JaxrsAnnotationProcessor;
import org.jboss.as.jaxrs.deployment.JaxrsCdiIntegrationProcessor;
Expand Down Expand Up @@ -66,8 +69,13 @@ public void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(JaxrsExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_JAXRS, new JaxrsDependencyProcessor());
processorTarget.addDeploymentProcessor(JaxrsExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_JAXRS_SCANNING, new JaxrsScanningProcessor());
processorTarget.addDeploymentProcessor(JaxrsExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_JAXRS_COMPONENT, new JaxrsComponentDeployer());
processorTarget.addDeploymentProcessor(JaxrsExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_JAXRS_CDI_INTEGRATION, new JaxrsCdiIntegrationProcessor());

CapabilityServiceSupport capabilities = context.getCapabilityServiceSupport();
if (capabilities.hasCapability(WELD_CAPABILITY_NAME)) {
processorTarget.addDeploymentProcessor(JaxrsExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_JAXRS_CDI_INTEGRATION, new JaxrsCdiIntegrationProcessor());
}
processorTarget.addDeploymentProcessor(JaxrsExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_JAXRS_METHOD_PARAMETER, new JaxrsMethodParameterProcessor());

processorTarget.addDeploymentProcessor(JaxrsExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_JAXRS_DEPLOYMENT, new JaxrsIntegrationProcessor());
}
}, OperationContext.Stage.RUNTIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@
package org.jboss.as.jaxrs.deployment;

import static org.jboss.as.jaxrs.logging.JaxrsLogger.JAXRS_LOGGER;
import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME;

import java.util.ArrayList;
import java.util.List;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ee.weld.WeldDeploymentMarker;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.web.common.WarMetaData;
import org.jboss.as.weld.WeldCapability;
import org.jboss.metadata.javaee.spec.ParamValueMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.modules.Module;

import java.util.ArrayList;
import java.util.List;

/**
* @author Stuart Douglas
*/
Expand All @@ -63,11 +65,15 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
final JBossWebMetaData webdata = warMetaData.getMergedJBossWebMetaData();

try {
module.getClassLoader().loadClass(CDI_INJECTOR_FACTORY_CLASS);
// don't set this param if CDI is not in classpath
if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
JAXRS_LOGGER.debug("Found CDI, adding injector factory class");
setContextParameter(webdata, "resteasy.injector.factory", CDI_INJECTOR_FACTORY_CLASS);
final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
if (support.hasCapability(WELD_CAPABILITY_NAME)) {
final WeldCapability api = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get();
if (api.isWeldDeployment(deploymentUnit)) {
// don't set this param if CDI is not in classpath
module.getClassLoader().loadClass(CDI_INJECTOR_FACTORY_CLASS);
JAXRS_LOGGER.debug("Found CDI, adding injector factory class");
setContextParameter(webdata, "resteasy.injector.factory", CDI_INJECTOR_FACTORY_CLASS);
}
}
} catch (ClassNotFoundException ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@
package org.jboss.as.jaxrs.deployment;

import static org.jboss.as.jaxrs.logging.JaxrsLogger.JAXRS_LOGGER;
import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME;

import java.util.Arrays;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription;
import org.jboss.as.ee.weld.WeldDeploymentMarker;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.weld.WeldCapability;
import org.jboss.modules.Module;
import org.jboss.resteasy.util.GetRestful;

Expand Down Expand Up @@ -81,6 +83,12 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro

final ClassLoader loader = module.getClassLoader();

final CapabilityServiceSupport support = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
boolean partOfWeldDeployment = false;
if (support.hasCapability(WELD_CAPABILITY_NAME)) {
partOfWeldDeployment = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get()
.isPartOfWeldDeployment(deploymentUnit);
}
for (final ComponentDescription component : moduleDescription.getComponentDescriptions()) {
Class<?> componentClass = null;
try {
Expand All @@ -95,7 +103,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
//using SFSB's as JAX-RS endpoints is not recommended, but if people really want to do it they can

JAXRS_LOGGER.debugf("Stateful session bean %s is being used as a JAX-RS endpoint, this is not recommended", component.getComponentName());
if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
if (partOfWeldDeployment) {
//if possible just let CDI handle the integration
continue;
}
Expand Down
Loading

0 comments on commit ac53dff

Please sign in to comment.