Search in sources :

Example 1 with JBoss70WebMetaData

use of org.jboss.metadata.web.jboss.JBoss70WebMetaData in project wildfly by wildfly.

the class EarContextRootProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        // Nothing we can do without WarMetaData
        return;
    }
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    if (deploymentRoot == null) {
        // We don't have a root to work with
        return;
    }
    final DeploymentUnit parent = deploymentUnit.getParent();
    if (parent == null || !DeploymentTypeMarker.isType(DeploymentType.EAR, parent)) {
        // Only care if this war is nested in an EAR
        return;
    }
    final EarMetaData earMetaData = parent.getAttachment(Attachments.EAR_METADATA);
    if (earMetaData == null) {
        // Nothing to see here
        return;
    }
    final ModulesMetaData modulesMetaData = earMetaData.getModules();
    if (modulesMetaData != null)
        for (ModuleMetaData moduleMetaData : modulesMetaData) {
            if (Web.equals(moduleMetaData.getType()) && moduleMetaData.getFileName().equals(deploymentRoot.getRootName())) {
                String contextRoot = WebModuleMetaData.class.cast(moduleMetaData.getValue()).getContextRoot();
                if (contextRoot == null && (warMetaData.getJBossWebMetaData() == null || warMetaData.getJBossWebMetaData().getContextRoot() == null)) {
                    contextRoot = "/" + parent.getName().substring(0, parent.getName().length() - 4) + "/" + deploymentUnit.getName().substring(0, deploymentUnit.getName().length() - 4);
                }
                if (contextRoot != null) {
                    JBossWebMetaData jBossWebMetaData = warMetaData.getJBossWebMetaData();
                    if (jBossWebMetaData == null) {
                        jBossWebMetaData = new JBoss70WebMetaData();
                        warMetaData.setJBossWebMetaData(jBossWebMetaData);
                    }
                    jBossWebMetaData.setContextRoot(contextRoot);
                }
                return;
            }
        }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) ModulesMetaData(org.jboss.metadata.ear.spec.ModulesMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) JBoss70WebMetaData(org.jboss.metadata.web.jboss.JBoss70WebMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) WebModuleMetaData(org.jboss.metadata.ear.spec.WebModuleMetaData) ModuleMetaData(org.jboss.metadata.ear.spec.ModuleMetaData)

Aggregations

DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1 WarMetaData (org.jboss.as.web.common.WarMetaData)1 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)1 ModuleMetaData (org.jboss.metadata.ear.spec.ModuleMetaData)1 ModulesMetaData (org.jboss.metadata.ear.spec.ModulesMetaData)1 WebModuleMetaData (org.jboss.metadata.ear.spec.WebModuleMetaData)1 JBoss70WebMetaData (org.jboss.metadata.web.jboss.JBoss70WebMetaData)1 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)1