From 63a3d1f38074eb69c8c6f821c025e7b0671f9932 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Sun, 22 Dec 2024 14:47:15 -0500 Subject: [PATCH] [WFCORE-7115] Remove use of ModuleIdentifier from AdditionalModuleSpecification --- .../annotation/CompositeIndexProcessor.java | 49 +++++++++---------- .../module/AdditionalModuleSpecification.java | 27 +++++----- .../module/ManifestClassPathProcessor.java | 11 +++-- .../module/ManifestDependencyProcessor.java | 13 ++--- .../module/ModuleSpecProcessor.java | 12 ++--- .../DeploymentStructureDescriptorParser.java | 42 ++++++++++------ .../JBossDeploymentStructureParser10.java | 3 +- .../JBossDeploymentStructureParser11.java | 3 +- .../JBossDeploymentStructureParser12.java | 3 +- .../JBossDeploymentStructureParser13.java | 3 +- .../descriptor/ModuleStructureSpec.java | 10 ++-- .../jboss/as/server/logging/ServerLogger.java | 2 +- .../moduleservice/ModuleLoadService.java | 8 +-- 13 files changed, 99 insertions(+), 87 deletions(-) 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 338f9df0647..b8409fe2f7b 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 @@ -53,18 +53,19 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro return; } DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent(); - Map additionalModuleSpecificationMap = new HashMap<>(); + Map additionalModuleSpecificationMap = new HashMap<>(); for(AdditionalModuleSpecification i : top.getAttachmentList(Attachments.ADDITIONAL_MODULES)) { - additionalModuleSpecificationMap.put(i.getModuleIdentifier(), i); + additionalModuleSpecificationMap.put(i.getModuleName(), i); } - Map additionalAnnotationIndexes = new HashMap(); + Map additionalAnnotationIndexes = new HashMap<>(); final List additionalModuleIndexes = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES); final List indexes = new ArrayList(); - Map subdeploymentDependencies = buildSubdeploymentDependencyMap(deploymentUnit); + Map subdeploymentDependencies = buildSubdeploymentDependencyMap(deploymentUnit); for (final ModuleIdentifier moduleIdentifier : additionalModuleIndexes) { - AdditionalModuleSpecification additional = additionalModuleSpecificationMap.get(moduleIdentifier); + String moduleName = moduleIdentifier.toString(); + 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 // or jboss-deployment-structure.xml or equivalent jboss-all.xml content. Obtain indexes from its resources. @@ -78,16 +79,16 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro } } if (!moduleIndexes.isEmpty()) { - additionalAnnotationIndexes.put(moduleIdentifier, new CompositeIndex(moduleIndexes)); + additionalAnnotationIndexes.put(moduleName, new CompositeIndex(moduleIndexes)); } - } else if (subdeploymentDependencies.containsKey(moduleIdentifier)) { + } else if (subdeploymentDependencies.containsKey(moduleName)) { // This module id refers to a subdeployment. Find the indices for its resources. - List resourceRoots = subdeploymentDependencies.get(moduleIdentifier).getAttachment(Attachments.RESOURCE_ROOTS); + List resourceRoots = subdeploymentDependencies.get(moduleName).getAttachment(Attachments.RESOURCE_ROOTS); final List allResourceRoots = new ArrayList<>(); if (resourceRoots != null) { allResourceRoots.addAll(resourceRoots); } - final ResourceRoot deploymentRoot = subdeploymentDependencies.get(moduleIdentifier).getAttachment(Attachments.DEPLOYMENT_ROOT); + final ResourceRoot deploymentRoot = subdeploymentDependencies.get(moduleName).getAttachment(Attachments.DEPLOYMENT_ROOT); if (ModuleRootMarker.isModuleRoot(deploymentRoot)) { allResourceRoots.add(deploymentRoot); } @@ -100,33 +101,31 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro } } if (!moduleIndexes.isEmpty()) { - additionalAnnotationIndexes.put(moduleIdentifier, new CompositeIndex(moduleIndexes)); + additionalAnnotationIndexes.put(moduleName, new CompositeIndex(moduleIndexes)); } } else { // This module id refers to a module external to the deployment. Get the indices from the support object. CompositeIndex externalModuleIndexes; AnnotationIndexSupport annotationIndexSupport = indexSupportRef.get(); if (annotationIndexSupport != null) { - externalModuleIndexes = annotationIndexSupport.getAnnotationIndices(moduleIdentifier.toString(), moduleLoader); + externalModuleIndexes = annotationIndexSupport.getAnnotationIndices(moduleName, moduleLoader); } else { // This implies the DeploymentUnitService was restarted after the original operation that held // the strong ref to the AnnotationIndexSupport. So we can't benefit from caching. Just calculate // the indices without worrying about caching. - externalModuleIndexes = AnnotationIndexSupport.indexModule(moduleIdentifier.toString(), moduleLoader); + externalModuleIndexes = AnnotationIndexSupport.indexModule(moduleName, moduleLoader); } indexes.addAll(externalModuleIndexes.indexes); - additionalAnnotationIndexes.put(moduleIdentifier, externalModuleIndexes); + additionalAnnotationIndexes.put(moduleName, externalModuleIndexes); } } - 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, Collections.unmodifiableMap(additionalAnnotationIndexes)); + // For compatibility attach an additional map keyed by ModuleIdentifier. TODO remove this key and stop doing this. + Map additionalIndexesByModId = new HashMap<>(additionalAnnotationIndexes.size()); + for (Map.Entry entry : additionalAnnotationIndexes.entrySet()) { + additionalIndexesByModId.put(ModuleIdentifier.fromString(entry.getKey()), entry.getValue()); } - deploymentUnit.putAttachment(Attachments.ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE_NAME, - // This should have always been an immutable map - Collections.unmodifiableMap(additionalIndexesByName)); + deploymentUnit.putAttachment(Attachments.ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE, additionalIndexesByModId); final List allResourceRoots = new ArrayList(); final List resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS); @@ -158,19 +157,19 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro deploymentUnit.putAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX, new CompositeIndex(indexes)); } - private Map buildSubdeploymentDependencyMap(DeploymentUnit deploymentUnit) { + private Map buildSubdeploymentDependencyMap(DeploymentUnit deploymentUnit) { Set depModuleIdentifiers = new HashSet<>(); for (ModuleDependency dep: deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION).getAllDependencies()) { depModuleIdentifiers.add(dep.getDependencyModule()); } DeploymentUnit top = deploymentUnit.getParent()==null?deploymentUnit:deploymentUnit.getParent(); - Map res = new HashMap<>(); + Map res = new HashMap<>(); AttachmentList subDeployments = top.getAttachment(Attachments.SUB_DEPLOYMENTS); if (subDeployments != null) { for (DeploymentUnit subDeployment : subDeployments) { - ModuleIdentifier moduleIdentifier = subDeployment.getAttachment(Attachments.MODULE_IDENTIFIER); - if (depModuleIdentifiers.contains(moduleIdentifier.toString())) { + String moduleIdentifier = subDeployment.getAttachment(Attachments.MODULE_NAME); + if (depModuleIdentifiers.contains(moduleIdentifier)) { res.put(moduleIdentifier, subDeployment); } } diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/AdditionalModuleSpecification.java b/server/src/main/java/org/jboss/as/server/deployment/module/AdditionalModuleSpecification.java index f08aeaeb642..091b4047c91 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/AdditionalModuleSpecification.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/AdditionalModuleSpecification.java @@ -10,7 +10,6 @@ import java.util.List; import org.jboss.as.server.deployment.Attachable; -import org.jboss.modules.ModuleIdentifier; /** @@ -21,37 +20,35 @@ */ public class AdditionalModuleSpecification extends ModuleSpecification implements Attachable { - private final ModuleIdentifier moduleIdentifier; + private final String moduleName; private final List resourceRoots; - public AdditionalModuleSpecification(ModuleIdentifier moduleIdentifier, ResourceRoot resourceRoot) { - this.moduleIdentifier = moduleIdentifier; - this.resourceRoots = new ArrayList(); + public AdditionalModuleSpecification(String moduleName, ResourceRoot resourceRoot) { + this.moduleName = moduleName; + this.resourceRoots = new ArrayList<>(2); this.resourceRoots.add(resourceRoot); } - public AdditionalModuleSpecification(ModuleIdentifier moduleIdentifier, Collection resourceRoots) { - this.moduleIdentifier = moduleIdentifier; - this.resourceRoots = new ArrayList(resourceRoots); - } - - /** @deprecated use {@link #getModuleName()} */ - @Deprecated(forRemoval = true) - public ModuleIdentifier getModuleIdentifier() { - return moduleIdentifier; + public AdditionalModuleSpecification(String moduleName, Collection resourceRoots) { + this.moduleName = moduleName; + this.resourceRoots = new ArrayList<>(resourceRoots); } public String getModuleName() { - return moduleIdentifier.toString(); + return moduleName; } + /** @deprecated unused method will be removed */ + @Deprecated(forRemoval = true) public void addResourceRoot(ResourceRoot resourceRoot) { this.resourceRoots.add(resourceRoot); } + /** @deprecated unused method will be removed */ + @Deprecated(forRemoval = true) public void addResourceRoots(Collection resourceRoots) { this.resourceRoots.addAll(resourceRoots); } 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 de009d1d7cb..2f725031b23 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 @@ -16,6 +16,7 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; +import org.jboss.as.controller.ModuleIdentifierUtil; import org.jboss.as.server.logging.ServerLogger; import org.jboss.as.server.deployment.Attachable; import org.jboss.as.server.deployment.Attachments; @@ -196,7 +197,7 @@ 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, moduleSpecification.getModuleIdentifier()); + target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifier.fromString(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 @@ -204,15 +205,15 @@ private void handlingExistingClassPathEntry(final ArrayDeque resource final ResourceRoot otherRoot = subDeployments.get(classPathFile); target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifierProcessor.createModuleIdentifier(otherRoot.getRootName(), otherRoot, topLevelDeployment, topLevelRoot, false)); } else { - ModuleIdentifier identifier = createAdditionalModule(resourceRoot, topLevelDeployment, topLevelRoot, additionalModules, classPathFile, resourceRoots); - target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, identifier); + String identifier = createAdditionalModule(resourceRoot, topLevelDeployment, topLevelRoot, additionalModules, classPathFile, resourceRoots); + target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifier.fromString(identifier)); } } - private ModuleIdentifier createAdditionalModule(final ResourceRoot resourceRoot, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map additionalModules, final VirtualFile classPathFile, final ArrayDeque resourceRoots) throws DeploymentUnitProcessingException { + private String createAdditionalModule(final ResourceRoot resourceRoot, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map additionalModules, final VirtualFile classPathFile, final ArrayDeque resourceRoots) throws DeploymentUnitProcessingException { final ResourceRoot root = createResourceRoot(classPathFile, topLevelDeployment, topLevelRoot); final String pathName = root.getRoot().getPathNameRelativeTo(topLevelRoot); - ModuleIdentifier identifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + "." + pathName); + String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + "." + pathName, null); AdditionalModuleSpecification module = new AdditionalModuleSpecification(identifier, root); topLevelDeployment.addToAttachmentList(Attachments.ADDITIONAL_MODULES, module); additionalModules.put(classPathFile, module); 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 824ab7bff7a..614ffe99ab0 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 @@ -10,6 +10,7 @@ import java.util.Set; import java.util.jar.Manifest; +import org.jboss.as.controller.ModuleIdentifierUtil; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; @@ -52,13 +53,13 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU final List allResourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit); DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent(); - final Set additionalModules = new HashSet<>(); + final Set additionalModules = new HashSet<>(); final List additionalModuleList = top.getAttachmentList(Attachments.ADDITIONAL_MODULES); // Must synchronize on list as subdeployments executing Phase.STRUCTURE may be concurrently modifying it //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (additionalModuleList) { for (AdditionalModuleSpecification i : additionalModuleList) { - additionalModules.add(i.getModuleIdentifier()); + additionalModules.add(i.getModuleName()); } } for (final ResourceRoot resourceRoot : allResourceRoots) { @@ -84,23 +85,23 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU } final String[] dependencyParts = trimmed.split(" "); - final ModuleIdentifier dependencyId = ModuleIdentifier.fromString(dependencyParts[0]); + final String dependencyId = ModuleIdentifierUtil.canonicalModuleIdentifier(dependencyParts[0]); final boolean export = containsParam(dependencyParts, EXPORT_PARAM); final boolean optional = containsParam(dependencyParts, OPTIONAL_PARAM); final boolean services = containsParam(dependencyParts, SERVICES_PARAM); final boolean annotations = containsParam(dependencyParts, ANNOTATIONS_PARAM); final boolean metaInf = containsParam(dependencyParts, META_INF); final ModuleLoader dependencyLoader; - if (dependencyId.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX)) { + if (dependencyId.startsWith(ServiceModuleLoader.MODULE_PREFIX)) { dependencyLoader = deploymentModuleLoader; } else { dependencyLoader = Module.getBootModuleLoader(); } if(annotations) { - deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, dependencyId); + deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, ModuleIdentifier.fromString(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.toString())); + phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId)); } } diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecProcessor.java index b0e149dce0f..70d16a9c2a2 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecProcessor.java @@ -112,7 +112,7 @@ private void deployModuleSpec(final DeploymentPhaseContext phaseContext) throws } } - final ModuleIdentifier moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER); + final String moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_NAME); if (moduleIdentifier == null) { throw ServerLogger.ROOT_LOGGER.noModuleIdentifier(deploymentUnit.getName()); } @@ -134,7 +134,7 @@ private void deployModuleSpec(final DeploymentPhaseContext phaseContext) throws for (final AdditionalModuleSpecification module : additionalModules) { addAllDependenciesAndPermissions(moduleSpec, module); List roots = module.getResourceRoots(); - ServiceName serviceName = createModuleService(phaseContext, deploymentUnit, roots, parentResourceRoots, module, module.getModuleIdentifier()); + ServiceName serviceName = createModuleService(phaseContext, deploymentUnit, roots, parentResourceRoots, module, module.getModuleName()); phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, serviceName); } } @@ -152,7 +152,7 @@ private void addAllDependenciesAndPermissions(final ModuleSpecification moduleSp module.addSystemDependencies(moduleSpecification.getSystemDependenciesSet()); module.addLocalDependencies(moduleSpecification.getLocalDependenciesSet()); for(ModuleDependency dep : moduleSpecification.getUserDependenciesSet()) { - if(!dep.getDependencyModule().equals(module.getModuleIdentifier().toString())) { + if(!dep.getDependencyModule().equals(module.getModuleName())) { module.addUserDependency(dep); } } @@ -199,7 +199,7 @@ private void addAllDependenciesAndPermissions(final ModuleSpecification moduleSp private ServiceName createModuleService(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit, final List resourceRoots, final List parentResourceRoots, - final ModuleSpecification moduleSpecification, final ModuleIdentifier moduleIdentifier) throws DeploymentUnitProcessingException { + final ModuleSpecification moduleSpecification, final String moduleIdentifier) throws DeploymentUnitProcessingException { logger.debugf("Creating module: %s", moduleIdentifier); final ModuleSpec.Builder specBuilder = ModuleSpec.build(moduleIdentifier); for (final DependencySpec dep : moduleSpecification.getModuleSystemDependencies()) { @@ -278,14 +278,14 @@ private ServiceName createModuleService(final DeploymentPhaseContext phaseContex return ModuleLoadService.install(phaseContext.getServiceTarget(), moduleIdentifier, dependencies, localDependencies, userDependencies); } - private void installAliases(final ModuleSpecification moduleSpecification, final ModuleIdentifier moduleIdentifier, final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext) { + private void installAliases(final ModuleSpecification moduleSpecification, final String moduleIdentifier, final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext) { ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER); for (final String aliasName : moduleSpecification.getModuleAliases()) { final ModuleIdentifier alias = ModuleIdentifier.fromString(aliasName); final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(alias.toString()); - final ModuleSpec spec = ModuleSpec.buildAlias(aliasName, moduleIdentifier.toString()).create(); + final ModuleSpec spec = ModuleSpec.buildAlias(aliasName, moduleIdentifier).create(); HashSet dependencies = new HashSet<>(moduleSpecification.getAllDependencies()); //we need to add the module we are aliasing as a dependency, to make sure that it will be resolved 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 5e2e37469a7..51d9c99ea23 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 @@ -115,13 +115,13 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU //if the parent has already attached parsed data for this sub deployment we need to process it if (deploymentRoot.hasAttachment(SUB_DEPLOYMENT_STRUCTURE)) { final ModuleSpecification subModuleSpec = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); - Map additionalModules = new HashMap<>(); + Map additionalModules = new HashMap<>(); final List additionalModuleList = deploymentUnit.getParent().getAttachmentList(Attachments.ADDITIONAL_MODULES); // Must synchronize on list as subdeployments executing Phase.STRUCTURE may be concurrently modifying it //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (additionalModuleList) { for (AdditionalModuleSpecification i : additionalModuleList) { - additionalModules.put(i.getModuleIdentifier(), i); + additionalModules.put(i.getModuleName(), i); } } handleDeployment(phaseContext, deploymentUnit, subModuleSpec, deploymentRoot.getAttachment(SUB_DEPLOYMENT_STRUCTURE), additionalModules); @@ -155,11 +155,11 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU result = parse(deploymentFile.getPhysicalFile(), deploymentUnit, moduleLoader); } // handle additional modules - Map additionalModules = new HashMap<>(); + Map additionalModules = new HashMap<>(); for (final ModuleStructureSpec additionalModule : result.getAdditionalModules()) { for (final ModuleIdentifier identifier : additionalModule.getAnnotationModules()) { //additional modules don't support annotation imports - ServerLogger.DEPLOYMENT_LOGGER.annotationImportIgnored(identifier, additionalModule.getModuleIdentifier()); + ServerLogger.DEPLOYMENT_LOGGER.annotationImportIgnored(identifier, additionalModule.getModuleName()); } //log a warning if the resource root is wrong final List additionalModuleResourceRoots = new ArrayList(additionalModule.getResourceRoots()); @@ -171,10 +171,10 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU itr.remove(); } } - final AdditionalModuleSpecification additional = new AdditionalModuleSpecification(additionalModule.getModuleIdentifier(), additionalModuleResourceRoots); + final AdditionalModuleSpecification additional = new AdditionalModuleSpecification(additionalModule.getModuleName(), additionalModuleResourceRoots); additional.addAliases(additionalModule.getAliases()); additional.addSystemDependencies(additionalModule.getModuleDependencies()); - additionalModules.put(additional.getModuleIdentifier(), additional); + additionalModules.put(additional.getModuleName(), additional); deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_MODULES, additional); for (final ResourceRoot root : additionalModuleResourceRoots) { ResourceRootIndexer.indexResourceRoot(root); @@ -227,7 +227,10 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU } } - private void handleDeployment(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit, final ModuleSpecification moduleSpec, final ModuleStructureSpec rootDeploymentSpecification, final Map additionalModules) throws DeploymentUnitProcessingException { + private void handleDeployment(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit, + final ModuleSpecification moduleSpec, final ModuleStructureSpec rootDeploymentSpecification, + final Map additionalModules) + throws DeploymentUnitProcessingException { final Map resourceRoots = resourceRoots(deploymentUnit); // handle unmodifiable module dependencies with alias List moduleDependencies = rootDeploymentSpecification.getModuleDependencies(); @@ -243,10 +246,15 @@ private void handleDeployment(final DeploymentPhaseContext phaseContext, final D } } // No more nested loop + ModuleDependency moduleDependency; for (ModuleDependency dependency : moduleDependencies) { String identifier = dependency.getDependencyModule(); if (index.containsKey(identifier)) { - aliasDependencies.add(new ModuleDependency(dependency.getModuleLoader(), index.get(identifier).getModuleIdentifier(), dependency.isOptional(), dependency.isExport(), dependency.isImportServices(), dependency.isUserSpecified())); + moduleDependency = ModuleDependency.Builder.of(dependency.getModuleLoader(), index.get(identifier).getModuleName()) + .setOptional(dependency.isOptional()).setExport(dependency.isExport()) + .setImportServices(dependency.isImportServices()).setUserSpecified(dependency.isUserSpecified()) + .build(); + aliasDependencies.add(moduleDependency); } } @@ -277,18 +285,20 @@ private void handleDeployment(final DeploymentPhaseContext phaseContext, final D } // handle annotations for (final ModuleIdentifier dependency : rootDeploymentSpecification.getAnnotationModules()) { - ModuleIdentifier identifier = dependency; + String identifier = dependency.toString(); + boolean aliased = false; for (AdditionalModuleSpecification module : additionalModules.values()) { - if (module.getModuleAliases().contains(dependency.toString())) { - identifier = module.getModuleIdentifier(); + if (module.getModuleAliases().contains(identifier)) { + identifier = module.getModuleName(); + aliased = true; break; } } - deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, identifier); + deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, aliased ? ModuleIdentifier.fromString(identifier) : dependency); // additional modules will not be created till much later, a dep on them would fail - if (identifier.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX) && + if (identifier.startsWith(ServiceModuleLoader.MODULE_PREFIX) && !(additionalModules.containsKey(identifier) || isSubdeployment(identifier, deploymentUnit))) { - phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(identifier.toString())); + phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(identifier)); } } moduleSpec.setLocalLast(rootDeploymentSpecification.isLocalLast()); @@ -298,9 +308,9 @@ private void handleDeployment(final DeploymentPhaseContext phaseContext, final D } } - private boolean isSubdeployment(ModuleIdentifier dependency, DeploymentUnit deploymentUnit) { + private boolean isSubdeployment(String dependency, DeploymentUnit deploymentUnit) { DeploymentUnit top = deploymentUnit.getParent()==null?deploymentUnit:deploymentUnit.getParent(); - return dependency.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX.concat(top.getName())); + return dependency.startsWith(ServiceModuleLoader.MODULE_PREFIX.concat(top.getName())); } private Map resourceRoots(final DeploymentUnit deploymentUnit) { diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser10.java b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser10.java index 6e1dba23de3..ef9ac127bf0 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser10.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/descriptor/JBossDeploymentStructureParser10.java @@ -22,6 +22,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.jboss.as.controller.ModuleIdentifierUtil; import org.jboss.as.server.logging.ServerLogger; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; @@ -280,7 +281,7 @@ private static void parseModule(final XMLStreamReader reader, final ParseResult throw ServerLogger.ROOT_LOGGER.invalidModuleName(name); } ModuleStructureSpec moduleSpecification = new ModuleStructureSpec(); - moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot)); + moduleSpecification.setModuleName(ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot)); result.getAdditionalModules().add(moduleSpecification); parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader()); } 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 782d270d77c..b6d15aa296e 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 @@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.jboss.as.controller.ModuleIdentifierUtil; import org.jboss.as.server.logging.ServerLogger; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; @@ -296,7 +297,7 @@ private static void parseModule(XMLStreamReader reader, ParseResult result) thro throw ServerLogger.ROOT_LOGGER.invalidModuleName(name); } final ModuleStructureSpec moduleSpecification = new ModuleStructureSpec(); - moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot)); + moduleSpecification.setModuleName(ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot)); result.getAdditionalModules().add(moduleSpecification); parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader()); } 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 bc4f994703c..765b21e1270 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 @@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.jboss.as.controller.ModuleIdentifierUtil; import org.jboss.as.server.logging.ServerLogger; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; @@ -300,7 +301,7 @@ private static void parseModule(XMLStreamReader reader, ParseResult result) thro throw ServerLogger.ROOT_LOGGER.invalidModuleName(name); } final ModuleStructureSpec moduleSpecification = new ModuleStructureSpec(); - moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot)); + moduleSpecification.setModuleName(ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot)); result.getAdditionalModules().add(moduleSpecification); parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader()); } 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 5dec3f9b308..4a4c5e4da8b 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 @@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.jboss.as.controller.ModuleIdentifierUtil; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.MountedDeploymentOverlay; @@ -310,7 +311,7 @@ private static void parseModule(XMLStreamReader reader, ParseResult result) thro throw ServerLogger.ROOT_LOGGER.invalidModuleName(name); } final ModuleStructureSpec moduleSpecification = new ModuleStructureSpec(); - moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot)); + moduleSpecification.setModuleName(ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot)); result.getAdditionalModules().add(moduleSpecification); parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader()); } 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 dd71bead8ae..3699e7cf294 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 @@ -21,7 +21,7 @@ */ class ModuleStructureSpec { - private ModuleIdentifier moduleIdentifier; + private String moduleName; private final List moduleDependencies = new ArrayList(); private final List systemDependencies = new ArrayList(); private final List resourceRoots = new ArrayList(); @@ -43,12 +43,12 @@ class ModuleStructureSpec { private boolean localLast = false; - public ModuleIdentifier getModuleIdentifier() { - return moduleIdentifier; + public String getModuleName() { + return moduleName; } - public void setModuleIdentifier(ModuleIdentifier moduleIdentifier) { - this.moduleIdentifier = moduleIdentifier; + public void setModuleName(String moduleName) { + this.moduleName = moduleName; } public void addModuleDependency(ModuleDependency dependency) { 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 0522743a530..b9807a84aef 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, ModuleIdentifier additionalModuleId); + void annotationImportIgnored(ModuleIdentifier 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.") diff --git a/server/src/main/java/org/jboss/as/server/moduleservice/ModuleLoadService.java b/server/src/main/java/org/jboss/as/server/moduleservice/ModuleLoadService.java index d710bf1deae..b6912084138 100644 --- a/server/src/main/java/org/jboss/as/server/moduleservice/ModuleLoadService.java +++ b/server/src/main/java/org/jboss/as/server/moduleservice/ModuleLoadService.java @@ -130,14 +130,14 @@ public static ServiceName install(final ServiceTarget target, final ModuleIdenti return install(target, identifier.toString(), service); } - public static ServiceName install(final ServiceTarget target, final ModuleIdentifier identifier, final Collection systemDependencies, final Collection localDependencies, final Collection userDependencies) { + public static ServiceName install(final ServiceTarget target, final String identifier, final Collection systemDependencies, final Collection localDependencies, final Collection userDependencies) { final ModuleLoadService service = new ModuleLoadService(systemDependencies, localDependencies, userDependencies); - return install(target, identifier.toString(), service); + return install(target, identifier, service); } - public static ServiceName installAliases(final ServiceTarget target, final ModuleIdentifier identifier, final List aliases) { + public static ServiceName installAliases(final ServiceTarget target, final ModuleIdentifier identifier, final List aliases) { final ArrayList dependencies = new ArrayList(aliases.size()); - for (final ModuleIdentifier i : aliases) { + for (final String i : aliases) { dependencies.add(new ModuleDependency(null, i, false, false, false, false)); } final ModuleLoadService service = new ModuleLoadService(dependencies);