From 572a4d467c8ab312b786aad8f6c32d1bb0f4f100 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Sat, 21 Dec 2024 17:38:07 -0500 Subject: [PATCH] [WFCORE-7111] Prepare org.jboss.as.server.deployment.Attachments for removal of ModuleIdentifier --- .../as/server/deployment/Attachments.java | 32 ++++++++++++++++++- .../annotation/CompositeIndexProcessor.java | 9 ++++++ .../module/ModuleIdentifierProcessor.java | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/jboss/as/server/deployment/Attachments.java b/server/src/main/java/org/jboss/as/server/deployment/Attachments.java index 1a99d32b01c..6728bb3bfa9 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/Attachments.java +++ b/server/src/main/java/org/jboss/as/server/deployment/Attachments.java @@ -121,8 +121,13 @@ public final class Attachments { public static final AttachmentKey MANIFEST = AttachmentKey.create(Manifest.class); /** - * Module identifiers for Class-Path information + * Module identifiers for Class-Path information. + *

+ * Note: This is only meant for use within the server kernel. + * + * @deprecated this will either be changed incompatibly (to provide a string) or removed altogether in the next WildFly Core major. */ + @Deprecated(forRemoval = true) public static final AttachmentKey> CLASS_PATH_ENTRIES = AttachmentKey.createList(ModuleIdentifier.class); /** @@ -191,10 +196,27 @@ public final class Attachments { */ public static final AttachmentKey> ADDITIONAL_MODULES = AttachmentKey.createList(AdditionalModuleSpecification.class); + /** + * A list of modules for which annotation indexes should be prepared (or, in later phases, have been prepared). + * + * @deprecated this will either be changed incompatibly (to provide a list of string) or removed altogether in the next WildFly Core major. + */ + @Deprecated(forRemoval = true) public static final AttachmentKey> ADDITIONAL_ANNOTATION_INDEXES = AttachmentKey.createList(ModuleIdentifier.class); + /** + * Annotation indices, keyed by the identifier of the module from which they were obtained. + * + * @deprecated use {@link #ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE_NAME} + */ + @Deprecated(forRemoval = true) public static final AttachmentKey> ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE = AttachmentKey.create(Map.class); + /** + * Annotation indices, keyed by the canonical name module from which they were obtained. + */ + public static final AttachmentKey> ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE_NAME = AttachmentKey.create(Map.class); + public static final AttachmentKey> DEPLOYMENT_OVERLAY_LOCATIONS = AttachmentKey.create(Map.class); /** @@ -237,9 +259,17 @@ public final class Attachments { // /** * The module identifier. + * + * @deprecated use {@link #MODULE_NAME} */ + @Deprecated(forRemoval = true) public static final AttachmentKey MODULE_IDENTIFIER = AttachmentKey.create(ModuleIdentifier.class); + /** + * The canonical name of the module. + */ + public static final AttachmentKey MODULE_NAME = AttachmentKey.create(String.class); + // // MODULARIZE // diff --git a/server/src/main/java/org/jboss/as/server/deployment/annotation/CompositeIndexProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/annotation/CompositeIndexProcessor.java index ed2f43cdb73..4515a160b0a 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/annotation/CompositeIndexProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/annotation/CompositeIndexProcessor.java @@ -9,6 +9,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -118,6 +119,14 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro } } deploymentUnit.putAttachment(Attachments.ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE, additionalAnnotationIndexes); + // Attach an additional map keyed by name. Next release this key will be the only map attached. + Map additionalIndexesByName = new HashMap<>(additionalAnnotationIndexes.size()); + for (Map.Entry entry : additionalAnnotationIndexes.entrySet()) { + additionalIndexesByName.put(entry.getKey().toString(), entry.getValue()); + } + deploymentUnit.putAttachment(Attachments.ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE_NAME, + // This should have always been an immutable map + Collections.unmodifiableMap(additionalIndexesByName)); final List allResourceRoots = new ArrayList(); final List resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS); diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleIdentifierProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleIdentifierProcessor.java index 09f83a4eea4..8671069f622 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleIdentifierProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleIdentifierProcessor.java @@ -29,6 +29,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro final VirtualFile toplevelRoot = topLevelDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot(); final ModuleIdentifier moduleIdentifier = createModuleIdentifier(deploymentUnit.getName(), deploymentRoot, topLevelDeployment, toplevelRoot, deploymentUnit.getParent() == null); deploymentUnit.putAttachment(Attachments.MODULE_IDENTIFIER, moduleIdentifier); + deploymentUnit.putAttachment(Attachments.MODULE_NAME, moduleIdentifier.toString()); } public static ModuleIdentifier createModuleIdentifier(final String deploymentUnitName, final ResourceRoot deploymentRoot, final DeploymentUnit topLevelDeployment, final VirtualFile toplevelRoot, final boolean topLevel) {