From 53c08bb0d7f2af636d9d8e6b87d704eeb835f42d Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Mon, 23 Dec 2024 09:05:28 -0500 Subject: [PATCH] [WFCORE-7118] Provide an alternative to Attachments.ADDITIONAL_ANNOTATION_INDEXES --- .../jboss/as/server/deployment/Attachments.java | 8 +++++++- .../annotation/CompositeIndexProcessor.java | 17 ++++++++++++----- .../module/ManifestDependencyProcessor.java | 3 +-- .../DeploymentStructureDescriptorParser.java | 10 ++++------ .../JBossDeploymentStructureParser11.java | 2 +- .../JBossDeploymentStructureParser12.java | 2 +- .../JBossDeploymentStructureParser13.java | 2 +- .../module/descriptor/ModuleStructureSpec.java | 6 +++--- .../jboss/as/server/logging/ServerLogger.java | 2 +- 9 files changed, 31 insertions(+), 21 deletions(-) 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 6728bb3bfa9..a56ae40269e 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 @@ -199,11 +199,17 @@ public final class Attachments { /** * 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 use {@link #ADDITIONAL_INDEX_MODULES} */ @Deprecated(forRemoval = true) public static final AttachmentKey> ADDITIONAL_ANNOTATION_INDEXES = AttachmentKey.createList(ModuleIdentifier.class); + /** + * A list of modules for which annotation indexes should be prepared (or, in later phases, have been prepared). + * + */ + public static final AttachmentKey> ADDITIONAL_INDEX_MODULES = AttachmentKey.createList(String.class); + /** * Annotation indices, keyed by the identifier of the module from which they were obtained. * 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 b8409fe2f7b..525011ef224 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 @@ -57,14 +57,21 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro for(AdditionalModuleSpecification i : top.getAttachmentList(Attachments.ADDITIONAL_MODULES)) { additionalModuleSpecificationMap.put(i.getModuleName(), i); } - Map additionalAnnotationIndexes = new HashMap<>(); - final List additionalModuleIndexes = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES); - final List indexes = new ArrayList(); + // Until we remove ADDITIONAL_ANNOTATION_INDEXES, pick up any index modules added by the full WF ee subsystem + // and store them in the ADDITIONAL_INDEX_MODULES list. Use addToAttachmentList to ensure the + // ADDITIONAL_INDEX_MODULES key gets initialized to an AttachmentList, in case it hasn't already been. + for (ModuleIdentifier mi: deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES)) { + deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_INDEX_MODULES, mi.toString()); + } + // Now we can use the ADDITIONAL_INDEX_MODULES list. + final List additionalModuleIndexes = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_INDEX_MODULES); + + Map additionalAnnotationIndexes = new HashMap<>(); + final List indexes = new ArrayList<>(); Map subdeploymentDependencies = buildSubdeploymentDependencyMap(deploymentUnit); - for (final ModuleIdentifier moduleIdentifier : additionalModuleIndexes) { - String moduleName = moduleIdentifier.toString(); + for (final String moduleName : additionalModuleIndexes) { AdditionalModuleSpecification additional = additionalModuleSpecificationMap.get(moduleName); if(additional != null) { // This module id refers to a deployment-specific module created based on a MANIFEST.MF Class-Path entry diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/ManifestDependencyProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/module/ManifestDependencyProcessor.java index 614ffe99ab0..3fc7bdd7f2f 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/ManifestDependencyProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/ManifestDependencyProcessor.java @@ -21,7 +21,6 @@ import org.jboss.as.server.deployment.SubDeploymentMarker; import org.jboss.as.server.moduleservice.ServiceModuleLoader; import org.jboss.modules.Module; -import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoader; import org.jboss.modules.filter.PathFilters; @@ -98,7 +97,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU dependencyLoader = Module.getBootModuleLoader(); } if(annotations) { - deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, ModuleIdentifier.fromString(dependencyId)); + deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_INDEX_MODULES, dependencyId); if(dependencyLoader == deploymentModuleLoader && !additionalModules.contains(dependencyId)) { //additional modules will not be created till much later, a dep on them would fail phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId)); diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/DeploymentStructureDescriptorParser.java b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/DeploymentStructureDescriptorParser.java index 51d9c99ea23..63c14bf4918 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/DeploymentStructureDescriptorParser.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/DeploymentStructureDescriptorParser.java @@ -157,7 +157,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU // handle additional modules Map additionalModules = new HashMap<>(); for (final ModuleStructureSpec additionalModule : result.getAdditionalModules()) { - for (final ModuleIdentifier identifier : additionalModule.getAnnotationModules()) { + for (final String identifier : additionalModule.getAnnotationModules()) { //additional modules don't support annotation imports ServerLogger.DEPLOYMENT_LOGGER.annotationImportIgnored(identifier, additionalModule.getModuleName()); } @@ -284,17 +284,15 @@ private void handleDeployment(final DeploymentPhaseContext phaseContext, final D moduleSpec.addClassTransformer(classTransformer); } // handle annotations - for (final ModuleIdentifier dependency : rootDeploymentSpecification.getAnnotationModules()) { - String identifier = dependency.toString(); - boolean aliased = false; + for (final String dependency : rootDeploymentSpecification.getAnnotationModules()) { + String identifier = dependency; for (AdditionalModuleSpecification module : additionalModules.values()) { if (module.getModuleAliases().contains(identifier)) { identifier = module.getModuleName(); - aliased = true; break; } } - deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, aliased ? ModuleIdentifier.fromString(identifier) : dependency); + deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_INDEX_MODULES, identifier); // additional modules will not be created till much later, a dep on them would fail if (identifier.startsWith(ServiceModuleLoader.MODULE_PREFIX) && !(additionalModules.containsKey(identifier) || isSubdeployment(identifier, deploymentUnit))) { diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser11.java b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser11.java index b6d15aa296e..5221daa2bb4 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser11.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser11.java @@ -598,7 +598,7 @@ private static void parseModuleDependency(final XMLStreamReader reader, final Mo if (!required.isEmpty()) { throw missingAttributes(reader.getLocation(), required); } - final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); + final String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot); final ModuleDependency dependency = new ModuleDependency(moduleLoader, identifier, optional, export, services == Disposition.IMPORT, true); if(annotations) { diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser12.java b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser12.java index 765b21e1270..416760e9692 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser12.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser12.java @@ -605,7 +605,7 @@ private static void parseModuleDependency(final XMLStreamReader reader, final Mo if (!required.isEmpty()) { throw missingAttributes(reader.getLocation(), required); } - final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); + final String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot); final ModuleDependency dependency = new ModuleDependency(moduleLoader, identifier, optional, export, services == Disposition.IMPORT, true); if(annotations) { diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser13.java b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser13.java index 4a4c5e4da8b..371f61f74f4 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser13.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser13.java @@ -615,7 +615,7 @@ private static void parseModuleDependency(final XMLStreamReader reader, final Mo if (!required.isEmpty()) { throw missingAttributes(reader.getLocation(), required); } - final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); + final String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot); final ModuleDependency dependency = new ModuleDependency(moduleLoader, identifier, optional, export, services == Disposition.IMPORT, true); if(annotations) { diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/ModuleStructureSpec.java b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/ModuleStructureSpec.java index 3699e7cf294..fc3401fb405 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/ModuleStructureSpec.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/ModuleStructureSpec.java @@ -29,7 +29,7 @@ class ModuleStructureSpec { private final List exclusions = new ArrayList(); private final List classTransformers = new ArrayList(); private final List aliases = new ArrayList(); - private final List annotationModules = new ArrayList(); + private final List annotationModules = new ArrayList<>(); /** * Note that this being null is different to an empty list. @@ -83,11 +83,11 @@ public List getAliases() { return Collections.unmodifiableList(aliases); } - public void addAnnotationModule(final ModuleIdentifier dependency) { + public void addAnnotationModule(final String dependency) { annotationModules.add(dependency); } - public List getAnnotationModules() { + public List getAnnotationModules() { return Collections.unmodifiableList(annotationModules); } diff --git a/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java b/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java index b9807a84aef..64eff640424 100644 --- a/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java +++ b/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java @@ -189,7 +189,7 @@ public interface ServerLogger extends BasicLogger { @LogMessage(level = WARN) @Message(id = 17, value = "Annotations import option %s specified in jboss-deployment-structure.xml for additional module %s has been ignored. Additional modules cannot import annotations.") - void annotationImportIgnored(ModuleIdentifier annotationModuleId, String additionalModuleId); + void annotationImportIgnored(String annotationModuleId, String additionalModuleId); @LogMessage(level = WARN) @Message(id = 18, value = "Deployment \"%s\" is using a private module (\"%s\") which may be changed or removed in future versions without notice.")