Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-7118] Provide an alternative to Attachments.ADDITIONAL_ANNOTATION_INDEXES #6306

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<AttachmentList<ModuleIdentifier>> 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<AttachmentList<String>> ADDITIONAL_INDEX_MODULES = AttachmentKey.createList(String.class);

/**
* Annotation indices, keyed by the identifier of the module from which they were obtained.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,26 @@ 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>();
final List<ModuleIdentifier> additionalModuleIndexes = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES);
final List<Index> indexes = new ArrayList<Index>();

Map<ModuleIdentifier, DeploymentUnit> subdeploymentDependencies = buildSubdeploymentDependencyMap(deploymentUnit);
// 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<String> additionalModuleIndexes = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_INDEX_MODULES);

Map<String, CompositeIndex> additionalAnnotationIndexes = new HashMap<>();
final List<Index> indexes = new ArrayList<>();
Map<String, DeploymentUnit> subdeploymentDependencies = buildSubdeploymentDependencyMap(deploymentUnit);

for (final ModuleIdentifier moduleIdentifier : additionalModuleIndexes) {
AdditionalModuleSpecification additional = additionalModuleSpecificationMap.get(moduleIdentifier);
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
// or jboss-deployment-structure.xml or equivalent jboss-all.xml content. Obtain indexes from its resources.
Expand All @@ -78,16 +86,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 +108,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 +164,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 All @@ -20,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;

Expand Down Expand Up @@ -52,13 +52,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 +84,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_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.toString()));
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId));
}
}

Expand Down
Loading
Loading