This is an automated email from the ASF dual-hosted git repository.

tandraschko 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 0ce034d  OWB-1398
0ce034d is described below

commit 0ce034d4c0da95989f094963e16d0db6398a7f56
Author: Thomas Andraschko <[email protected]>
AuthorDate: Mon Dec 13 13:26:53 2021 +0100

    OWB-1398
---
 .../corespi/scanner/AbstractMetaDataDiscovery.java | 63 +++++++++++++---------
 1 file changed, 37 insertions(+), 26 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 4ca7624..d2b2ebe 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
@@ -60,6 +60,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.stream.Collectors;
 
 
 
@@ -209,7 +210,7 @@ public abstract class AbstractMetaDataDiscovery implements 
BdaScannerService
         try
         {
             final Set<URL> classPathUrls = ClassLoaders.findUrls(loader);
-            final Map<File, URL> classpathFiles = toFiles(classPathUrls);
+            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);
@@ -260,6 +261,7 @@ public abstract class AbstractMetaDataDiscovery implements 
BdaScannerService
             {
                 // third step: remove all jars we know they do not contain any 
CDI beans
                 filterExcludedJars(classPathUrls);
+                classpathFiles = filterExcludedJars(classpathFiles);
 
                 // forth step: add all 'implicit bean archives'
                 for (URL url : (classpathFiles == null ? classPathUrls : 
classpathFiles.values()))
@@ -311,43 +313,52 @@ public abstract class AbstractMetaDataDiscovery 
implements BdaScannerService
         return urlPath;
     }
 
+    protected Map<File, URL> filterExcludedJars(Map<File, URL> classpathFiles)
+    {
+        return classpathFiles.entrySet().stream()
+                .filter(e -> !isExcludedJar(e.getValue()))
+                .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
+    }
+
     protected void filterExcludedJars(Set<URL> classPathUrls)
     {
-        Iterator<URL> it = classPathUrls.iterator();
-        while (it.hasNext())
+        classPathUrls.removeIf(i -> isExcludedJar(i));
+    }
+    
+    protected boolean isExcludedJar(URL url)
+    {
+        String path = url.toExternalForm();   
+        // TODO: should extract file path and test file.getName(), not the 
whole path
+        // + should be configurable
+        int knownJarIdx = getKnownJarIdx(path);
+        // -Prun-its openwebbeans-tomcat7 in path but WEB-INF/classes
+        if (knownJarIdx > 0 && knownJarIdx < path.indexOf(".jar"))
         {
-            URL url = it.next();
-            String path = url.toExternalForm();
-            // TODO: should extract file path and test file.getName(), not the 
whole path
-            // + should be configurable
-            int knownJarIdx = isExcludedJar(path);
-            // -Prun-its openwebbeans-tomcat7 in path but WEB-INF/classes
-            if (knownJarIdx > 0 && knownJarIdx < path.indexOf(".jar"))
-            {
-                //X TODO this should be much more actually
-                //X TODO we might need to configure it via files
-                it.remove();
-            }
-            else
+            //X TODO this should be much more actually
+            //X TODO we might need to configure it via files
+            return true;
+        }
+        else
+        {
+            if (path.contains("geronimo-"))
             {
-                if (path.contains("geronimo-"))
+                // we could check for META-INF/maven/org.apache.geronimo.specs 
presence there but this is faster
+                final File file = Files.toFile(url);
+                if (file != null)
                 {
-                    // we could check for 
META-INF/maven/org.apache.geronimo.specs presence there but this is faster
-                    final File file = Files.toFile(url);
-                    if (file != null)
+                    final String filename = file.getName();
+                    if (filename.startsWith("geronimo-") && 
filename.contains("_spec"))
                     {
-                        final String filename = file.getName();
-                        if (filename.startsWith("geronimo-") && 
filename.contains("_spec"))
-                        {
-                            it.remove();
-                        }
+                        return true;
                     }
                 }
             }
         }
+        
+        return false;
     }
 
-    protected int isExcludedJar(String path)
+    protected int getKnownJarIdx(String path)
     {
         // lazy init - required when using DS CdiTestRunner
         initScanningExcludes();

Reply via email to