use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class WebFragmentParsingDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
if (webFragments == null) {
webFragments = new HashMap<String, WebFragmentMetaData>();
warMetaData.setWebFragmentsMetaData(webFragments);
}
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
VirtualFile webFragment = resourceRoot.getRoot().getChild(WEB_FRAGMENT_XML);
if (webFragment.exists() && webFragment.isFile()) {
InputStream is = null;
try {
is = webFragment.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
WebFragmentMetaData webFragmentMetaData = WebFragmentMetaDataParser.parse(xmlReader, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
webFragments.put(resourceRoot.getRootName(), webFragmentMetaData);
/*Log message to inform that distributable is not set in web-fragment.xml while it is set in web.xml*/
if (warMetaData.getWebMetaData() != null && warMetaData.getWebMetaData().getDistributable() != null && webFragmentMetaData.getDistributable() == null)
UndertowLogger.ROOT_LOGGER.distributableDisabledInFragmentXml(deploymentUnit.getName(), resourceRoot.getRootName());
} catch (XMLStreamException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webFragment.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()));
} catch (IOException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webFragment.toString()), e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// Ignore
}
}
}
}
}
}
use of org.jboss.as.web.common.WarMetaData 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 JBossWebMetaData();
warMetaData.setJBossWebMetaData(jBossWebMetaData);
}
jBossWebMetaData.setContextRoot(contextRoot);
}
return;
}
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class ASHelper method getJBossWebMetaData.
/**
* Gets the JBossWebMetaData from the WarMetaData attached to the provided deployment unit, if any.
*
* @param unit
* @return the JBossWebMetaData or null if either that or the parent WarMetaData are not found.
*/
public static JBossWebMetaData getJBossWebMetaData(final DeploymentUnit unit) {
final WarMetaData warMetaData = getOptionalAttachment(unit, WarMetaData.ATTACHMENT_KEY);
JBossWebMetaData result = null;
if (warMetaData != null) {
result = warMetaData.getMergedJBossWebMetaData();
if (result == null) {
result = warMetaData.getJBossWebMetaData();
}
} else {
result = getOptionalAttachment(unit, WSAttachmentKeys.JBOSSWEB_METADATA_KEY);
}
return result;
}
Aggregations