Skip to content

Commit

Permalink
[WFCORE-6750] Integrate the unstable api annotation scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
kabir committed Jun 21, 2024
1 parent 5846028 commit 6ddb03e
Show file tree
Hide file tree
Showing 63 changed files with 2,610 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ public class ModelDescriptionConstants {
public static final String TYPE = "type";
public static final String UDP = "udp";
public static final String UNDEFINE_ATTRIBUTE_OPERATION = "undefine-attribute";
public static final String UNSTABLE_API_ANNOTATIONS = "unstable-api-annotations";
public static final String UNDEPLOY = "undeploy";
public static final String UNREADABLE_CHILDREN = "unreadable-children";
public static final String UPLOAD_DEPLOYMENT_BYTES = "upload-deployment-bytes";
Expand Down
5 changes: 5 additions & 0 deletions core-feature-pack/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-elytron-x500-principal</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.unstable.api.annotation</groupId>
<artifactId>unstable-api-annotation-classpath-indexer</artifactId>
</dependency>


<dependency>
<groupId>org.wildfly.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Comment to include file
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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="org.wildfly._internal.unstable-api-annotation-index">

<properties>
<property name="jboss.api" value="private"/>
</properties>

<resources>
<resource-root path="content"></resource-root>
</resources>

<exports>
<include path="*"/>
<include path="**/*"/>
</exports>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
<dependencies>
<!-- for java.beans -->
<module name="java.desktop"/>
<module name="io.smallrye.jandex"/>
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.server" />
<module name="org.jboss.as.version" />
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/>
<module name="org.jboss.staxmapper"/>
<module name="org.jboss.vfs" services="import"/>
<module name="org.wildfly.extension.core-management-client"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.service"/>
<module name="org.wildfly.unstable.annotation.api.indexer"/>
<module name="org.wildfly._internal.unstable-api-annotation-index"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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="org.wildfly.unstable.annotation.api.indexer">
<properties>
<property name="jboss.api" value="private"/>
</properties>

<resources>
<artifact name="${org.wildfly.unstable.api.annotation:unstable-api-annotation-classpath-indexer}"/>
</resources>

<dependencies>
<module name="org.jboss.logging"/>
<module name="io.smallrye.jandex"/>
</dependencies>
</module>
5 changes: 5 additions & 0 deletions core-management/core-management-subsystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.wildfly.unstable.api.annotation</groupId>
<artifactId>unstable-api-annotation-classpath-indexer</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.PersistentResourceXMLDescriptionWriter;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
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.registry.ManagementResourceRegistration;

import java.util.EnumSet;

/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2016 Red Hat inc.
*/
public class CoreManagementExtension implements Extension {
public static final String SUBSYSTEM_NAME = "core-management";
static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);
public static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);
static final PathElement PROCESS_STATE_LISTENER_PATH = PathElement.pathElement("process-state-listener");

static final String RESOURCE_NAME = CoreManagementExtension.class.getPackage().getName() + ".LocalDescriptions";

private static final ModelVersion CURRENT_VERSION = ModelVersion.create(1, 0, 0);
static final ModelVersion VERSION_1_0_0 = ModelVersion.create(1, 0, 0);

static final ModelVersion CURRENT_VERSION = VERSION_1_0_0;

public static ResourceDescriptionResolver getResourceDescriptionResolver(final String... keyPrefix) {
StringBuilder prefix = new StringBuilder(SUBSYSTEM_NAME);
Expand All @@ -44,7 +49,7 @@ public static ResourceDescriptionResolver getResourceDescriptionResolver(final S
@Override
public void initialize(ExtensionContext context) {
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_VERSION);
subsystem.registerXMLElementWriter(CoreManagementSubsystemParser_1_0::new);
subsystem.registerXMLElementWriter(new PersistentResourceXMLDescriptionWriter(CoreManagementSubsystemSchema_1_0.ALL.get(context.getStability())));
//This subsystem should be runnable on a host
subsystem.setHostCapable();
ManagementResourceRegistration registration = subsystem.registerSubsystemModel(new CoreManagementRootResourceDefinition());
Expand All @@ -53,8 +58,6 @@ public void initialize(ExtensionContext context) {

@Override
public void initializeParsers(ExtensionParsingContext context) {
// For the current version we don't use a Supplier as we want its description initialized
// TODO if any new xsd versions are added, use a Supplier for the old version
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, CoreManagementSubsystemParser_1_0.NAMESPACE, new CoreManagementSubsystemParser_1_0());
context.setSubsystemXmlMappings(CoreManagementExtension.SUBSYSTEM_NAME, EnumSet.allOf(CoreManagementSubsystemSchema_1_0.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,31 @@
package org.wildfly.extension.core.management;


import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.wildfly.extension.core.management.UnstableApiAnnotationResourceDefinition.UnstableApiAnnotationLevel;
import org.wildfly.extension.core.management.deployment.ReportUnstableApiAnnotationsProcessor;
import org.wildfly.extension.core.management.deployment.ScanUnstableApiAnnotationsProcessor;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelOnlyAddStepHandler;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import static org.jboss.as.server.deployment.Phase.PARSE;
import static org.jboss.as.server.deployment.Phase.PARSE_REPORT_EXPERIMENTAL_ANNOTATIONS;
import static org.jboss.as.server.deployment.Phase.PARSE_SCAN_EXPERIMENTAL_ANNOTATIONS;
import static org.wildfly.extension.core.management.CoreManagementExtension.SUBSYSTEM_NAME;

/**
* {@link org.jboss.as.controller.ResourceDefinition} for the core-management subsystem root resource.
Expand All @@ -26,7 +42,7 @@ class CoreManagementRootResourceDefinition extends PersistentResourceDefinition
CoreManagementRootResourceDefinition() {
super(CoreManagementExtension.SUBSYSTEM_PATH,
CoreManagementExtension.getResourceDescriptionResolver(),
ModelOnlyAddStepHandler.INSTANCE,
new CoreManagementAddHandler(),
ReloadRequiredRemoveStepHandler.INSTANCE);
}

Expand All @@ -38,7 +54,40 @@ public Collection<AttributeDefinition> getAttributes() {
@Override
protected List<? extends PersistentResourceDefinition> getChildren() {
return Arrays.asList(ConfigurationChangeResourceDefinition.INSTANCE,
new ProcessStateListenerResourceDefinition()
new ProcessStateListenerResourceDefinition(),
UnstableApiAnnotationResourceDefinition.INSTANCE
);
}

private static class CoreManagementAddHandler extends AbstractBoottimeAddStepHandler {

@Override
protected void performBoottime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {

if (context.isNormalServer()) {
context.addStep(new AbstractDeploymentChainStep() {
@Override
protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_SCAN_EXPERIMENTAL_ANNOTATIONS,
new ScanUnstableApiAnnotationsProcessor(context.getRunningMode(), context.getStability(), UnstableApiAnnotationService.LEVEL_SUPPLIER));
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_REPORT_EXPERIMENTAL_ANNOTATIONS,
new ReportUnstableApiAnnotationsProcessor(UnstableApiAnnotationService.LEVEL_SUPPLIER));
}
}, OperationContext.Stage.RUNTIME);
}

Resource unstableApiResource = resource.getChild(UnstableApiAnnotationResourceDefinition.PATH);
UnstableApiAnnotationLevel level = null;
if (unstableApiResource != null) {
ModelNode model = unstableApiResource.getModel();
String levelValue = UnstableApiAnnotationResourceDefinition.LEVEL.resolveModelAttribute(context, model).asString();
level = UnstableApiAnnotationLevel.valueOf(levelValue);
}

ServiceBuilder<?> sb = context.getCapabilityServiceTarget().addService();
Consumer<UnstableApiAnnotationService> serviceConsumer = sb.provides(UnstableApiAnnotationService.SERVICE_NAME);
sb.setInstance(new UnstableApiAnnotationService(serviceConsumer, level));
sb.install();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.extension.core.management;

import org.jboss.as.controller.Feature;
import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentSubsystemSchema;
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 java.util.EnumSet;
import java.util.Map;

/**
* Parser and Marshaller for core-management subsystem.
*
* <em>All resources and attributes must be listed explicitly and not through any collections.</em>
* This ensures that if the resource definitions change in later version (e.g. a new attribute is added),
* this will have no impact on parsing this specific version of the subsystem.
*
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2016 Red Hat inc.
*/
public enum CoreManagementSubsystemSchema_1_0 implements PersistentSubsystemSchema<CoreManagementSubsystemSchema_1_0> {

VERSION_1_0(1),
VERSION_1_0_PREVIEW(1, Stability.PREVIEW);
static final Map<Stability, CoreManagementSubsystemSchema_1_0> ALL = Feature.map(EnumSet.of(VERSION_1_0, VERSION_1_0_PREVIEW));

private final VersionedNamespace<IntVersion, CoreManagementSubsystemSchema_1_0> namespace;

CoreManagementSubsystemSchema_1_0(int major) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(CoreManagementExtension.SUBSYSTEM_NAME, new IntVersion(major, 0));
}

CoreManagementSubsystemSchema_1_0(int major, Stability stability) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(CoreManagementExtension.SUBSYSTEM_NAME, stability, new IntVersion(major, 0));
}

@Override
public VersionedNamespace<IntVersion, CoreManagementSubsystemSchema_1_0> getNamespace() {
return this.namespace;
}

@Override
public PersistentResourceXMLDescription getXMLDescription() {
PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this);
PersistentResourceXMLDescription.Builder builder = factory.builder(CoreManagementExtension.SUBSYSTEM_PATH);
builder.addChild(
factory.builder(ConfigurationChangeResourceDefinition.PATH)
.addAttribute(ConfigurationChangeResourceDefinition.MAX_HISTORY)
.build());
builder.addChild(
factory.builder(UnstableApiAnnotationResourceDefinition.RESOURCE_REGISTRATION)
.addAttribute(UnstableApiAnnotationResourceDefinition.LEVEL)
.build());
builder.addChild(
factory.builder(CoreManagementExtension.PROCESS_STATE_LISTENER_PATH)

.addAttribute(ProcessStateListenerResourceDefinition.LISTENER_CLASS)
.addAttribute(ProcessStateListenerResourceDefinition.LISTENER_MODULE)
.addAttribute(ProcessStateListenerResourceDefinition.PROPERTIES)
.addAttribute(ProcessStateListenerResourceDefinition.TIMEOUT)
.build());
return builder.build();
}
}
Loading

0 comments on commit 6ddb03e

Please sign in to comment.