From 41939cff3b2e64f50bf192466126c89f38b1fe79 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Thu, 15 Feb 2024 09:54:53 -0600 Subject: [PATCH] [Issue_14] Refactor the subsystem to use wildfly-subsystem This brings also the stability=preview concept into the xml handling --- .../extension/mvc-krazo/main/module.xml | 2 + pom.xml | 24 ++++ subsystem/pom.xml | 8 ++ .../DeploymentDependenciesProcessor.java | 6 +- .../mvc/krazo/MVCKrazoExtension.java | 133 +++++++++--------- .../krazo/MVCKrazoSubsystemDefinition.java | 78 ---------- .../mvc/krazo/MVCKrazoSubsystemRegistrar.java | 59 ++++++++ .../schema/wildfly-mvc-krazo_preview_1_1.xsd | 18 +++ .../mvc/krazo/SubsystemTestCase.java | 34 +++-- .../mvc/krazo/mvc-krazo-preview-1.0.xml | 6 + .../mvc/krazo/mvc-krazo-preview-1.1.xml | 6 + testsuite/tck/pom.xml | 1 + .../tck/src/test/resources/arquillian.xml | 1 + 13 files changed, 222 insertions(+), 154 deletions(-) delete mode 100644 subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemDefinition.java create mode 100644 subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemRegistrar.java create mode 100644 subsystem/src/main/resources/schema/wildfly-mvc-krazo_preview_1_1.xsd create mode 100644 subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.0.xml create mode 100644 subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.1.xml diff --git a/galleon-shared/src/main/resources/modules/system/add-ons/mvc-krazo/org/wildfly/extension/mvc-krazo/main/module.xml b/galleon-shared/src/main/resources/modules/system/add-ons/mvc-krazo/org/wildfly/extension/mvc-krazo/main/module.xml index ea00f60..5d6b340 100644 --- a/galleon-shared/src/main/resources/modules/system/add-ons/mvc-krazo/org/wildfly/extension/mvc-krazo/main/module.xml +++ b/galleon-shared/src/main/resources/modules/system/add-ons/mvc-krazo/org/wildfly/extension/mvc-krazo/main/module.xml @@ -16,7 +16,9 @@ + + diff --git a/pom.xml b/pom.xml index d7cad21..7f061ff 100644 --- a/pom.xml +++ b/pom.xml @@ -159,6 +159,30 @@ + + org.wildfly.core + wildfly-subsystem + ${version.org.wildfly.core} + + + org.wildfly.core + * + + + + + + org.wildfly.core + wildfly-version + ${version.org.wildfly.core} + + + org.wildfly.core + * + + + + org.wildfly wildfly-ee diff --git a/subsystem/pom.xml b/subsystem/pom.xml index 2863943..90bbb1a 100644 --- a/subsystem/pom.xml +++ b/subsystem/pom.xml @@ -49,6 +49,14 @@ org.wildfly.core wildfly-server + + org.wildfly.core + wildfly-subsystem + + + org.wildfly.core + wildfly-version + org.wildfly.core diff --git a/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/DeploymentDependenciesProcessor.java b/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/DeploymentDependenciesProcessor.java index 79412b6..b2daf52 100644 --- a/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/DeploymentDependenciesProcessor.java +++ b/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/DeploymentDependenciesProcessor.java @@ -48,9 +48,9 @@ public void deploy(DeploymentPhaseContext phaseContext) { final ModuleLoader moduleLoader = Module.getBootModuleLoader(); // Use addSystemDependencies instead of multiple calls to addSystemDependency to avoid WFCORE-6601 moduleSpecification.addSystemDependencies(Set.of( - new ModuleDependency(moduleLoader, MVCKrazoSubsystemDefinition.MVC_API, false, true, true, false), - new ModuleDependency(moduleLoader, MVCKrazoSubsystemDefinition.KRAZO_CORE, false, true, true, false), - new ModuleDependency(moduleLoader, MVCKrazoSubsystemDefinition.KRAZO_RESTEASY, false, true, true, false) + new ModuleDependency(moduleLoader, MVCKrazoSubsystemRegistrar.MVC_API, false, true, true, false), + new ModuleDependency(moduleLoader, MVCKrazoSubsystemRegistrar.KRAZO_CORE, false, true, true, false), + new ModuleDependency(moduleLoader, MVCKrazoSubsystemRegistrar.KRAZO_RESTEASY, false, true, true, false) )); } diff --git a/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoExtension.java b/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoExtension.java index 6afdb80..0859b73 100644 --- a/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoExtension.java +++ b/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoExtension.java @@ -6,28 +6,18 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; -import java.util.List; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; - -import org.jboss.as.controller.Extension; -import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.ModelVersion; -import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PersistentResourceXMLDescription; -import org.jboss.as.controller.SubsystemRegistration; -import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; -import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; -import org.jboss.as.controller.parsing.ExtensionParsingContext; -import org.jboss.as.controller.persistence.SubsystemMarshallingContext; -import org.jboss.as.controller.registry.ManagementResourceRegistration; -import org.jboss.dmr.ModelNode; -import org.jboss.staxmapper.XMLElementReader; -import org.jboss.staxmapper.XMLElementWriter; -import org.jboss.staxmapper.XMLExtendedStreamReader; -import org.jboss.staxmapper.XMLExtendedStreamWriter; +import org.jboss.as.controller.PersistentSubsystemSchema; +import org.jboss.as.controller.SubsystemModel; +import org.jboss.as.controller.SubsystemSchema; +import org.jboss.as.controller.xml.VersionedNamespace; +import org.jboss.as.version.Stability; +import org.jboss.staxmapper.IntVersion; +import org.wildfly.subsystem.SubsystemConfiguration; +import org.wildfly.subsystem.SubsystemExtension; +import org.wildfly.subsystem.SubsystemPersistence; /** @@ -35,74 +25,91 @@ * * @author Brian Stansberry */ -public final class MVCKrazoExtension implements Extension { - - /** - * The name space used for the {@code substystem} element - */ - public static final String NAMESPACE = "urn:jboss:domain:mvc-krazo:1.0"; +public final class MVCKrazoExtension extends SubsystemExtension { /** * The name of our subsystem within the model. */ - public static final String SUBSYSTEM_NAME = "mvc-krazo"; - - /** - * The parser used for parsing our subsystem - */ - private final SubsystemParser parser = new SubsystemParser(); + static final String SUBSYSTEM_NAME = "mvc-krazo"; + private static final Stability FEATURE_STABILITY = Stability.PREVIEW; static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME); - private static final String RESOURCE_NAME = MVCKrazoExtension.class.getPackage().getName() + ".LocalDescriptions"; - static StandardResourceDescriptionResolver getResourceDescriptionResolver() { - return new StandardResourceDescriptionResolver(SUBSYSTEM_NAME, RESOURCE_NAME, MVCKrazoExtension.class.getClassLoader(), true, false); + public MVCKrazoExtension() { + super(SubsystemConfiguration.of(SUBSYSTEM_NAME, MVCKrazoSubsystemModel.CURRENT, MVCKrazoSubsystemRegistrar::new), + SubsystemPersistence.of(MVCKrazoSubsystemSchema.CURRENT)); } - @Override - public void initializeParsers(ExtensionParsingContext context) { - context.setSubsystemXmlMapping(SUBSYSTEM_NAME, NAMESPACE, parser); - } + // TODO enable this when WildFly Galleon Plugin can handle it +// @Override +// public Stability getStability() { +// return FEATURE_STABILITY; +// } + + /** + * Model for the 'mvc-krazo' subsystem. + */ + public enum MVCKrazoSubsystemModel implements SubsystemModel { + VERSION_1_0_0(1, 0, 0), + ; + static final MVCKrazoSubsystemModel CURRENT = VERSION_1_0_0; - @Override - public void initialize(ExtensionContext context) { - final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, ModelVersion.create(1, 0)); - final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(MVCKrazoSubsystemDefinition.INSTANCE); - registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE); + private final ModelVersion version; - subsystem.registerXMLElementWriter(parser); + MVCKrazoSubsystemModel(int major, int minor, int micro) { + this.version = ModelVersion.create(major, minor, micro); + } + + @Override + public ModelVersion getVersion() { + return this.version; + } } /** - * The subsystem parser, which uses stax to read and write to and from xml. + * Schema for the 'mvc-krazo' subsystem. */ - private static class SubsystemParser implements XMLStreamConstants, XMLElementReader>, XMLElementWriter { + public enum MVCKrazoSubsystemSchema implements PersistentSubsystemSchema { - private final PersistentResourceXMLDescription xmlDescription; + /* urn:jboss:domain variant from WF Preview 31 + It wasn't really DEFAULT stability, but its namespace didn't include 'preview' + so we work around that. See also getStability(). */ + VERSION_1_0_LEGACY(1, 0, Stability.DEFAULT, true), + // first urn:wildfly variant + VERSION_1_1_PREVIEW(1, 1, FEATURE_STABILITY), + ; - private SubsystemParser() { - this.xmlDescription = PersistentResourceXMLDescription.builder(MVCKrazoSubsystemDefinition.INSTANCE.getPathElement()) - .build(); + static final MVCKrazoSubsystemSchema CURRENT = VERSION_1_1_PREVIEW; + + private final VersionedNamespace namespace; + + MVCKrazoSubsystemSchema(int major, int minor, Stability stability) { + this(major, minor, stability, false); + } + MVCKrazoSubsystemSchema(int major, int minor, Stability stability, boolean legacy) { + if (legacy) { + this.namespace = SubsystemSchema.createLegacySubsystemURN(SUBSYSTEM_NAME, stability, new IntVersion(major, minor)); + } else { + this.namespace = SubsystemSchema.createSubsystemURN(SUBSYSTEM_NAME, stability, new IntVersion(major, minor)); + } } - /** - * {@inheritDoc} - */ @Override - public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { - ModelNode model = new ModelNode(); - model.get(MVCKrazoSubsystemDefinition.INSTANCE.getPathElement().getKeyValuePair()).set(context.getModelNode()); - xmlDescription.persist(writer, model, MVCKrazoExtension.NAMESPACE); + public VersionedNamespace getNamespace() { + return this.namespace; } - /** - * {@inheritDoc} - */ @Override - public void readElement(XMLExtendedStreamReader reader, List list) throws XMLStreamException { - xmlDescription.parse(reader, PathAddress.EMPTY_ADDRESS, list); + public Stability getStability() { + return this == VERSION_1_0_LEGACY ? Stability.PREVIEW : this.getNamespace().getStability(); } - } + @Override + public PersistentResourceXMLDescription getXMLDescription() { + PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this); + return factory.builder(SUBSYSTEM_PATH) + .build(); + } + } } diff --git a/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemDefinition.java b/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemDefinition.java deleted file mode 100644 index 3e4b014..0000000 --- a/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemDefinition.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.extension.mvc.krazo; - -import java.util.Arrays; -import java.util.Collection; - -import org.jboss.as.controller.AbstractBoottimeAddStepHandler; -import org.jboss.as.controller.AttributeDefinition; -import org.jboss.as.controller.OperationContext; -import org.jboss.as.controller.PersistentResourceDefinition; -import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; -import org.jboss.as.controller.registry.ManagementResourceRegistration; -import org.jboss.as.controller.registry.Resource; -import org.jboss.as.controller.registry.RuntimePackageDependency; -import org.jboss.as.server.AbstractDeploymentChainStep; -import org.jboss.as.server.DeploymentProcessorTarget; -import org.jboss.dmr.ModelNode; - -/** - * Resource definition for the mvc-krazo subsystem root resource. - * - * @author Brian Stansberry - */ -final class MVCKrazoSubsystemDefinition extends PersistentResourceDefinition { - - static final String MVC_API = "jakarta.mvc.api"; - static final String KRAZO_CORE = "org.eclipse.krazo.core"; - static final String KRAZO_RESTEASY = "org.eclipse.krazo.resteasy"; - - static final AttributeDefinition[] ATTRIBUTES = { /* none */ }; - - static final MVCKrazoSubsystemDefinition INSTANCE = new MVCKrazoSubsystemDefinition(); - - private MVCKrazoSubsystemDefinition() { - super(MVCKrazoExtension.SUBSYSTEM_PATH, - MVCKrazoExtension.getResourceDescriptionResolver(), - new SubsystemAdd(), - ReloadRequiredRemoveStepHandler.INSTANCE); - } - - @Override - public Collection getAttributes() { - return Arrays.asList(ATTRIBUTES); - } - - @Override - public void registerAdditionalRuntimePackages(ManagementResourceRegistration resourceRegistration) { - resourceRegistration.registerAdditionalRuntimePackages( - RuntimePackageDependency.required(MVC_API), - RuntimePackageDependency.required(KRAZO_CORE), - RuntimePackageDependency.required(KRAZO_RESTEASY) - ); - } - - /** - * Handler responsible for adding the subsystem resource to the model - */ - private static class SubsystemAdd extends AbstractBoottimeAddStepHandler { - - @Override - public void performBoottime(OperationContext context, ModelNode operation, Resource resource) { - - context.addStep(new AbstractDeploymentChainStep() { - public void execute(DeploymentProcessorTarget processorTarget) { - processorTarget.addDeploymentProcessor(MVCKrazoExtension.SUBSYSTEM_NAME, - DeploymentDependenciesProcessor.PHASE, - DeploymentDependenciesProcessor.PRIORITY, - new DeploymentDependenciesProcessor()); - } - }, OperationContext.Stage.RUNTIME); - - } - } - -} diff --git a/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemRegistrar.java b/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemRegistrar.java new file mode 100644 index 0000000..d27286e --- /dev/null +++ b/subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemRegistrar.java @@ -0,0 +1,59 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.wildfly.extension.mvc.krazo; + +import static org.wildfly.extension.mvc.krazo.MVCKrazoExtension.SUBSYSTEM_NAME; +import static org.wildfly.extension.mvc.krazo.MVCKrazoExtension.SUBSYSTEM_PATH; + +import org.jboss.as.controller.ResourceDefinition; +import org.jboss.as.controller.ResourceRegistration; +import org.jboss.as.controller.SubsystemRegistration; +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.RuntimePackageDependency; +import org.jboss.as.server.DeploymentProcessorTarget; +import org.wildfly.subsystem.resource.ManagementResourceRegistrar; +import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext; +import org.wildfly.subsystem.resource.ResourceDescriptor; +import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar; + +/** + * Resource definition for the mvc-krazo subsystem root resource. + * + * @author Brian Stansberry + */ +final class MVCKrazoSubsystemRegistrar implements SubsystemResourceDefinitionRegistrar { + + static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME, MVCKrazoSubsystemRegistrar.class); + + static final String MVC_API = "jakarta.mvc.api"; + static final String KRAZO_CORE = "org.eclipse.krazo.core"; + static final String KRAZO_RESTEASY = "org.eclipse.krazo.resteasy"; + + @Override + public ManagementResourceRegistration register(SubsystemRegistration parent, ManagementResourceRegistrationContext managementResourceRegistrationContext) { + ResourceDefinition definition = ResourceDefinition.builder(ResourceRegistration.of(SUBSYSTEM_PATH), RESOLVER).build(); + ManagementResourceRegistration registration = parent.registerSubsystemModel(definition); + ResourceDescriptor descriptor = ResourceDescriptor.builder(RESOLVER) + .withDeploymentChainContributor(MVCKrazoSubsystemRegistrar::registerDeploymentUnitProcessors) + .build(); + ManagementResourceRegistrar.of(descriptor).register(registration); + registration.registerAdditionalRuntimePackages( + RuntimePackageDependency.required(MVC_API), + RuntimePackageDependency.required(KRAZO_CORE), + RuntimePackageDependency.required(KRAZO_RESTEASY) + ); + return registration; + } + + private static void registerDeploymentUnitProcessors(DeploymentProcessorTarget processorTarget) { + processorTarget.addDeploymentProcessor(MVCKrazoExtension.SUBSYSTEM_NAME, + DeploymentDependenciesProcessor.PHASE, + DeploymentDependenciesProcessor.PRIORITY, + new DeploymentDependenciesProcessor()); + } + +} diff --git a/subsystem/src/main/resources/schema/wildfly-mvc-krazo_preview_1_1.xsd b/subsystem/src/main/resources/schema/wildfly-mvc-krazo_preview_1_1.xsd new file mode 100644 index 0000000..19f9f0e --- /dev/null +++ b/subsystem/src/main/resources/schema/wildfly-mvc-krazo_preview_1_1.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + diff --git a/subsystem/src/test/java/org/wildfly/extension/mvc/krazo/SubsystemTestCase.java b/subsystem/src/test/java/org/wildfly/extension/mvc/krazo/SubsystemTestCase.java index d524cbe..182ce54 100644 --- a/subsystem/src/test/java/org/wildfly/extension/mvc/krazo/SubsystemTestCase.java +++ b/subsystem/src/test/java/org/wildfly/extension/mvc/krazo/SubsystemTestCase.java @@ -4,26 +4,40 @@ */ package org.wildfly.extension.mvc.krazo; -import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; +import static org.wildfly.extension.mvc.krazo.MVCKrazoExtension.SUBSYSTEM_NAME; +import static org.wildfly.extension.mvc.krazo.MVCKrazoExtension.MVCKrazoSubsystemSchema.CURRENT; import java.io.IOException; +import java.util.EnumSet; + +import org.jboss.as.subsystem.test.AbstractSubsystemSchemaTest; +import org.jboss.as.version.Stability; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; /** - * This is the bare bones test example that tests subsystem + * Standard subsystem test. * * @author Brian Stansberry */ -public class SubsystemTestCase extends AbstractSubsystemBaseTest { +@RunWith(Parameterized.class) +public class SubsystemTestCase extends AbstractSubsystemSchemaTest { - public SubsystemTestCase() { - super(MVCKrazoExtension.SUBSYSTEM_NAME, new MVCKrazoExtension()); + @Parameterized.Parameters + public static Iterable parameters() { + return EnumSet.allOf(MVCKrazoExtension.MVCKrazoSubsystemSchema.class); } - - @Override - protected String getSubsystemXml() throws IOException { - return "" + - ""; + public SubsystemTestCase(MVCKrazoExtension.MVCKrazoSubsystemSchema schema) { + super(SUBSYSTEM_NAME, new MVCKrazoExtension(), schema, CURRENT); } + protected String getSubsystemXsdPath() throws Exception { + if (getSubsystemSchema() == MVCKrazoExtension.MVCKrazoSubsystemSchema.VERSION_1_0_LEGACY) { + // Provide the xsd file name we used with WF Preview 31 + return "schema/mvc-krazo_1.0.xsd"; + } else { + return super.getSubsystemXsdPath(); + } + } } diff --git a/subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.0.xml b/subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.0.xml new file mode 100644 index 0000000..63e86ad --- /dev/null +++ b/subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.0.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.1.xml b/subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.1.xml new file mode 100644 index 0000000..23e549f --- /dev/null +++ b/subsystem/src/test/resources/org/wildfly/extension/mvc/krazo/mvc-krazo-preview-1.1.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/testsuite/tck/pom.xml b/testsuite/tck/pom.xml index 8aa2698..857cff3 100644 --- a/testsuite/tck/pom.xml +++ b/testsuite/tck/pom.xml @@ -187,6 +187,7 @@ org.wildfly.extension.mvc.krazo.tck.WildFlyArchiveProvider ${server.jvm.args} + --stability=preview ${surefire.system.args} diff --git a/testsuite/tck/src/test/resources/arquillian.xml b/testsuite/tck/src/test/resources/arquillian.xml index b3e8350..b9b273f 100644 --- a/testsuite/tck/src/test/resources/arquillian.xml +++ b/testsuite/tck/src/test/resources/arquillian.xml @@ -12,6 +12,7 @@ ${jboss.home} ${server.jvm.args} ${jboss.server.config.file.name:standalone.xml} + ${server.jboss.args} 127.0.0.1 9990 true