This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 0210711 OWB-1391 avoid to drop classpath entries during scanning time
if not relevant
0210711 is described below
commit 02107113d5e8b8c9127cb63c56f46b7cb048aab7
Author: Romain Manni-Bucau <[email protected]>
AuthorDate: Wed Sep 29 09:03:42 2021 +0200
OWB-1391 avoid to drop classpath entries during scanning time if not
relevant
---
.../corespi/scanner/AbstractMetaDataDiscovery.java | 55 +++++++++++++++++-----
1 file changed, 43 insertions(+), 12 deletions(-)
diff --git
a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
index d09e2b3..002e81e 100644
---
a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
+++
b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
@@ -19,6 +19,7 @@
package org.apache.webbeans.corespi.scanner;
+import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import org.apache.webbeans.config.OWBLogConst;
@@ -201,7 +202,8 @@ public abstract class AbstractMetaDataDiscovery implements
BdaScannerService
try
{
- Set<URL> classPathUrls = ClassLoaders.findUrls(loader);
+ final Set<URL> classPathUrls = ClassLoaders.findUrls(loader);
+ final 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);
@@ -210,19 +212,30 @@ public abstract class AbstractMetaDataDiscovery
implements BdaScannerService
URL beansXmlUrl = beansXmlUrls.nextElement();
addWebBeansXmlLocation(beansXmlUrl);
- // second step: remove the corresponding classpath entry if we
found an explicit beans.xml
- String beansXml = beansXmlUrl.toExternalForm();
- beansXml = stripProtocol(beansXml);
+ 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())
+ 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
{
- URL cpUrl = cpIt.next();
- if
(beansXml.startsWith(stripProtocol(cpUrl.toExternalForm())))
+ final URL url =
classpathFiles.remove(Files.toFile(beansXmlUrl));
+ if (url != null)
{
- cpIt.remove();
- addDeploymentUrl(beansXml, cpUrl);
- break;
+ addDeploymentUrl(beansXmlUrl.toExternalForm(), url);
}
}
}
@@ -234,7 +247,7 @@ public abstract class AbstractMetaDataDiscovery implements
BdaScannerService
filterExcludedJars(classPathUrls);
// forth step: add all 'implicit bean archives'
- for (URL url : classPathUrls)
+ for (URL url : (classpathFiles == null ? classPathUrls :
classpathFiles.values()))
{
if (isBdaUrlEnabled(url))
{
@@ -250,6 +263,24 @@ public abstract class AbstractMetaDataDiscovery implements
BdaScannerService
}
}
+ protected Map<File, URL> toFiles(final Set<URL> classPathUrls)
+ {
+ try
+ {
+ final Map<File, URL> collected = classPathUrls.stream()
+ .collect(toMap(Files::toFile, identity(), (a, b) -> a));
+ if (collected.containsKey(null)) // not a known protocol
+ {
+ return null;
+ }
+ return collected;
+ }
+ catch (final RuntimeException re)
+ {
+ return null;
+ }
+ }
+
/**
* Get rid of any protocol header from the url externalForm
* @param urlPath