try
{
if (hasCp || hasWB)
{
VFSDeploymentUnit moduleUnit = unit;
Module module = moduleUnit.getAttachment(Module.class);
while (moduleUnit != null && module == null)
{
moduleUnit = moduleUnit.getParent();
module = moduleUnit.getAttachment(Module.class);
}
if (module == null)
throw new DeploymentException("No module in deployment unit's hierarchy: " + unit.getName());
ArchiveInfo archive = moduleUnit.getAttachment(ArchiveInfo.class);
if (archive == null)
throw new IllegalStateException("Archive attachment expected for unit " + unit);
WeldDiscoveryEnvironment environment = archive.getEnvironment();
if (hasCp)
{
URL[] urls = new URL[cpFiles.size()];
int i = 0;
for (VirtualFile file : cpFiles)
{
urls[i++] = file.toURL();
}
WBDiscoveryVisitor visitor = new WBDiscoveryVisitor(environment);
module.visit(visitor, ClassFilter.INSTANCE, null, urls);
}
if (hasWB)
{
for (VirtualFile file : wbFiles)
environment.addWeldXmlURL(file.toURL());