forked from wildfly/wildfly
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wildfly#18078 from manovotn/wfly19573
WFLY-19573 Expand WeldCapability to include build compatible extensions
- Loading branch information
Showing
14 changed files
with
464 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
...org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem; | ||
|
||
import org.jboss.as.controller.Extension; | ||
import org.jboss.as.controller.ModelVersion; | ||
import org.jboss.as.controller.OperationContext; | ||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.controller.PathElement; | ||
import org.jboss.as.controller.PersistentResourceXMLDescription; | ||
import org.jboss.as.controller.PersistentSubsystemSchema; | ||
import org.jboss.as.controller.ResourceDefinition; | ||
import org.jboss.as.controller.ResourceRegistration; | ||
import org.jboss.as.controller.SubsystemModel; | ||
import org.jboss.as.controller.SubsystemRegistration; | ||
import org.jboss.as.controller.SubsystemSchema; | ||
import org.jboss.as.controller.capability.CapabilityServiceSupport; | ||
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver; | ||
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver; | ||
import org.jboss.as.controller.registry.ManagementResourceRegistration; | ||
import org.jboss.as.controller.registry.OperationEntry; | ||
import org.jboss.as.controller.xml.VersionedNamespace; | ||
import org.jboss.as.server.AbstractDeploymentChainStep; | ||
import org.jboss.as.server.DeploymentProcessorTarget; | ||
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.deployment.Phase; | ||
import org.jboss.as.version.Stability; | ||
import org.jboss.as.weld.Capabilities; | ||
import org.jboss.as.weld.WeldCapability; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.staxmapper.IntVersion; | ||
import org.kohsuke.MetaInfServices; | ||
import org.wildfly.subsystem.SubsystemConfiguration; | ||
import org.wildfly.subsystem.SubsystemExtension; | ||
import org.wildfly.subsystem.SubsystemPersistence; | ||
import org.wildfly.subsystem.resource.ManagementResourceRegistrar; | ||
import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext; | ||
import org.wildfly.subsystem.resource.ResourceDescriptor; | ||
import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar; | ||
import org.wildfly.subsystem.resource.operation.ResourceOperationRuntimeHandler; | ||
|
||
@MetaInfServices(Extension.class) | ||
public class BCEExtension extends SubsystemExtension<BCEExtension.BCESubsystemSchema> { | ||
|
||
public BCEExtension() { | ||
super(SubsystemConfiguration.of(BCESubsystemRegistrar.NAME, BCESubsystemModel.CURRENT, | ||
BCESubsystemRegistrar::new), SubsystemPersistence.of(BCESubsystemSchema.CURRENT)); | ||
} | ||
|
||
/** | ||
* Model for the 'bce' subsystem. | ||
*/ | ||
public enum BCESubsystemModel implements SubsystemModel { | ||
VERSION_1_0_0(1, 0, 0), | ||
; | ||
|
||
static final BCESubsystemModel CURRENT = VERSION_1_0_0; | ||
|
||
private final ModelVersion version; | ||
|
||
BCESubsystemModel(int major, int minor, int micro) { | ||
this.version = ModelVersion.create(major, minor, micro); | ||
} | ||
|
||
@Override | ||
public ModelVersion getVersion() { | ||
return this.version; | ||
} | ||
} | ||
|
||
/** | ||
* Schema for the 'bce' subsystem. | ||
*/ | ||
public enum BCESubsystemSchema implements PersistentSubsystemSchema<BCESubsystemSchema> { | ||
|
||
VERSION_1_0(1, 0, Stability.DEFAULT), | ||
; | ||
|
||
static final BCESubsystemSchema CURRENT = VERSION_1_0; | ||
|
||
private final VersionedNamespace<IntVersion, BCESubsystemSchema> namespace; | ||
|
||
BCESubsystemSchema(int major, int minor, Stability stability) { | ||
this.namespace = SubsystemSchema.createSubsystemURN(BCESubsystemRegistrar.NAME, stability, new IntVersion(major, minor)); | ||
} | ||
|
||
@Override | ||
public VersionedNamespace<IntVersion, BCESubsystemSchema> getNamespace() { | ||
return this.namespace; | ||
} | ||
|
||
@Override | ||
public Stability getStability() { | ||
return Stability.DEFAULT; | ||
} | ||
|
||
@Override | ||
public PersistentResourceXMLDescription getXMLDescription() { | ||
PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this); | ||
return factory.builder(BCESubsystemRegistrar.PATH).build(); | ||
} | ||
} | ||
|
||
/** | ||
* Registrar for the 'bce' subsystem root resource. | ||
*/ | ||
private static final class BCESubsystemRegistrar implements SubsystemResourceDefinitionRegistrar { | ||
|
||
static final String NAME = "bce"; | ||
static final PathElement PATH = SubsystemResourceDefinitionRegistrar.pathElement(NAME); | ||
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(NAME, BCESubsystemRegistrar.class); | ||
|
||
@Override | ||
public ManagementResourceRegistration register(SubsystemRegistration parent, ManagementResourceRegistrationContext context) { | ||
ManagementResourceRegistration registration = parent.registerSubsystemModel(ResourceDefinition.builder(ResourceRegistration.of(PATH), RESOLVER).build()); | ||
ResourceDescriptor descriptor = ResourceDescriptor.builder(RESOLVER) | ||
.withAddOperationRestartFlag(OperationEntry.Flag.RESTART_ALL_SERVICES) | ||
.withRemoveOperationRestartFlag(OperationEntry.Flag.RESTART_ALL_SERVICES) | ||
.withRuntimeHandler(new ResourceOperationRuntimeHandler() { | ||
@Override | ||
public void addRuntime(OperationContext context, ModelNode model) { | ||
if (context.isBooting()) { | ||
context.addStep(new AbstractDeploymentChainStep() { | ||
@Override | ||
protected void execute(DeploymentProcessorTarget processorTarget) { | ||
processorTarget.addDeploymentProcessor(NAME, Phase.INSTALL, Phase.INSTALL_WELD_DEPLOYMENT, new BCEDeploymentUnitProcessor()); | ||
|
||
} | ||
}, OperationContext.Stage.RUNTIME); | ||
} else { | ||
context.reloadRequired(); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeRuntime(OperationContext context, ModelNode model) throws OperationFailedException { | ||
context.reloadRequired(); | ||
} | ||
}) | ||
.build(); | ||
ManagementResourceRegistrar.of(descriptor).register(registration); | ||
return registration; | ||
} | ||
} | ||
|
||
private static final class BCEDeploymentUnitProcessor implements DeploymentUnitProcessor { | ||
|
||
@Override | ||
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { | ||
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); | ||
try { | ||
final WeldCapability weldCapability = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT) | ||
.getCapabilityRuntimeAPI(Capabilities.WELD_CAPABILITY_NAME, WeldCapability.class); | ||
weldCapability.registerBuildCompatibleExtension(RegisteredExtension.class, deploymentUnit); | ||
} catch (CapabilityServiceSupport.NoSuchCapabilityException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...va/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/DummyBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class DummyBean { | ||
} |
10 changes: 10 additions & 0 deletions
10
...g/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem; | ||
|
||
// no bean defining annotation, processed via RegisteredExtension | ||
public class RegisteredBean { | ||
} |
18 changes: 18 additions & 0 deletions
18
...ss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
import jakarta.enterprise.inject.build.compatible.spi.Discovery; | ||
import jakarta.enterprise.inject.build.compatible.spi.ScannedClasses; | ||
|
||
public class RegisteredExtension implements BuildCompatibleExtension { | ||
|
||
@Discovery | ||
public void discovery(ScannedClasses sc) { | ||
sc.add(RegisteredBean.class.getName()); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...t/integration/weld/extensions/buildcompatible/subsystem/SubsystemBceRegistrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem; | ||
|
||
import jakarta.inject.Inject; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.as.arquillian.api.ServerSetup; | ||
import org.jboss.as.arquillian.api.ServerSetupTask; | ||
import org.jboss.as.arquillian.container.ManagementClient; | ||
import org.jboss.as.controller.PathAddress; | ||
import org.jboss.as.controller.operations.common.Util; | ||
import org.jboss.as.test.module.util.TestModule; | ||
import org.jboss.as.test.shared.ServerReload; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
@RunWith(Arquillian.class) | ||
@ServerSetup(SubsystemBceRegistrationTest.SetupTask.class) | ||
public class SubsystemBceRegistrationTest { | ||
|
||
@Deployment | ||
public static WebArchive getDeployment() throws Exception { | ||
return ShrinkWrap.create(WebArchive.class) | ||
.addClasses(SubsystemBceRegistrationTest.class, DummyBean.class, TestModule.class, RegisteredBean.class) | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
} | ||
|
||
@Inject | ||
DummyBean dummyBean; | ||
|
||
@Inject | ||
RegisteredBean registeredBean; | ||
|
||
@Test | ||
public void testBceRegisteredAndExecuted() { | ||
// check plain WAR deployment | ||
Assert.assertNotNull(dummyBean); | ||
|
||
// verify BCE was executed; if so, RegisteredBean would now be resolvable | ||
Assert.assertNotNull(registeredBean); | ||
} | ||
|
||
public static class SetupTask implements ServerSetupTask { | ||
private static final String MODULE_NAME = "build-compatible-extension"; | ||
private static TestModule testModule; | ||
|
||
@Override | ||
public void setup(ManagementClient managementClient, String containerId) throws Exception { | ||
URL url = BCEExtension.class.getResource(MODULE_NAME + "-module.xml"); | ||
File moduleXmlFile = new File(url.toURI()); | ||
testModule = new TestModule("test." + MODULE_NAME, moduleXmlFile); | ||
testModule.addResource("bce-extension.jar") | ||
.addClasses(BCEExtension.class, RegisteredExtension.class, RegisteredBean.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") | ||
.addAsServiceProvider(org.jboss.as.controller.Extension.class, BCEExtension.class); | ||
testModule.create(); | ||
|
||
managementClient.getControllerClient().execute(Util.createAddOperation(PathAddress.pathAddress("extension", "test." + MODULE_NAME))); | ||
managementClient.getControllerClient().execute(Util.createAddOperation(PathAddress.pathAddress("subsystem", "bce"))); | ||
|
||
ServerReload.executeReloadAndWaitForCompletion(managementClient); | ||
} | ||
|
||
@Override | ||
public void tearDown(ManagementClient managementClient, String containerId) throws Exception { | ||
|
||
managementClient.getControllerClient().execute(Util.createRemoveOperation(PathAddress.pathAddress("subsystem", "bce"))); | ||
managementClient.getControllerClient().execute(Util.createRemoveOperation(PathAddress.pathAddress("extension", "test." + MODULE_NAME))); | ||
|
||
testModule.remove(); | ||
|
||
ServerReload.executeReloadAndWaitForCompletion(managementClient); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...tegration/weld/extensions/buildcompatible/subsystem/build-compatible-extension-module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ Copyright The WildFly Authors | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<module xmlns="urn:jboss:module:1.9" name="test.build-compatible-extension"> | ||
|
||
<resources> | ||
<resource-root path="bce-extension.jar"/> | ||
<!-- Insert resources here --> | ||
</resources> | ||
|
||
<dependencies> | ||
<module name="jakarta.enterprise.api"/> | ||
<module name="jakarta.inject.api"/> | ||
<module name="org.jboss.staxmapper"/> | ||
<module name="org.jboss.as.controller"/> | ||
<module name="org.jboss.as.server"/> | ||
<module name="org.jboss.as.weld.common"/> | ||
<module name="org.jboss.as.version"/> | ||
<module name="org.jboss.logging"/> | ||
<module name="org.wildfly.subsystem"/> | ||
</dependencies> | ||
</module> |
Oops, something went wrong.