Skip to content

Commit

Permalink
[WFCORE-7118] Provide an alternative to Attachments.ADDITIONAL_ANNOTA…
Browse files Browse the repository at this point in the history
…TION_INDEXES

[WFCORE-7136] Remove ModuleIdentifier use from JBossDeploymentStructureParser##
  • Loading branch information
bstansberry committed Jan 15, 2025
1 parent a245d5a commit d3c8038
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 26 deletions.
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 @@ -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<String, CompositeIndex> additionalAnnotationIndexes = new HashMap<>();
final List<ModuleIdentifier> additionalModuleIndexes = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES);
final List<Index> indexes = new ArrayList<Index>();

// 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) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
// handle additional modules
Map<String, AdditionalModuleSpecification> 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());
}
Expand Down Expand Up @@ -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))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ private static void parseModuleDependency(final XMLStreamReader reader, final Mo
if (!required.isEmpty()) {
throw missingAttributes(reader.getLocation(), required);
}
final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier.toString())
final String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier)
.setOptional(optional).setExport(export).setImportServices(services == Disposition.IMPORT).setUserSpecified(true).build();
specBuilder.addModuleDependency(dependency);
while (reader.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ private static void parseModuleDependency(final XMLStreamReader reader, final Mo
if (!required.isEmpty()) {
throw missingAttributes(reader.getLocation(), required);
}
final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier.toString())
final String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier)
.setOptional(optional).setExport(export).setImportServices(services == Disposition.IMPORT).setUserSpecified(true).build();
if(annotations) {
specBuilder.addAnnotationModule(identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ private static void parseModuleDependency(final XMLStreamReader reader, final Mo
if (!required.isEmpty()) {
throw missingAttributes(reader.getLocation(), required);
}
final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier.toString())
final String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier)
.setOptional(optional).setExport(export).setImportServices(services == Disposition.IMPORT).setUserSpecified(true).build();
if(annotations) {
specBuilder.addAnnotationModule(identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ private static void parseModuleDependency(final XMLStreamReader reader, final Mo
if (!required.isEmpty()) {
throw missingAttributes(reader.getLocation(), required);
}
final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier.toString())
final String identifier = ModuleIdentifierUtil.canonicalModuleIdentifier(name, slot);
ModuleDependency dependency = ModuleDependency.Builder.of(moduleLoader, identifier)
.setOptional(optional).setExport(export).setImportServices(services == Disposition.IMPORT).setUserSpecified(true).build();
if(annotations) {
specBuilder.addAnnotationModule(identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ModuleStructureSpec {
private final List<ModuleIdentifier> exclusions = new ArrayList<ModuleIdentifier>();
private final List<String> classTransformers = new ArrayList<String>();
private final List<ModuleIdentifier> aliases = new ArrayList<ModuleIdentifier>();
private final List<ModuleIdentifier> annotationModules = new ArrayList<ModuleIdentifier>();
private final List<String> annotationModules = new ArrayList<>();

/**
* Note that this being null is different to an empty list.
Expand Down Expand Up @@ -83,11 +83,11 @@ public List<ModuleIdentifier> getAliases() {
return Collections.unmodifiableList(aliases);
}

public void addAnnotationModule(final ModuleIdentifier dependency) {
public void addAnnotationModule(final String dependency) {
annotationModules.add(dependency);
}

public List<ModuleIdentifier> getAnnotationModules() {
public List<String> getAnnotationModules() {
return Collections.unmodifiableList(annotationModules);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit d3c8038

Please sign in to comment.