Skip to content

Commit

Permalink
[Issue_14] Refactor the subsystem to use wildfly-subsystem
Browse files Browse the repository at this point in the history
This brings also the stability=preview concept into the xml handling
  • Loading branch information
bstansberry committed Mar 19, 2024
1 parent 9254f2c commit 41939cf
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<module name="org.jboss.as.ee"/>
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.version"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.logging"/>
<module name="org.wildfly.subsystem"/>
</dependencies>
</module>
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem</artifactId>
<version>${version.org.wildfly.core}</version>
<exclusions>
<exclusion>
<groupId>org.wildfly.core</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-version</artifactId>
<version>${version.org.wildfly.core}</version>
<exclusions>
<exclusion>
<groupId>org.wildfly.core</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ee</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions subsystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-version</artifactId>
</dependency>

<dependency>
<groupId>org.wildfly.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,103 +6,110 @@

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;


/**
* WildFly extension that provides Jakarta MVC support based on Eclipse Krazo.
*
* @author <a href="mailto:[email protected]">Brian Stansberry</a>
*/
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<MVCKrazoExtension.MVCKrazoSubsystemSchema> {

/**
* 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<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {
public enum MVCKrazoSubsystemSchema implements PersistentSubsystemSchema<MVCKrazoSubsystemSchema> {

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<IntVersion, MVCKrazoSubsystemSchema> 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<IntVersion, MVCKrazoSubsystemSchema> getNamespace() {
return this.namespace;
}

/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> 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();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 <a href="mailto:[email protected]">Brian Stansberry</a>
*/
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());
}

}
Loading

0 comments on commit 41939cf

Please sign in to comment.