From 8fb905974f2341d8ca1d4a3bd21e06aaa1c93e38 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Sat, 28 Dec 2024 09:29:39 -0500 Subject: [PATCH 1/2] [WFCORE-7127] Replace Attachments.CLASS_PATH_ENTRIES --- .../jboss/as/server/deployment/Attachments.java | 17 +++-------------- .../org/jboss/as/server/deployment/Phase.java | 2 +- .../module/ManifestClassPathProcessor.java | 15 +++++++++++---- .../module/ModuleClassPathProcessor.java | 13 ++++++------- 4 files changed, 21 insertions(+), 26 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..83aadb04b11 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 @@ -38,7 +38,6 @@ /** * @author David M. Lloyd */ -@SuppressWarnings("deprecation") public final class Attachments { // @@ -120,19 +119,9 @@ public final class Attachments { */ public static final AttachmentKey MANIFEST = AttachmentKey.create(Manifest.class); - /** - * 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); - /** * Resource roots for additional modules referenced via Class-Path. - * + *

* These are attached to the resource root that actually defined the class path entry, and are used to transitively resolve * the annotation index for class path items. */ @@ -231,7 +220,7 @@ public final class Attachments { /** * A service target that can be used to install services outside the scope of the deployment. - * + *

* These services will not be removed automatically on undeploy, so if this is used some other strategy must be used * to handle undeployment. */ @@ -296,7 +285,7 @@ public final class Attachments { /** * Sub deployments that are visible from this deployments module loader, in the order they are accessible. - * + *

* This list includes the current deployment, which under normal circumstances will be the first item in the list */ public static final AttachmentKey> ACCESSIBLE_SUB_DEPLOYMENTS = AttachmentKey.createList(DeploymentUnit.class); diff --git a/server/src/main/java/org/jboss/as/server/deployment/Phase.java b/server/src/main/java/org/jboss/as/server/deployment/Phase.java index 1620df0dc1c..63aa8530daa 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/Phase.java +++ b/server/src/main/java/org/jboss/as/server/deployment/Phase.java @@ -85,7 +85,7 @@ public enum Phase { *

* In this phase, these phase attachments may be modified: *

*

diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java index 2f725031b23..02fb2953ce2 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java @@ -17,6 +17,8 @@ import java.util.jar.Manifest; import org.jboss.as.controller.ModuleIdentifierUtil; +import org.jboss.as.server.deployment.AttachmentKey; +import org.jboss.as.server.deployment.AttachmentList; import org.jboss.as.server.logging.ServerLogger; import org.jboss.as.server.deployment.Attachable; import org.jboss.as.server.deployment.Attachments; @@ -57,6 +59,11 @@ */ public final class ManifestClassPathProcessor implements DeploymentUnitProcessor { + /** + * Module identifiers for Class-Path information. + */ + static final AttachmentKey> CLASS_PATH_MODULES = AttachmentKey.createList(String.class); + private static final String[] EMPTY_STRING_ARRAY = {}; /** @@ -148,7 +155,7 @@ public synchronized void deploy(final DeploymentPhaseContext phaseContext) throw if (item.startsWith("/")) { if (externalModuleService.isValidFile(item)) { final ModuleIdentifier moduleIdentifier = externalModuleService.addExternalModule(item, phaseContext.getServiceRegistry(), externalServiceTarget); - target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, moduleIdentifier); + target.addToAttachmentList(CLASS_PATH_MODULES, moduleIdentifier.toString()); ServerLogger.DEPLOYMENT_LOGGER.debugf("Resource %s added as external jar %s", classPathFile, resourceRoot.getRoot()); } else { ServerLogger.DEPLOYMENT_LOGGER.classPathEntryNotValid(item, resourceRoot.getRoot().getPathName()); @@ -197,16 +204,16 @@ private void handlingExistingClassPathEntry(final ArrayDeque resource } else if (additionalModules.containsKey(classPathFile)) { final AdditionalModuleSpecification moduleSpecification = additionalModules.get(classPathFile); //as class path entries are exported, transitive dependencies will also be available - target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifier.fromString(moduleSpecification.getModuleName())); + target.addToAttachmentList(CLASS_PATH_MODULES, moduleSpecification.getModuleName()); } else if (subDeployments.containsKey(classPathFile)) { //now we need to calculate the sub deployment module identifier //unfortunately the sub deployment has not been setup yet, so we cannot just //get it from the sub deployment directly final ResourceRoot otherRoot = subDeployments.get(classPathFile); - target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifierProcessor.createModuleIdentifier(otherRoot.getRootName(), otherRoot, topLevelDeployment, topLevelRoot, false)); + target.addToAttachmentList(CLASS_PATH_MODULES, ModuleIdentifierProcessor.createModuleIdentifier(otherRoot.getRootName(), otherRoot, topLevelDeployment, topLevelRoot, false).toString()); } else { String identifier = createAdditionalModule(resourceRoot, topLevelDeployment, topLevelRoot, additionalModules, classPathFile, resourceRoots); - target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifier.fromString(identifier)); + target.addToAttachmentList(CLASS_PATH_MODULES, identifier); } } diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleClassPathProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleClassPathProcessor.java index 0adf79f897e..5a4023a9775 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleClassPathProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleClassPathProcessor.java @@ -13,7 +13,6 @@ import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; -import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoader; /** @@ -29,26 +28,26 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER); - final AttachmentList entries = deploymentUnit.getAttachment(Attachments.CLASS_PATH_ENTRIES); + final AttachmentList entries = deploymentUnit.getAttachment(ManifestClassPathProcessor.CLASS_PATH_MODULES); if (entries != null) { - for (ModuleIdentifier entry : entries) { + for (String entry : entries) { //class path items are always exported to make transitive dependencies work - moduleSpecification.addLocalDependency(ModuleDependency.Builder.of(moduleLoader, entry.toString()).setExport(true).setImportServices(true).build()); + moduleSpecification.addLocalDependency(ModuleDependency.Builder.of(moduleLoader, entry).setExport(true).setImportServices(true).build()); } } final List additionalModules = deploymentUnit.getAttachment(Attachments.ADDITIONAL_MODULES); if (additionalModules != null) { for (AdditionalModuleSpecification additionalModule : additionalModules) { - final AttachmentList dependencies = additionalModule.getAttachment(Attachments.CLASS_PATH_ENTRIES); + final AttachmentList dependencies = additionalModule.getAttachment(ManifestClassPathProcessor.CLASS_PATH_MODULES); if (dependencies == null || dependencies.isEmpty()) { continue; } // additional modules export any class-path entries // this means that a module that references the additional module // gets access to the transitive closure of its call-path entries - for (ModuleIdentifier entry : dependencies) { - additionalModule.addLocalDependency(ModuleDependency.Builder.of(moduleLoader, entry.toString()).setExport(true).setImportServices(true).build()); + for (String entry : dependencies) { + additionalModule.addLocalDependency(ModuleDependency.Builder.of(moduleLoader, entry).setExport(true).setImportServices(true).build()); } // add a dependency on the top ear itself for good measure additionalModule.addLocalDependency(ModuleDependency.Builder.of(moduleLoader, deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER).toString()).setImportServices(true).build()); From f0b607f51eb982067d403d9abefecdba6241c718 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Wed, 15 Jan 2025 16:04:43 -0600 Subject: [PATCH 2/2] Fix IDE warns in ManifestClassPathProcessor --- .../module/ManifestClassPathProcessor.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java index 02fb2953ce2..12e1794a0d2 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/ManifestClassPathProcessor.java @@ -85,9 +85,9 @@ public synchronized void deploy(final DeploymentPhaseContext phaseContext) throw //These are resource roots that are already accessible by default //such as ear/lib jars an web-inf/lib jars - final Set existingAccessibleRoots = new HashSet(); + final Set existingAccessibleRoots = new HashSet<>(); - final Map subDeployments = new HashMap(); + final Map subDeployments = new HashMap<>(); for (ResourceRoot root : DeploymentUtils.allResourceRoots(topLevelDeployment)) { if (SubDeploymentMarker.isSubDeployment(root)) { subDeployments.put(root.getRoot(), root); @@ -98,7 +98,7 @@ public synchronized void deploy(final DeploymentPhaseContext phaseContext) throw } } - final ArrayDeque resourceRoots = new ArrayDeque(); + final ArrayDeque resourceRoots = new ArrayDeque<>(); if (deploymentUnit.getParent() != null) { //top level deployments already had their exiting roots processed above for (ResourceRoot root : DeploymentUtils.allResourceRoots(deploymentUnit)) { @@ -120,10 +120,9 @@ public synchronized void deploy(final DeploymentPhaseContext phaseContext) throw // build a map of the additional module locations // note that if a resource root has been added to two different additional modules // and is then referenced via a Class-Path entry the behaviour is undefined - final Map additionalModules = new HashMap(); + final Map additionalModules = new HashMap<>(); final List additionalModuleList = topLevelDeployment.getAttachmentList(Attachments.ADDITIONAL_MODULES); // Must synchronize on list as subdeployments executing Phase.STRUCTURE may be concurrently modifying it - //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (additionalModuleList) { for (AdditionalModuleSpecification module : additionalModuleList) { for (ResourceRoot additionalModuleResourceRoot : module.getResourceRoots()) { @@ -259,7 +258,6 @@ private static String[] getClassPathEntries(final ResourceRoot resourceRoot) { * * @param file The file for which the resource root will be created * @return Returns the created {@link ResourceRoot} - * @throws java.io.IOException */ private synchronized ResourceRoot createResourceRoot(final VirtualFile file, final DeploymentUnit deploymentUnit, final VirtualFile deploymentRoot) throws DeploymentUnitProcessingException { try { @@ -283,7 +281,7 @@ private synchronized ResourceRoot createResourceRoot(final VirtualFile file, fin } } - private class RootEntry { + private static class RootEntry { private final ResourceRoot resourceRoot; private final Attachable target;