Skip to content

Commit

Permalink
[WFCORE-7115] Remove use of ModuleIdentifier from AdditionalModuleSpe…
Browse files Browse the repository at this point in the history
…cification
  • Loading branch information
bstansberry committed Dec 27, 2024
1 parent 1983240 commit 63a3d1f
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
return;
}
DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
Map<ModuleIdentifier, AdditionalModuleSpecification> additionalModuleSpecificationMap = new HashMap<>();
Map<String, AdditionalModuleSpecification> additionalModuleSpecificationMap = new HashMap<>();
for(AdditionalModuleSpecification i : top.getAttachmentList(Attachments.ADDITIONAL_MODULES)) {
additionalModuleSpecificationMap.put(i.getModuleIdentifier(), i);
additionalModuleSpecificationMap.put(i.getModuleName(), i);
}
Map<ModuleIdentifier, CompositeIndex> additionalAnnotationIndexes = new HashMap<ModuleIdentifier, CompositeIndex>();
Map<String, CompositeIndex> additionalAnnotationIndexes = new HashMap<>();
final List<ModuleIdentifier> additionalModuleIndexes = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES);
final List<Index> indexes = new ArrayList<Index>();

Map<ModuleIdentifier, DeploymentUnit> subdeploymentDependencies = buildSubdeploymentDependencyMap(deploymentUnit);
Map<String, DeploymentUnit> 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.
Expand All @@ -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<ResourceRoot> resourceRoots = subdeploymentDependencies.get(moduleIdentifier).getAttachment(Attachments.RESOURCE_ROOTS);
List<ResourceRoot> resourceRoots = subdeploymentDependencies.get(moduleName).getAttachment(Attachments.RESOURCE_ROOTS);
final List<ResourceRoot> 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);
}
Expand All @@ -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<String, CompositeIndex> additionalIndexesByName = new HashMap<>(additionalAnnotationIndexes.size());
for (Map.Entry<ModuleIdentifier, CompositeIndex> 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<ModuleIdentifier, CompositeIndex> additionalIndexesByModId = new HashMap<>(additionalAnnotationIndexes.size());
for (Map.Entry<String, CompositeIndex> 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<ResourceRoot> allResourceRoots = new ArrayList<ResourceRoot>();
final List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
Expand Down Expand Up @@ -158,19 +157,19 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
deploymentUnit.putAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX, new CompositeIndex(indexes));
}

private Map<ModuleIdentifier, DeploymentUnit> buildSubdeploymentDependencyMap(DeploymentUnit deploymentUnit) {
private Map<String, DeploymentUnit> buildSubdeploymentDependencyMap(DeploymentUnit deploymentUnit) {
Set<String> 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<ModuleIdentifier, DeploymentUnit> res = new HashMap<>();
Map<String, DeploymentUnit> res = new HashMap<>();
AttachmentList<DeploymentUnit> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;

import org.jboss.as.server.deployment.Attachable;
import org.jboss.modules.ModuleIdentifier;


/**
Expand All @@ -21,37 +20,35 @@
*/
public class AdditionalModuleSpecification extends ModuleSpecification implements Attachable {

private final ModuleIdentifier moduleIdentifier;
private final String moduleName;

private final List<ResourceRoot> resourceRoots;

public AdditionalModuleSpecification(ModuleIdentifier moduleIdentifier, ResourceRoot resourceRoot) {
this.moduleIdentifier = moduleIdentifier;
this.resourceRoots = new ArrayList<ResourceRoot>();
public AdditionalModuleSpecification(String moduleName, ResourceRoot resourceRoot) {
this.moduleName = moduleName;
this.resourceRoots = new ArrayList<>(2);
this.resourceRoots.add(resourceRoot);
}

public AdditionalModuleSpecification(ModuleIdentifier moduleIdentifier, Collection<ResourceRoot> resourceRoots) {
this.moduleIdentifier = moduleIdentifier;
this.resourceRoots = new ArrayList<ResourceRoot>(resourceRoots);
}

/** @deprecated use {@link #getModuleName()} */
@Deprecated(forRemoval = true)
public ModuleIdentifier getModuleIdentifier() {
return moduleIdentifier;
public AdditionalModuleSpecification(String moduleName, Collection<ResourceRoot> 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<ResourceRoot> resourceRoots) {
this.resourceRoots.addAll(resourceRoots);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,23 +197,23 @@ private void handlingExistingClassPathEntry(final ArrayDeque<RootEntry> 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
//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));
} 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<VirtualFile, AdditionalModuleSpecification> additionalModules, final VirtualFile classPathFile, final ArrayDeque<RootEntry> resourceRoots) throws DeploymentUnitProcessingException {
private String createAdditionalModule(final ResourceRoot resourceRoot, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map<VirtualFile, AdditionalModuleSpecification> additionalModules, final VirtualFile classPathFile, final ArrayDeque<RootEntry> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,13 +53,13 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
final List<ResourceRoot> allResourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit);
DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();

final Set<ModuleIdentifier> additionalModules = new HashSet<>();
final Set<String> additionalModules = new HashSet<>();
final List<AdditionalModuleSpecification> 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) {
Expand All @@ -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));
}
}

Expand Down
Loading

0 comments on commit 63a3d1f

Please sign in to comment.