in webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java [203:283]
protected void registerBeanArchives(ClassLoader loader)
{
this.loader = loader;
try
{
final Set<URL> classPathUrls = ClassLoaders.findUrls(loader);
Map<File, URL> classpathFiles = toFiles(classPathUrls);
// first step: get all META-INF/beans.xml marker files
Enumeration<URL> beansXmlUrls = loader.getResources(META_INF_BEANS_XML);
while (beansXmlUrls.hasMoreElements())
{
URL beansXmlUrl = beansXmlUrls.nextElement();
addWebBeansXmlLocation(beansXmlUrl);
if (classpathFiles == null) // handle protocols out if [jar,file] set
{
// second step: remove the corresponding classpath entry if we found an explicit beans.xml
String beansXml = beansXmlUrl.toExternalForm();
beansXml = stripProtocol(beansXml);
Iterator<URL> cpIt = classPathUrls.iterator(); // do not use Set<URL> remove as this would trigger hashCode -> DNS
while (cpIt.hasNext())
{
URL cpUrl = cpIt.next();
if (beansXml.startsWith(stripProtocol(cpUrl.toExternalForm())))
{
cpIt.remove();
addDeploymentUrl(beansXml, cpUrl);
break;
}
}
}
else
{
File key = Files.toFile(beansXmlUrl);
URL url = classpathFiles.remove(key);
if (url == null &&
"beans.xml".equals(key.getName()) &&
key.getParentFile() != null &&
"META-INF".equals(key.getParentFile().getName()))
{
key = key.getParentFile().getParentFile();
url = classpathFiles.remove(key);
}
if (url != null)
{
addDeploymentUrl(beansXmlUrl.toExternalForm(), url);
}
}
}
boolean onlyBeansXmlJars = webBeansContext().getOpenWebBeansConfiguration().scanOnlyBeansXmlJars();
if (!onlyBeansXmlJars)
{
// third step: remove all jars we know they do not contain any CDI beans
filterExcludedJars(classPathUrls);
if (classpathFiles != null)
{
classpathFiles = classpathFiles.entrySet().stream()
.filter(e -> classPathUrls.contains(e.getValue()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
// forth step: add all 'implicit bean archives'
for (URL url : (classpathFiles == null ? classPathUrls : classpathFiles.values()))
{
if (isBdaUrlEnabled(url))
{
addWebBeansXmlLocation(url);
addDeploymentUrl(url.toExternalForm(), url);
}
}
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}