openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1606864 - in /openwebbeans/trunk: webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/ webbeans-impl/src/main/java/org/apache/webbeans/util/ webbeans-impl/src/main/java/org/apache/webbeans/...
Date Mon, 30 Jun 2014 18:45:16 GMT
Author: rmannibucau
Date: Mon Jun 30 18:45:15 2014
New Revision: 1606864

URL: http://svn.apache.org/r1606864
Log:
implementing exclusion rules of beans.xml

Modified:
    openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

Modified: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java?rev=1606864&r1=1606863&r2=1606864&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
(original)
+++ openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
Mon Jun 30 18:45:15 2014
@@ -18,16 +18,9 @@
  */
 package org.apache.webbeans.arquillian.standalone;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLStreamHandler;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.spi.BDABeansXmlScanner;
+import org.apache.webbeans.spi.BeanArchiveService;
 import org.apache.webbeans.spi.ScannerService;
 import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.shrinkwrap.api.ArchivePath;
@@ -40,6 +33,15 @@ import org.jboss.shrinkwrap.api.asset.Fi
 import org.jboss.shrinkwrap.api.exporter.ZipExporter;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
 /**
  *
  */
@@ -49,6 +51,9 @@ public class OwbArquillianScannerService
     private final static String WEB_INF_CLASS_FOLDER = "/WEB-INF/classes/";
 
     private final boolean beansXmlBdaScanningEnabled;
+    private final WebBeansContext webBeansContext;
+    private final BeanArchiveService archiveService;
+
     private Archive archive;
 
     private UrlSet beansXmls = new UrlSet();
@@ -58,6 +63,8 @@ public class OwbArquillianScannerService
     public OwbArquillianScannerService()
     {
         this.beansXmlBdaScanningEnabled = false;
+        webBeansContext = WebBeansContext.getInstance();
+        archiveService = webBeansContext.getBeanArchiveService();
     }
 
     @Override
@@ -144,9 +151,11 @@ public class OwbArquillianScannerService
 
         if (metainfBeansXmlUrl != null || webBeansXmlUrl != null)
         {
+            final BeanArchiveService.BeanArchiveInformation info = archiveService.getBeanArchiveInformation(webBeansXmlUrl
!= null ? webBeansXmlUrl : metainfBeansXmlUrl);
+
             // in this case we need to scan the WEB-INF/classses folder for .class files
             Map<ArchivePath, Node> classes = archive.getContent(Filters.include(WEB_INF_CLASS_FOLDER
+ ".*\\.class"));
-            scanClasses(classes, WEB_INF_CLASS_FOLDER);
+            scanClasses(info, classes, WEB_INF_CLASS_FOLDER);
         }
 
 
@@ -171,7 +180,6 @@ public class OwbArquillianScannerService
                 scanJarArchive(jarArchive);
             }
         }
-
     }
 
     private void scanJarArchive(final Archive<?> archive)
@@ -184,12 +192,13 @@ public class OwbArquillianScannerService
             return;
         }
 
+
         // otherwise we store it for later use
         beansXmls.add(beansXmlUrl);
 
         // and now add all classes
         Map<ArchivePath, Node> classes = archive.getContent(Filters.include(".*\\.class"));
-        scanClasses(classes, null);
+        scanClasses(archiveService.getBeanArchiveInformation(beansXmlUrl), classes, null);
     }
 
     /**
@@ -197,7 +206,8 @@ public class OwbArquillianScannerService
      * @param classes the scanned classes
      * @param classBasePath the base class in which the classes are, or null if they are
directly in the root
      */
-    private void scanClasses(Map<ArchivePath, Node> classes, String classBasePath)
+    private void scanClasses(final BeanArchiveService.BeanArchiveInformation info,
+                             final Map<ArchivePath, Node> classes, String classBasePath)
     {
         for (Map.Entry<ArchivePath, Node> classEntry : classes.entrySet())
         {
@@ -219,6 +229,11 @@ public class OwbArquillianScannerService
 
             className = className.replace('/', '.');
 
+            if (info != null && info.isClassExcluded(className))
+            {
+                continue;
+            }
+
 
             try
             {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java?rev=1606864&r1=1606863&r2=1606864&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
Mon Jun 30 18:45:15 2014
@@ -46,6 +46,9 @@ public final class WebBeansConstants
     public static final String WEB_BEANS_XML_CLASS = "class";
     public static final String WEB_BEANS_XML_STEREOTYPE = "stereotype";
     public static final String WEB_BEANS_XML_EXCLUDE = "exclude";
+    public static final String WEB_BEANS_XML_IF_CLASS_NOT_AVAILABLE = "if-class-not-available";
+    public static final String WEB_BEANS_XML_IF_CLASS_AVAILABLE = "if-class-available";
+    public static final String WEB_BEANS_XML_IF_SYSTEM_PROPERTY = "if-system-property ";
 
     /**JNDI name of the {@link javax.enterprise.inject.spi.BeanManager} instance*/
     public static final String WEB_BEANS_MANAGER_JNDI_NAME = "java:comp/BeanManager";

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java?rev=1606864&r1=1606863&r2=1606864&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
Mon Jun 30 18:45:15 2014
@@ -39,6 +39,8 @@ import org.apache.webbeans.spi.BeanArchi
 import org.apache.webbeans.util.UrlSet;
 import org.apache.webbeans.util.WebBeansConstants;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * Please note that this implementation is not thread safe.
@@ -314,35 +316,97 @@ public class DefaultBeanArchiveService i
 
     private void fillExcludes(DefaultBeanArchiveInformation bdaInfo, Element scanElement)
     {
-        ElementIterator elit = new ElementIterator(scanElement);
-        while (elit.hasNext())
+        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        final NodeList childNodes = scanElement.getChildNodes();
+        for (int i = 0; i < childNodes.getLength(); i++)
         {
-            Element child = elit.next();
+            final Node nd = childNodes.item(i);
+            if (!Element.class.isInstance(nd))
+            {
+                continue;
+            }
+
+            final Element child = Element.class.cast(nd);
             if (WebBeansConstants.WEB_BEANS_XML_EXCLUDE.equalsIgnoreCase(child.getLocalName()))
             {
-                String name = getTrimmedAttribute(child, "name");
-                if (name != null)
+                final String name = getTrimmedAttribute(child, "name");
+                final NodeList children = child.getChildNodes();
+                boolean skip = false;
+                for (int j = 0; j < children.getLength(); j++)
                 {
-                    if (name.endsWith(".*"))
+                    final Node ndChild = children.item(j);
+                    if (!Element.class.isInstance(ndChild))
                     {
-                        // package exclude without sub-packages
-                        bdaInfo.addClassExclude(name.substring(0, name.length() - 2));
+                        continue;
                     }
-                    else if (name.endsWith(".**"))
+
+                    final Element condition = Element.class.cast(ndChild);
+
+                    final String localName = condition.getLocalName();
+                    if (WebBeansConstants.WEB_BEANS_XML_IF_CLASS_AVAILABLE.equalsIgnoreCase(localName))
                     {
-                        // package exclude WITH sub-packages
-                        bdaInfo.addPackageExclude(name.substring(0, name.length() - 3));
+                        if (!isClassAvailable(loader, getTrimmedAttribute(condition, "name")))
+                        {
+                            skip = true;
+                            break;
+                        }
                     }
-                    else
+                    else if (WebBeansConstants.WEB_BEANS_XML_IF_CLASS_NOT_AVAILABLE.equalsIgnoreCase(localName))
                     {
-                        // a simple Class
-                        bdaInfo.addClassExclude(name);
+                        if (isClassAvailable(loader, getTrimmedAttribute(condition, "name")))
+                        {
+                            skip = true;
+                            break;
+                        }
                     }
+                    else if (WebBeansConstants.WEB_BEANS_XML_IF_SYSTEM_PROPERTY.equalsIgnoreCase(localName))
+                    {
+                        final String value = getTrimmedAttribute(condition, "value");
+                        final String systProp = System.getProperty(getTrimmedAttribute(condition,
"name"));
+                        if ((value == null && systProp == null) || !value.equals(systProp))
+                        {
+                            skip = true;
+                            break;
+                        }
+                    }
+                }
+                if (skip)
+                {
+                    continue;
+                }
+                if (name.endsWith(".*"))
+                {
+                    // package exclude without sub-packages
+                    bdaInfo.addClassExclude(name.substring(0, name.length() - 2));
+                }
+                else if (name.endsWith(".**"))
+                {
+                    // package exclude WITH sub-packages
+                    bdaInfo.addPackageExclude(name.substring(0, name.length() - 3));
+                }
+                else
+                {
+                    // a simple Class
+                    bdaInfo.addClassExclude(name);
                 }
             }
         }
     }
 
+    private static boolean isClassAvailable(final ClassLoader loader, final String name)
+    {
+        try
+        {
+            // no Class.forName(name) since it doesn't attach the classloader loader to the
class in some cases
+            loader.loadClass(name);
+            return true;
+        }
+        catch (final Throwable e) // NoClassDefFoundError or ClassNotFoundException
+        {
+            return false;
+        }
+    }
+
     @Override
     public void release()
     {

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1606864&r1=1606863&r2=1606864&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Mon Jun 30 18:45:15 2014
@@ -19,7 +19,7 @@
   <test name="JSR-346 TCK">
     <classes>
       <class
-          name="org.jboss.cdi.tck.tests.extensions.beanManager.BeanManagerTest" />
+          name="org.jboss.cdi.tck.tests.deployment.exclude.ExcludeFiltersTest" />
     </classes>
     <groups>
       <run>



Mime
View raw message