From db355e7a165a38ab5c6fc0045b3616bb8b10a59f Mon Sep 17 00:00:00 2001 From: Jozef Hartinger Date: Tue, 16 Oct 2012 09:11:21 +0200 Subject: [PATCH] Make sure BeansXmlHandler remains compatible with JBoss AS 7.1.1.Final --- .../org/jboss/as/weld/WeldSubsystemAdd.java | 7 +- .../as/weld/deployment/BeansXmlHandler.java | 16 +- .../as/weld/deployment/BeansXmlParser.java | 12 +- .../deployment/ReplacingBeansXmlHandler.java | 44 ++++++ .../processors/BeansXmlProcessor.java | 115 ++------------ .../processors/LegacyBeansXmlProcessor.java | 149 ++++++++++++++++++ 6 files changed, 226 insertions(+), 117 deletions(-) create mode 100644 subsystem/src/main/java/org/jboss/as/weld/deployment/ReplacingBeansXmlHandler.java create mode 100644 subsystem/src/main/java/org/jboss/as/weld/deployment/processors/LegacyBeansXmlProcessor.java diff --git a/subsystem/src/main/java/org/jboss/as/weld/WeldSubsystemAdd.java b/subsystem/src/main/java/org/jboss/as/weld/WeldSubsystemAdd.java index 87123b1..47e6b35 100644 --- a/subsystem/src/main/java/org/jboss/as/weld/WeldSubsystemAdd.java +++ b/subsystem/src/main/java/org/jboss/as/weld/WeldSubsystemAdd.java @@ -34,6 +34,7 @@ import org.jboss.as.weld.deployment.CdiAnnotationProcessor; import org.jboss.as.weld.deployment.processors.BeanArchiveProcessor; import org.jboss.as.weld.deployment.processors.BeansXmlProcessor; +import org.jboss.as.weld.deployment.processors.LegacyBeansXmlProcessor; import org.jboss.as.weld.deployment.processors.WebIntegrationProcessor; import org.jboss.as.weld.deployment.processors.WeldBeanManagerServiceProcessor; import org.jboss.as.weld.deployment.processors.WeldComponentIntegrationProcessor; @@ -66,7 +67,11 @@ protected void execute(DeploymentProcessorTarget processorTarget) { DeploymentProcessorRegistrar registrar = new DeploymentProcessorRegistrar(processorTarget); registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_WELD, new WeldDependencyProcessor()); registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_CDI_ANNOTATIONS, new CdiAnnotationProcessor()); - registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_WELD_DEPLOYMENT, new BeansXmlProcessor()); + if (ApplicationServerVersion.isEqualOrNewer(ApplicationServerVersion.AS712Final)) { + registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_WELD_DEPLOYMENT, new BeansXmlProcessor()); + } else { + registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_WELD_DEPLOYMENT, new LegacyBeansXmlProcessor()); + } registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_WEB_INTEGRATION, new WebIntegrationProcessor()); registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_BEAN_ARCHIVE, new BeanArchiveProcessor()); registrar.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_PORTABLE_EXTENSIONS, new WeldPortableExtensionProcessor()); diff --git a/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlHandler.java b/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlHandler.java index 4d48eb6..2f1792a 100644 --- a/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlHandler.java +++ b/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlHandler.java @@ -118,7 +118,6 @@ protected static String trim(String str) { private final List> includes; private final List> excludes; private final URL file; - final PropertyReplacer propertyReplacer; /* * Parser State @@ -128,9 +127,8 @@ protected static String trim(String str) { private StringBuilder buffer; private Locator locator; - public BeansXmlHandler(final URL file, final PropertyReplacer propertyReplacer) { + public BeansXmlHandler(final URL file) { this.file = file; - this.propertyReplacer = propertyReplacer; this.interceptors = new ArrayList>(); this.decorators = new ArrayList>(); this.alternativeClasses = new ArrayList>(); @@ -144,7 +142,7 @@ public BeansXmlHandler(final URL file, final PropertyReplacer propertyReplacer) @Override public void processEndChildElement(String uri, String localName, String qName, String nestedText) { if (isInNamespace(uri) && "class".equals(localName)) { - interceptors.add(new XmlMetadata(qName, propertyReplacer.replaceProperties(trim(nestedText)), file, locator.getLineNumber())); + interceptors.add(new XmlMetadata(qName, replaceProperties(trim(nestedText)), file, locator.getLineNumber())); } } @@ -159,7 +157,7 @@ public void handleMultiple() { @Override public void processEndChildElement(String uri, String localName, String qName, String nestedText) { if (isInNamespace(uri) && "class".equals(localName)) { - decorators.add(new XmlMetadata(qName, propertyReplacer.replaceProperties(trim(nestedText)), file, locator.getLineNumber())); + decorators.add(new XmlMetadata(qName, replaceProperties(trim(nestedText)), file, locator.getLineNumber())); } } @@ -174,9 +172,9 @@ public void handleMultiple() { @Override public void processEndChildElement(String uri, String localName, String qName, String nestedText) { if (isInNamespace(uri) && "class".equals(localName)) { - alternativeClasses.add(new XmlMetadata(qName, propertyReplacer.replaceProperties(trim(nestedText)), file, locator.getLineNumber())); + alternativeClasses.add(new XmlMetadata(qName, replaceProperties(trim(nestedText)), file, locator.getLineNumber())); } else if (isInNamespace(uri) && "stereotype".equals(localName)) { - alternativeStereotypes.add(new XmlMetadata(qName, propertyReplacer.replaceProperties(trim(nestedText)), file, locator.getLineNumber())); + alternativeStereotypes.add(new XmlMetadata(qName, replaceProperties(trim(nestedText)), file, locator.getLineNumber())); } } @@ -328,4 +326,8 @@ public void error(SAXParseException e) throws SAXException { WeldLogger.DEPLOYMENT_LOGGER.beansXmlValidationError(file, e.getLineNumber(), e.getMessage()); } + protected String replaceProperties(String text) { + return text; // noop by default + } + } diff --git a/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlParser.java b/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlParser.java index fedddfe..392ca7b 100644 --- a/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlParser.java +++ b/subsystem/src/main/java/org/jboss/as/weld/deployment/BeansXmlParser.java @@ -58,7 +58,7 @@ public class BeansXmlParser { private static final InputSource[] EMPTY_INPUT_SOURCE_ARRAY = new InputSource[0]; - public BeansXml parse(final URL beansXml, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException { + public BeansXml parse(final URL beansXml) throws DeploymentUnitProcessingException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); factory.setNamespaceAware(true); @@ -81,7 +81,7 @@ public BeansXml parse(final URL beansXml, final PropertyReplacer propertyReplace // The file is just acting as a marker file return EMPTY_BEANS_XML; } - BeansXmlHandler handler = new BeansXmlHandler(beansXml, propertyReplacer); + BeansXmlHandler handler = getHandler(beansXml); try { parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); @@ -109,7 +109,7 @@ public BeansXml parse(final URL beansXml, final PropertyReplacer propertyReplace } } - public BeansXml parse(Iterable urls, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException { + public BeansXml parse(Iterable urls) throws DeploymentUnitProcessingException { List> alternativeStereotypes = new ArrayList>(); List> alternativeClasses = new ArrayList>(); List> decorators = new ArrayList>(); @@ -118,7 +118,7 @@ public BeansXml parse(Iterable urls, final PropertyReplacer propertyReplace List> excludes = new ArrayList>(); URL beansXmlUrl = null; for (URL url : urls) { - BeansXml beansXml = parse(url, propertyReplacer); + BeansXml beansXml = parse(url); alternativeStereotypes.addAll(beansXml.getEnabledAlternativeStereotypes()); alternativeClasses.addAll(beansXml.getEnabledAlternativeClasses()); decorators.addAll(beansXml.getEnabledDecorators()); @@ -159,5 +159,9 @@ private static InputSource loadXsd(String name, ClassLoader classLoader) { } } + protected BeansXmlHandler getHandler(final URL beansXml) { + return new BeansXmlHandler(beansXml); + } + } diff --git a/subsystem/src/main/java/org/jboss/as/weld/deployment/ReplacingBeansXmlHandler.java b/subsystem/src/main/java/org/jboss/as/weld/deployment/ReplacingBeansXmlHandler.java new file mode 100644 index 0000000..0361227 --- /dev/null +++ b/subsystem/src/main/java/org/jboss/as/weld/deployment/ReplacingBeansXmlHandler.java @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.as.weld.deployment; + +import java.net.URL; + +import org.jboss.metadata.property.PropertyReplacer; + +/** + * BeansXmlHandler that uses {@link PropertyReplacer} to replace properties. + * + * @author Jozef Hartinger + * @author Stuart Douglas + * + */ +public class ReplacingBeansXmlHandler extends BeansXmlHandler { + + private final PropertyReplacer replacer; + + public ReplacingBeansXmlHandler(URL file, PropertyReplacer replacer) { + super(file); + this.replacer = replacer; + } + + @Override + protected String replaceProperties(String text) { + return replacer.replaceProperties(text); + } + +} diff --git a/subsystem/src/main/java/org/jboss/as/weld/deployment/processors/BeansXmlProcessor.java b/subsystem/src/main/java/org/jboss/as/weld/deployment/processors/BeansXmlProcessor.java index 9214cb5..ba79540 100644 --- a/subsystem/src/main/java/org/jboss/as/weld/deployment/processors/BeansXmlProcessor.java +++ b/subsystem/src/main/java/org/jboss/as/weld/deployment/processors/BeansXmlProcessor.java @@ -21,122 +21,27 @@ */ package org.jboss.as.weld.deployment.processors; -import java.net.MalformedURLException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.net.URL; -import org.jboss.as.ee.structure.DeploymentType; -import org.jboss.as.ee.structure.DeploymentTypeMarker; import org.jboss.as.ee.structure.SpecDescriptorPropertyReplacement; -import org.jboss.as.server.deployment.Attachments; -import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; -import org.jboss.as.server.deployment.DeploymentUnitProcessingException; -import org.jboss.as.server.deployment.DeploymentUnitProcessor; -import org.jboss.as.server.deployment.SubDeploymentMarker; -import org.jboss.as.server.deployment.module.ModuleRootMarker; -import org.jboss.as.server.deployment.module.ResourceRoot; -import org.jboss.as.weld.WeldDeploymentMarker; -import org.jboss.as.weld.WeldLogger; -import org.jboss.as.weld.WeldMessages; -import org.jboss.as.weld.deployment.BeanArchiveMetadata; +import org.jboss.as.weld.deployment.BeansXmlHandler; import org.jboss.as.weld.deployment.BeansXmlParser; -import org.jboss.as.weld.deployment.WeldDeploymentMetadata; -import org.jboss.vfs.VirtualFile; -import org.jboss.weld.bootstrap.spi.BeansXml; +import org.jboss.as.weld.deployment.ReplacingBeansXmlHandler; /** * Deployment processor that finds beans.xml files and attaches the information to the deployment * * @author Stuart Douglas */ -public class BeansXmlProcessor implements DeploymentUnitProcessor { - - private static final String WEB_INF_BEANS_XML = "WEB-INF/beans.xml"; - private static final String META_INF_BEANS_XML = "META-INF/beans.xml"; +public class BeansXmlProcessor extends LegacyBeansXmlProcessor { @Override - public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { - final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); - - BeansXmlParser parser = new BeansXmlParser(); - - Set beanArchiveMetadata = new HashSet(); - ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); - if (deploymentRoot == null) { - return; - } - - ResourceRoot classesRoot = null; - List structure = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS); - for (ResourceRoot resourceRoot : structure) { - if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) { - if (resourceRoot.getRootName().equals("classes")) { - // hack for dealing with war modules - classesRoot = resourceRoot; - } else { - VirtualFile beansXml = resourceRoot.getRoot().getChild(META_INF_BEANS_XML); - if (beansXml.exists() && beansXml.isFile()) { - WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml.toString()); - beanArchiveMetadata.add(new BeanArchiveMetadata(beansXml, resourceRoot, parseBeansXml(beansXml, - parser, deploymentUnit), false)); - } - } + protected BeansXmlParser getBeansXmlParser(final DeploymentUnit deploymentUnit) { + return new BeansXmlParser() { + protected BeansXmlHandler getHandler(final URL beansXml) { + return new ReplacingBeansXmlHandler(beansXml, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit)); } - } - - if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) { - if (classesRoot != null) { - // look for WEB-INF/beans.xml - final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(WEB_INF_BEANS_XML); - final boolean rootBeansXmlPresent = rootBeansXml.exists() && rootBeansXml.isFile(); - // look for beans.xml files in the wrong location - final VirtualFile beansXml = classesRoot.getRoot().getChild(META_INF_BEANS_XML); - final boolean beansXmlPresent = beansXml.exists() && beansXml.isFile(); - - if (rootBeansXmlPresent) { - if (beansXmlPresent) { - // warn that it is not portable to use both locations at the same time - WeldLogger.DEPLOYMENT_LOGGER.duplicateBeansXml(); - } - WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml); - beanArchiveMetadata.add(new BeanArchiveMetadata(rootBeansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true)); - } else if (beansXmlPresent) { - WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml); - beanArchiveMetadata.add(new BeanArchiveMetadata(beansXml, classesRoot, parseBeansXml(beansXml, parser, deploymentUnit), true)); - } - } - } else if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) { - final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(META_INF_BEANS_XML); - if (rootBeansXml.exists() && rootBeansXml.isFile()) { - WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml.toString()); - beanArchiveMetadata.add(new BeanArchiveMetadata(rootBeansXml, deploymentRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true)); - } - } - - if (!beanArchiveMetadata.isEmpty()) { - WeldDeploymentMetadata deploymentMetadata = new WeldDeploymentMetadata(beanArchiveMetadata); - deploymentUnit.putAttachment(WeldDeploymentMetadata.ATTACHMENT_KEY, deploymentMetadata); - // mark the deployment as requiring CDI integration - WeldDeploymentMarker.mark(deploymentUnit); - if (deploymentUnit.getParent() != null) { - WeldDeploymentMarker.mark(deploymentUnit.getParent()); - } - } - } - - @Override - public void undeploy(DeploymentUnit context) { - - } - - private BeansXml parseBeansXml(VirtualFile beansXmlFile, BeansXmlParser parser, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { - try { - return parser.parse(beansXmlFile.asFileURL(), SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit)); - } catch (MalformedURLException e) { - throw WeldMessages.MESSAGES.couldNotGetBeansXmlAsURL(beansXmlFile.toString(), e); - } + }; } - -} +} \ No newline at end of file diff --git a/subsystem/src/main/java/org/jboss/as/weld/deployment/processors/LegacyBeansXmlProcessor.java b/subsystem/src/main/java/org/jboss/as/weld/deployment/processors/LegacyBeansXmlProcessor.java new file mode 100644 index 0000000..45c255f --- /dev/null +++ b/subsystem/src/main/java/org/jboss/as/weld/deployment/processors/LegacyBeansXmlProcessor.java @@ -0,0 +1,149 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.weld.deployment.processors; + +import java.net.MalformedURLException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.jboss.as.ee.structure.DeploymentType; +import org.jboss.as.ee.structure.DeploymentTypeMarker; +import org.jboss.as.server.deployment.Attachments; +import org.jboss.as.server.deployment.DeploymentPhaseContext; +import org.jboss.as.server.deployment.DeploymentUnit; +import org.jboss.as.server.deployment.DeploymentUnitProcessingException; +import org.jboss.as.server.deployment.DeploymentUnitProcessor; +import org.jboss.as.server.deployment.SubDeploymentMarker; +import org.jboss.as.server.deployment.module.ModuleRootMarker; +import org.jboss.as.server.deployment.module.ResourceRoot; +import org.jboss.as.weld.WeldDeploymentMarker; +import org.jboss.as.weld.WeldLogger; +import org.jboss.as.weld.WeldMessages; +import org.jboss.as.weld.deployment.BeanArchiveMetadata; +import org.jboss.as.weld.deployment.BeansXmlParser; +import org.jboss.as.weld.deployment.WeldDeploymentMetadata; +import org.jboss.metadata.property.PropertyReplacer; +import org.jboss.vfs.VirtualFile; +import org.jboss.weld.bootstrap.spi.BeansXml; + +/** + * Deployment processor that finds beans.xml files and attaches the information to the deployment + * + * This implementation does not use {@link PropertyReplacer} and is therefore compatible with AS 7.1.1.Final + * + * @author Stuart Douglas + */ +public class LegacyBeansXmlProcessor implements DeploymentUnitProcessor { + + private static final String WEB_INF_BEANS_XML = "WEB-INF/beans.xml"; + private static final String META_INF_BEANS_XML = "META-INF/beans.xml"; + + @Override + public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { + final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); + + + Set beanArchiveMetadata = new HashSet(); + ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); + if (deploymentRoot == null) { + return; + } + + BeansXmlParser parser = getBeansXmlParser(deploymentUnit); + + ResourceRoot classesRoot = null; + List structure = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS); + for (ResourceRoot resourceRoot : structure) { + if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) { + if (resourceRoot.getRootName().equals("classes")) { + // hack for dealing with war modules + classesRoot = resourceRoot; + } else { + VirtualFile beansXml = resourceRoot.getRoot().getChild(META_INF_BEANS_XML); + if (beansXml.exists() && beansXml.isFile()) { + WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml.toString()); + beanArchiveMetadata.add(new BeanArchiveMetadata(beansXml, resourceRoot, parseBeansXml(beansXml, + parser, deploymentUnit), false)); + } + } + } + } + + if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) { + if (classesRoot != null) { + // look for WEB-INF/beans.xml + final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(WEB_INF_BEANS_XML); + final boolean rootBeansXmlPresent = rootBeansXml.exists() && rootBeansXml.isFile(); + // look for beans.xml files in the wrong location + final VirtualFile beansXml = classesRoot.getRoot().getChild(META_INF_BEANS_XML); + final boolean beansXmlPresent = beansXml.exists() && beansXml.isFile(); + + if (rootBeansXmlPresent) { + if (beansXmlPresent) { + // warn that it is not portable to use both locations at the same time + WeldLogger.DEPLOYMENT_LOGGER.duplicateBeansXml(); + } + WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml); + beanArchiveMetadata.add(new BeanArchiveMetadata(rootBeansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true)); + } else if (beansXmlPresent) { + WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml); + beanArchiveMetadata.add(new BeanArchiveMetadata(beansXml, classesRoot, parseBeansXml(beansXml, parser, deploymentUnit), true)); + } + } + } else if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) { + final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(META_INF_BEANS_XML); + if (rootBeansXml.exists() && rootBeansXml.isFile()) { + WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml.toString()); + beanArchiveMetadata.add(new BeanArchiveMetadata(rootBeansXml, deploymentRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true)); + } + } + + if (!beanArchiveMetadata.isEmpty()) { + WeldDeploymentMetadata deploymentMetadata = new WeldDeploymentMetadata(beanArchiveMetadata); + deploymentUnit.putAttachment(WeldDeploymentMetadata.ATTACHMENT_KEY, deploymentMetadata); + // mark the deployment as requiring CDI integration + WeldDeploymentMarker.mark(deploymentUnit); + if (deploymentUnit.getParent() != null) { + WeldDeploymentMarker.mark(deploymentUnit.getParent()); + } + } + } + + @Override + public void undeploy(DeploymentUnit context) { + + } + + private BeansXml parseBeansXml(VirtualFile beansXmlFile, BeansXmlParser parser, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { + try { + return parser.parse(beansXmlFile.asFileURL()); + } catch (MalformedURLException e) { + throw WeldMessages.MESSAGES.couldNotGetBeansXmlAsURL(beansXmlFile.toString(), e); + } + } + + protected BeansXmlParser getBeansXmlParser(final DeploymentUnit deploymentUnit) { + return new BeansXmlParser(); + } + +}