Skip to content

Commit

Permalink
Merge pull request wildfly#18441 from RanabirChakraborty/WFLY-20022
Browse files Browse the repository at this point in the history
WFLY-20022 Remove all non-breaking uses of ModuleIdentifier in JSF Subsystem
  • Loading branch information
bstansberry authored Dec 15, 2024
2 parents 7fdec39 + bc9e952 commit 3edeef5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.jboss.metadata.javaee.spec.ParamValueMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
import org.jboss.modules.filter.PathFilters;
Expand All @@ -33,7 +32,7 @@
public class JSFDependencyProcessor implements DeploymentUnitProcessor {
public static final String IS_CDI_PARAM = "org.jboss.jbossfaces.IS_CDI";

private static final ModuleIdentifier JSF_SUBSYSTEM = ModuleIdentifier.create("org.jboss.as.jsf");
private static final String JSF_SUBSYSTEM = "org.jboss.as.jsf";
// We use . instead of / on this stream as a workaround to get it transformed correctly by Batavia into a Jakarta namespace
private static final String JAVAX_FACES_EVENT_NAMEDEVENT_class = "/jakarta.faces.event.NamedEvent".replaceAll("\\.", "/") + ".class";

Expand Down Expand Up @@ -93,7 +92,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
private void addJSFAPI(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) {
if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) return;

ModuleIdentifier jsfModule = moduleIdFactory.getApiModId(jsfVersion);
String jsfModule = moduleIdFactory.getApiModId(jsfVersion);
ModuleDependency jsfAPI = new ModuleDependency(moduleLoader, jsfModule, false, false, false, false);
moduleSpecification.addSystemDependency(jsfAPI);
}
Expand All @@ -103,7 +102,7 @@ private void addJSFImpl(String jsfVersion,
ModuleLoader moduleLoader) {
if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) return;

ModuleIdentifier jsfModule = moduleIdFactory.getImplModId(jsfVersion);
String jsfModule = moduleIdFactory.getImplModId(jsfVersion);
ModuleDependency jsfImpl = new ModuleDependency(moduleLoader, jsfModule, false, false, true, false);
jsfImpl.addImportFilter(PathFilters.getMetaInfFilter(), true);
moduleSpecification.addSystemDependency(jsfImpl);
Expand All @@ -113,7 +112,7 @@ private void addJSFInjection(String jsfVersion, ModuleSpecification moduleSpecif
throws DeploymentUnitProcessingException {
if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) return;

ModuleIdentifier jsfInjectionModule = moduleIdFactory.getInjectionModId(jsfVersion);
String jsfInjectionModule = moduleIdFactory.getInjectionModId(jsfVersion);
ModuleDependency jsfInjectionDependency = new ModuleDependency(moduleLoader, jsfInjectionModule, false, true, true, false);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.List;

import jakarta.faces.application.ViewHandler;
import org.jboss.as.controller.ModuleIdentifierUtil;
import org.jboss.as.jsf.logging.JSFLogger;
import org.jboss.as.jsf.subsystem.JSFResourceDefinition;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
Expand Down Expand Up @@ -72,8 +72,20 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro

String version = JsfVersionMarker.getVersion(deploymentUnit);
// Disable counter-productive "distributable" logic in Mojarra implementation
if (version.equals(JsfVersionMarker.JSF_4_0) && JSFModuleIdFactory.getInstance().getImplModId(version).getSlot().equals(JSFResourceDefinition.DEFAULT_SLOT)) {
setContextParameterIfAbsent(webMetaData, WebConfiguration.BooleanWebContextInitParameter.EnableDistributable.getQualifiedName(), Boolean.FALSE.toString());
if (version.equals(JsfVersionMarker.JSF_4_0)) {
// Retrieve the canonical module identifier string
String implModId = JSFModuleIdFactory.getInstance().getImplModId(version);

// Now compare the canonical module identifier (which doesn't include "main" as the slot)
String canonicalModId = ModuleIdentifierUtil.canonicalModuleIdentifier(implModId);
// Check if the canonical module identifier is for the "main" slot
if (canonicalModId != null && !canonicalModId.contains(":")) {
setContextParameterIfAbsent(
webMetaData,
WebConfiguration.BooleanWebContextInitParameter.EnableDistributable.getQualifiedName(),
Boolean.FALSE.toString()
);
}
}
}
// Set a default buffer size as 1024 is too small
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.jboss.as.jsf.logging.JSFLogger;
import org.jboss.as.jsf.subsystem.JSFResourceDefinition;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.as.controller.ModuleIdentifierUtil;

/**
* This class finds all the installed Jakarta Server Faces implementations and provides their ModuleId's.
Expand All @@ -34,9 +34,9 @@ public class JSFModuleIdFactory {
// The default JSF impl slot. This can be overridden by the management layer.
private String defaultSlot = JSFResourceDefinition.DEFAULT_SLOT;

private Map<String, ModuleIdentifier> apiIds = new HashMap<>();
private Map<String, ModuleIdentifier> implIds = new HashMap<>();
private Map<String, ModuleIdentifier> injectionIds = new HashMap<>();
private Map<String, String> apiIds = new HashMap<>();
private Map<String, String> implIds = new HashMap<>();
private Map<String, String> injectionIds = new HashMap<>();

private Set<String> allVersions = new HashSet<>();
private List<String> activeVersions = new ArrayList<>();
Expand Down Expand Up @@ -79,9 +79,9 @@ private boolean isBogusPath(String path) {

// just provide the default implementations
private void loadIdsManually() {
implIds.put("main", ModuleIdentifier.create(IMPL_MODULE));
apiIds.put("main", ModuleIdentifier.create(API_MODULE));
injectionIds.put("main", ModuleIdentifier.create(INJECTION_MODULE));
implIds.put("main", ModuleIdentifierUtil.canonicalModuleIdentifier(IMPL_MODULE, "main"));
apiIds.put("main", ModuleIdentifierUtil.canonicalModuleIdentifier(API_MODULE, "main"));
injectionIds.put("main", ModuleIdentifierUtil.canonicalModuleIdentifier(INJECTION_MODULE, "main"));

allVersions.add("main");

Expand All @@ -97,7 +97,7 @@ private void loadIdsFromModulePath(String modulePath) {
checkVersionIntegrity();
}

private void loadIds(String moduleRootDir, Map<String, ModuleIdentifier> idMap, String moduleName) {
private void loadIds(String moduleRootDir, Map<String, String> idMap, String moduleName) {
StringBuilder baseDirBuilder = new StringBuilder(moduleRootDir);
baseDirBuilder.append(File.separator);
baseDirBuilder.append(moduleName.replace(".", File.separator));
Expand All @@ -116,7 +116,7 @@ public boolean accept(File pathname) {
if (!new File(slot, "module.xml").exists()) continue; // make sure directory represents a real module
String slotName = slot.getName();
allVersions.add(slotName);
idMap.put(slotName, ModuleIdentifier.create(moduleName, slotName));
idMap.put(slotName, ModuleIdentifierUtil.canonicalModuleIdentifier(moduleName, slotName));
}
}

Expand Down Expand Up @@ -154,15 +154,15 @@ String computeSlot(String jsfVersion) {
return jsfVersion;
}

ModuleIdentifier getApiModId(String jsfVersion) {
String getApiModId(String jsfVersion) {
return this.apiIds.get(computeSlot(jsfVersion));
}

ModuleIdentifier getImplModId(String jsfVersion) {
String getImplModId(String jsfVersion) {
return this.implIds.get(computeSlot(jsfVersion));
}

ModuleIdentifier getInjectionModId(String jsfVersion) {
String getInjectionModId(String jsfVersion) {
return this.injectionIds.get(computeSlot(jsfVersion));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/
package org.jboss.as.jsf.deployment;

import static org.jboss.as.controller.ModuleIdentifierUtil.canonicalModuleIdentifier;

import java.util.List;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -50,27 +51,30 @@ public void validSlotTest() {
}

@Test
@Ignore("Depends on https://issues.redhat.com/browse/WFLY-17405")
public void modIdsTest() {
Assert.assertEquals(API_MODULE, factory.getApiModId("main").getName());
Assert.assertEquals("main", factory.getApiModId("main").getSlot());
Assert.assertEquals(IMPL_MODULE, factory.getImplModId("main").getName());
Assert.assertEquals("main", factory.getImplModId("main").getSlot());
Assert.assertEquals(INJECTION_MODULE, factory.getInjectionModId("main").getName());
Assert.assertEquals("main", factory.getInjectionModId("main").getSlot());

Assert.assertEquals(API_MODULE, factory.getApiModId("myfaces").getName());
Assert.assertEquals("myfaces", factory.getApiModId("myfaces").getSlot());
Assert.assertEquals(IMPL_MODULE, factory.getImplModId("myfaces").getName());
Assert.assertEquals("myfaces", factory.getImplModId("myfaces").getSlot());
Assert.assertEquals(INJECTION_MODULE, factory.getInjectionModId("myfaces").getName());
Assert.assertEquals("myfaces", factory.getInjectionModId("myfaces").getSlot());

Assert.assertEquals(API_MODULE, factory.getApiModId("myfaces2").getName());
Assert.assertEquals("myfaces2", factory.getApiModId("myfaces2").getSlot());
Assert.assertEquals(IMPL_MODULE, factory.getImplModId("myfaces2").getName());
Assert.assertEquals("myfaces2", factory.getImplModId("myfaces2").getSlot());
Assert.assertEquals(INJECTION_MODULE, factory.getInjectionModId("myfaces2").getName());
Assert.assertEquals("myfaces2", factory.getInjectionModId("myfaces2").getSlot());
String apiModIdMain = factory.getApiModId("main");
String implModIdMain = factory.getImplModId("main");
String injectionModIdMain = factory.getInjectionModId("main");


Assert.assertEquals(canonicalModuleIdentifier(API_MODULE, "main"), apiModIdMain);
Assert.assertEquals(canonicalModuleIdentifier(IMPL_MODULE, "main"), implModIdMain);
Assert.assertEquals(canonicalModuleIdentifier(INJECTION_MODULE, "main"), injectionModIdMain);

String apiModIdMyfaces = factory.getApiModId("myfaces");
String implModIdMyfaces = factory.getImplModId("myfaces");
String injectionModIdMyfaces = factory.getInjectionModId("myfaces");

Assert.assertEquals(canonicalModuleIdentifier(API_MODULE, "myfaces"), apiModIdMyfaces);
Assert.assertEquals(canonicalModuleIdentifier(IMPL_MODULE, "myfaces"), implModIdMyfaces);
Assert.assertEquals(canonicalModuleIdentifier(INJECTION_MODULE, "myfaces"), injectionModIdMyfaces);

String apiModIdMyfaces2 = factory.getApiModId("myfaces2");
String implModIdMyfaces2 = factory.getImplModId("myfaces2");
String injectionModIdMyfaces2 = factory.getInjectionModId("myfaces2");

Assert.assertEquals(canonicalModuleIdentifier(API_MODULE, "myfaces2"), apiModIdMyfaces2);
Assert.assertEquals(canonicalModuleIdentifier(IMPL_MODULE, "myfaces2"), implModIdMyfaces2);
Assert.assertEquals(canonicalModuleIdentifier(INJECTION_MODULE, "myfaces2"), injectionModIdMyfaces2);
}
}

0 comments on commit 3edeef5

Please sign in to comment.