openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1447399 - in /openwebbeans/trunk: ./ webbeans-impl/ webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/ webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/ webbeans-impl/src/main/java/org/apache/webbeans/cor...
Date Mon, 18 Feb 2013 17:18:57 GMT
Author: rmannibucau
Date: Mon Feb 18 17:18:56 2013
New Revision: 1447399

URL: http://svn.apache.org/r1447399
Log:
OWB-779 importing xbean as main scanner

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java
Removed:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AnnotationDB.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/BeansXmlAnnotationDB.java
Modified:
    openwebbeans/trunk/pom.xml
    openwebbeans/trunk/webbeans-impl/pom.xml
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultScannerService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java
    openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/mock/TCKMetaDataDiscoveryImpl.java
    openwebbeans/trunk/webbeans-tck/pom.xml
    openwebbeans/trunk/webbeans-web/pom.xml
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/scanner/WebScannerService.java

Modified: openwebbeans/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/pom.xml?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/pom.xml (original)
+++ openwebbeans/trunk/pom.xml Mon Feb 18 17:18:56 2013
@@ -554,8 +554,8 @@
 
             <dependency>
                 <groupId>org.apache.xbean</groupId>
-                <artifactId>xbean-finder</artifactId>
-                <version>3.7</version>
+                <artifactId>xbean-finder-shaded</artifactId>
+                <version>3.13-SNAPSHOT</version>
             </dependency>
 
             <!--X TODO use a shaded version of:
@@ -566,11 +566,6 @@
                         <optional>true</optional>
                     </dependency>
             -->
-            <dependency>
-                <groupId>org.apache.xbean</groupId>
-                <artifactId>xbean-asm-shaded</artifactId>
-                <version>3.13-SNAPSHOT</version>
-            </dependency>
 
             <dependency>
                 <groupId>net.sf.scannotation</groupId>

Modified: openwebbeans/trunk/webbeans-impl/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/pom.xml?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/pom.xml (original)
+++ openwebbeans/trunk/webbeans-impl/pom.xml Mon Feb 18 17:18:56 2013
@@ -43,13 +43,8 @@
         </dependency>
 
         <dependency>
-            <groupId>net.sf.scannotation</groupId>
-            <artifactId>scannotation</artifactId>
-        </dependency>
-
-        <dependency>
             <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-asm-shaded</artifactId>
+            <artifactId>xbean-finder-shaded</artifactId>
         </dependency>
 
         <dependency>

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
Mon Feb 18 17:18:56 2013
@@ -19,28 +19,31 @@
 package org.apache.webbeans.corespi.scanner;
 
 
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.corespi.scanner.xbean.CdiArchive;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansDeploymentException;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.BDABeansXmlScanner;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+import org.apache.xbean.finder.AnnotationFinder;
+
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.apache.webbeans.config.OWBLogConst;
-import org.apache.webbeans.config.OpenWebBeansConfiguration;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.corespi.se.BeansXmlAnnotationDB;
-import org.apache.webbeans.corespi.se.DefaultBDABeansXmlScanner;
-import org.apache.webbeans.exception.WebBeansDeploymentException;
-import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.spi.BDABeansXmlScanner;
-import org.apache.webbeans.spi.ScannerService;
-import org.apache.webbeans.util.ClassUtil;
-
 public abstract class AbstractMetaDataDiscovery implements ScannerService
 {
     protected static final Logger logger = WebBeansLoggerFacade.getLogger(AbstractMetaDataDiscovery.class);
@@ -52,42 +55,56 @@ public abstract class AbstractMetaDataDi
 
     //private Map<String, InputStream> EJB_XML_LOCATIONS = new HashMap<String, InputStream>();
 
-    /** Annotation Database */
-    private AnnotationDB annotationDB;
-
+    protected ClassLoader loader;
+    protected CdiArchive archive;
+    protected AnnotationFinder finder;
     protected boolean isBDAScannerEnabled = false;
     protected BDABeansXmlScanner bdaBeansXmlScanner;
 
-    /**
-     * determines if cross referencing already got performed or not
-     */
-    private boolean isCrossReferenzed = false;
-
-    protected AbstractMetaDataDiscovery()
+    protected AnnotationFinder initFinder()
     {
-        initAnnotationDB();
-    }
-
-    private void initAnnotationDB()
-    {
-        try
+        if (finder != null)
         {
-            annotationDB = new AnnotationDB();
-            annotationDB.setScanClassAnnotations(true);
-            annotationDB.setScanFieldAnnotations(true);
-            annotationDB.setScanMethodAnnotations(true);
-            annotationDB.setScanParameterAnnotations(true);
+            return finder;
         }
-        catch(Exception e)
+
+        final Collection<URL> trimmedUrls = new ArrayList<URL>();
+        for (final URL url : getUrls())
         {
-            throw new WebBeansDeploymentException(e);
+            try
+            {
+                String file = url.getFile();
+                if (file.endsWith(META_INF_BEANS_XML))
+                {
+                    file = file.substring(0, file.length() - META_INF_BEANS_XML.length());
+                }
+                else if (file.endsWith("WEB-INF/beans.xml"))
+                {
+                    file = file.substring(0, file.length() - "WEB-INF/beans.xml".length());
+                }
+                trimmedUrls.add(new URL(url.getProtocol(), url.getHost(), url.getPort(),
file));
+            }
+            catch (MalformedURLException e)
+            {
+                throw new WebBeansConfigurationException("Can't trim url " + url.toExternalForm());
+            }
         }
+
+        archive = new CdiArchive(WebBeansUtil.getCurrentClassLoader(), trimmedUrls);
+        finder = new AnnotationFinder(archive);
+
+        return finder;
+    }
+
+    protected Iterable<URL> getUrls()
+    {
+        return webBeansXmlLocations;
     }
 
     /**
      * Configure the Web Beans Container with deployment information and fills
      * annotation database and beans.xml stream database.
-     * 
+     *
      * @throws org.apache.webbeans.exception.WebBeansConfigurationException if any run time
exception occurs
      */
     public void scan() throws WebBeansDeploymentException
@@ -104,7 +121,9 @@ public abstract class AbstractMetaDataDi
 
     public void release()
     {
-        initAnnotationDB();
+        finder = null;
+        archive = null;
+        loader = null;
     }
 
     abstract protected void configure();
@@ -120,6 +139,8 @@ public abstract class AbstractMetaDataDi
      */
     protected String[] findBeansXmlBases(String resourceName, ClassLoader loader)
     {
+        this.loader = loader;
+
         ArrayList<String> list = new ArrayList<String>();
         try
         {
@@ -143,12 +164,14 @@ public abstract class AbstractMetaDataDi
             throw new RuntimeException(e);
         }
 
+        initFinder();
+
         return list.toArray(new String[list.size()]);
 
     }
 
 
-    
+
     public void init(Object object)
     {
         // set per BDA beans.xml flag here because setting it in constructor
@@ -156,31 +179,16 @@ public abstract class AbstractMetaDataDi
         // properties are loaded.
         String usage = WebBeansContext.currentInstance().getOpenWebBeansConfiguration().getProperty(OpenWebBeansConfiguration.USE_BDA_BEANSXML_SCANNER);
         isBDAScannerEnabled = Boolean.parseBoolean(usage);
-        if (isBDAScannerEnabled)
-        {
-            annotationDB = new BeansXmlAnnotationDB();
-            ((BeansXmlAnnotationDB)annotationDB).setBdaBeansXmlScanner(this);
-
-            bdaBeansXmlScanner = new DefaultBDABeansXmlScanner();
-        }
-    }
-
-    /**
-     * @return the aNNOTATION_DB
-     */
-    protected AnnotationDB getAnnotationDB()
-    {
-        return annotationDB;
     }
 
     public Set<String> getAllAnnotations(String className)
     {
-        return annotationDB.getAnnotationIndex().get(className);
+        throw new UnsupportedOperationException();
     }
 
 
     /**
-     * add the given beans.xml path to the locations list 
+     * add the given beans.xml path to the locations list
      * @param beansXmlUrl location path
      */
     protected void addWebBeansXmlLocation(URL beansXmlUrl)
@@ -197,65 +205,35 @@ public abstract class AbstractMetaDataDi
      */
     public Set<Class<?>> getBeanClasses()
     {
-        crossReferenceBeans();
-
-        Set<Class<?>> classSet = new HashSet<Class<?>>();
-        Map<String,Set<String>> index = annotationDB.getClassIndex();
-        
-        if(index != null)
+        final Set<Class<?>> classSet = new HashSet<Class<?>>();
+        for(String str : archive.getClasses())
         {
-            Set<String> strSet = index.keySet();
-            if(strSet != null)
+            try
             {
-                for(String str : strSet)
+                Class<?> clazz = ClassUtil.getClassFromName(str);
+                if (clazz != null)
                 {
-                    try
-                    {
-                        Class<?> clazz = ClassUtil.getClassFromName(str);
-                        if (clazz != null)
-                        {
-                            
-                            // try to provoke a NoClassDefFoundError exception which is thrown

-                            // if some dependencies of the class are missing
-                            clazz.getDeclaredFields();
-                            clazz.getDeclaredMethods();
-                            
-                            // we can add this class cause it has been loaded completely
-                            classSet.add(clazz);
-                            
-                        }
-                    }
-                    catch (NoClassDefFoundError e)
-                    {
-                        if (logger.isLoggable(Level.WARNING))
-                        {
-                            logger.log(Level.WARNING, OWBLogConst.WARN_0018, new Object[]
{ str, e.toString() });
-                        }
-                    }
-                }
-            }   
-        }    
-        
-        return classSet;
-    }
 
-    /**
-     * Ensure that all Annotation CrossReferences got resolved.
-     */
-    protected synchronized void crossReferenceBeans()
-    {
-        if (!isCrossReferenzed)
-        {
-            try
-            {
-                annotationDB.crossReferenceMetaAnnotations();
+                    // try to provoke a NoClassDefFoundError exception which is thrown
+                    // if some dependencies of the class are missing
+                    clazz.getDeclaredFields();
+                    clazz.getDeclaredMethods();
+
+                    // we can add this class cause it has been loaded completely
+                    classSet.add(clazz);
+
+                }
             }
-            catch (AnnotationDB.CrossReferenceException e)
+            catch (NoClassDefFoundError e)
             {
-                throw new RuntimeException(e);
+                if (logger.isLoggable(Level.WARNING))
+                {
+                    logger.log(Level.WARNING, OWBLogConst.WARN_0018, new Object[] { str,
e.toString() });
+                }
             }
-            isCrossReferenzed = true;
         }
+
+        return classSet;
     }
 
 

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java?rev=1447399&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java
Mon Feb 18 17:18:56 2013
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.corespi.scanner.xbean;
+
+import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.ClassesArchive;
+import org.apache.xbean.finder.archive.ClasspathArchive;
+import org.apache.xbean.finder.archive.CompositeArchive;
+import org.apache.xbean.finder.archive.FilteredArchive;
+import org.apache.xbean.finder.filter.Filter;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+// this delegate pattern is interesting
+// because we will be able to add
+// some exclusion config through it
+// using Filter + FilterArchive
+public class CdiArchive implements Archive
+{
+    private final Map<URL, Collection<String>> map = new HashMap<URL, Collection<String>>();
+    private final Set<String> classes = new HashSet<String>();
+    private final Archive delegate;
+
+    public CdiArchive(final ClassLoader loader, final Iterable<URL> urls)
+    {
+        final Collection<Archive> archives = new ArrayList<Archive>();
+        for (final URL url : urls)
+        {
+            final List<String> classes = new ArrayList<String>();
+            final Archive archive = new FilteredArchive(ClasspathArchive.archive(loader,
url), new Filter()
+            {
+                @Override
+                public boolean accept(final String name)
+                {
+                    classes.add(name);
+                    CdiArchive.this.classes.add(name);
+                    return true;
+                }
+            });
+            map.put(url, classes);
+            archives.add(archive);
+        }
+
+        delegate = new CompositeArchive(archives);
+    }
+
+    public CdiArchive(final Collection<Class<?>> classList)
+    {
+        delegate = new FilteredArchive(new ClassesArchive(classList), new Filter()
+        {
+            @Override
+            public boolean accept(final String name)
+            {
+                classes.add(name);
+                return true;
+            }
+        });
+    }
+
+    public Set<String> getClasses()
+    {
+        return classes;
+    }
+
+    public Map<URL, Collection<String>> classesByUrl()
+    {
+        return map;
+    }
+
+    @Override
+    public InputStream getBytecode(final String className) throws IOException, ClassNotFoundException
+    {
+        return delegate.getBytecode(className);
+    }
+
+    @Override
+    public Class<?> loadClass(final String className) throws ClassNotFoundException
+    {
+        return delegate.loadClass(className);
+    }
+
+    @Override
+    public Iterator<Entry> iterator()
+    {
+        return delegate.iterator();
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultScannerService.java?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultScannerService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultScannerService.java
Mon Feb 18 17:18:56 2013
@@ -18,10 +18,7 @@
  */
 package org.apache.webbeans.corespi.se;
 
-import java.io.IOException;
-
 import org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.util.WebBeansUtil;
 
 public class DefaultScannerService extends AbstractMetaDataDiscovery
@@ -43,16 +40,7 @@ public class DefaultScannerService exten
         ClassLoader loader = WebBeansUtil.getCurrentClassLoader();
         //Store collection of beans.xml's before scanning archives
 
-        String[] urlPaths = findBeansXmlBases(META_INF_BEANS_XML, loader);
-
-        try
-        {
-            getAnnotationDB().scanArchives(urlPaths);
-        }
-        catch (IOException e)
-        {
-            throw new WebBeansConfigurationException("Error while scanning the JAR archives",
e);
-        }
+        findBeansXmlBases(META_INF_BEANS_XML, loader);
     }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java
Mon Feb 18 17:18:56 2013
@@ -18,19 +18,15 @@
  */
 package org.apache.webbeans.lifecycle.test;
 
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collection;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javassist.ClassPool;
-
 import org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery;
+import org.apache.webbeans.corespi.scanner.xbean.CdiArchive;
 import org.apache.webbeans.exception.WebBeansDeploymentException;
-import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.util.Asserts;
+import org.apache.xbean.finder.AnnotationFinder;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
 
 /**
  * Used by each test. 
@@ -39,8 +35,6 @@ import org.apache.webbeans.util.Asserts;
  */
 public class OpenWebBeansTestMetaDataDiscoveryService extends AbstractMetaDataDiscovery
 {
-    private static final Logger logger = WebBeansLoggerFacade.getLogger(OpenWebBeansTestMetaDataDiscoveryService.class);
-
     public OpenWebBeansTestMetaDataDiscoveryService()
     {
         
@@ -60,10 +54,8 @@ public class OpenWebBeansTestMetaDataDis
     {
         if(classes != null)
         {
-            for(Class<?> clazz : classes)
-            {
-                addBeanClass(clazz);
-            }
+            archive = new CdiArchive(classes);
+            finder = new AnnotationFinder(archive);
         }
     }
     
@@ -89,27 +81,6 @@ public class OpenWebBeansTestMetaDataDis
         }
     }
     
-    
-    /**
-     * Adds new class for scanning.
-     * @param clazz new scanned class
-     */
-    private void addBeanClass(Class<?> clazz)
-    {
-        Asserts.assertNotNull(clazz);
-        
-        URL url = ClassPool.getDefault().find(clazz.getName());
-        
-        try
-        {
-            getAnnotationDB().scanClass(url.openStream());
-        }
-        catch (IOException e)
-        {
-            logger.log(Level.WARNING, "Problems while scanning class " + clazz.getName());
-        }
-    }
-    
     /**
      * Adds new beans.xml url for scanning.
      * @param url new xml url

Modified: openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/mock/TCKMetaDataDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/mock/TCKMetaDataDiscoveryImpl.java?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/mock/TCKMetaDataDiscoveryImpl.java
(original)
+++ openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/mock/TCKMetaDataDiscoveryImpl.java
Mon Feb 18 17:18:56 2013
@@ -18,16 +18,18 @@
  */
 package org.apache.webbeans.test.tck.mock;
 
-import java.io.IOException;
-import java.net.URL;
-
-import javassist.ClassPool;
-
 import org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery;
+import org.apache.webbeans.corespi.scanner.xbean.CdiArchive;
 import org.apache.webbeans.util.Asserts;
+import org.apache.xbean.finder.AnnotationFinder;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
 
 public class TCKMetaDataDiscoveryImpl extends AbstractMetaDataDiscovery
 {
+    private Collection<Class<?>> classes = new ArrayList<Class<?>>();
 
     public TCKMetaDataDiscoveryImpl()
     {
@@ -39,19 +41,22 @@ public class TCKMetaDataDiscoveryImpl ex
     {
     }
 
-    public void addBeanClass(Class<?> clazz)
+    @Override
+    protected AnnotationFinder initFinder()
     {
-        Asserts.assertNotNull(clazz);
-        
-        URL url = ClassPool.getDefault().find(clazz.getName());
-        try
+        if (finder != null)
         {
-            this.getAnnotationDB().scanClass(url.openStream());
-        }
-        catch (IOException e)
-        {
-            e.printStackTrace();
+            return finder;
         }
+
+        archive = new CdiArchive(classes);
+        finder = new AnnotationFinder(archive);
+        return finder;
+    }
+
+    public void addBeanClass(Class<?> clazz)
+    {
+        classes.add(clazz);
     }
     
     public void addBeanXml(URL url)

Modified: openwebbeans/trunk/webbeans-tck/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/pom.xml?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/pom.xml (original)
+++ openwebbeans/trunk/webbeans-tck/pom.xml Mon Feb 18 17:18:56 2013
@@ -77,7 +77,7 @@
 
         <dependency>
             <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-asm-shaded</artifactId>
+            <artifactId>xbean-finder-shaded</artifactId>
         </dependency>
 
         <dependency>

Modified: openwebbeans/trunk/webbeans-web/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/pom.xml?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/pom.xml (original)
+++ openwebbeans/trunk/webbeans-web/pom.xml Mon Feb 18 17:18:56 2013
@@ -49,7 +49,7 @@
 
         <dependency>
             <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-asm-shaded</artifactId>
+            <artifactId>xbean-finder-shaded</artifactId>
         </dependency>
         
         <dependency>

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/scanner/WebScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/scanner/WebScannerService.java?rev=1447399&r1=1447398&r2=1447399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/scanner/WebScannerService.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/scanner/WebScannerService.java
Mon Feb 18 17:18:56 2013
@@ -18,22 +18,24 @@
  */
 package org.apache.webbeans.web.scanner;
 
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.ServletContext;
-
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery;
-import org.apache.webbeans.corespi.scanner.AnnotationDB;
-import org.apache.webbeans.corespi.se.BeansXmlAnnotationDB;
+import org.apache.webbeans.corespi.scanner.xbean.CdiArchive;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.util.WebBeansUtil;
-import org.scannotation.WarUrlFinder;
+import org.apache.xbean.finder.AnnotationFinder;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Configures the web application to find beans.
@@ -51,6 +53,40 @@ public class WebScannerService extends A
         
     }
 
+    @Override
+    protected AnnotationFinder initFinder()
+    {
+        final Collection<URL> trimmedUrls = new ArrayList<URL>();
+        try
+        {
+            for (final String trimmed : getArchives())
+            {
+                try
+                {
+                    String file = trimmed;
+                    if (file.endsWith(META_INF_BEANS_XML))
+                    {
+                        file = file.substring(0, file.length() - META_INF_BEANS_XML.length());
+                    }
+                    trimmedUrls.add(new URL(file));
+                }
+                catch (MalformedURLException e)
+                {
+                    throw new WebBeansConfigurationException("Can't trim url " + trimmed);
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            throw new WebBeansConfigurationException(WebBeansLoggerFacade.getTokenString(OWBLogConst.ERROR_0002),
e);
+        }
+
+        archive = new CdiArchive(WebBeansUtil.getCurrentClassLoader(), trimmedUrls);
+        finder = new AnnotationFinder(archive);
+
+        return finder;
+    }
+
     public void init(Object context)
     {
         super.init(context);
@@ -63,12 +99,7 @@ public class WebScannerService extends A
         {
             if (!configure)
             {
-                Set<String> arcs = getArchives();
-                String[] urls = new String[arcs.size()];
-                urls = arcs.toArray(urls);
-
-                getAnnotationDB().scanArchives(urls);
-                
+                initFinder();
                 configure = true;
             }
 
@@ -173,20 +204,23 @@ public class WebScannerService extends A
         if (url != null)
         {
             addWebBeansXmlLocation(url);
-            URL resourceUrl = WarUrlFinder.findWebInfClassesPath(this.servletContext);
 
-            if (resourceUrl == null)
+            URL resourceUrl = null;
+            final String path = servletContext.getRealPath("/WEB-INF/classes");
+            if (path != null)
             {
-                return null;
+                final File fp = new File(path);
+                if (fp.exists())
+                {
+                    resourceUrl = fp.toURI().toURL();
+                }
             }
 
-            //set resource to beans.xml mapping
-            AnnotationDB annotationDB = getAnnotationDB();
-
-            if(annotationDB instanceof BeansXmlAnnotationDB)
+            if (resourceUrl == null)
             {
-                ((BeansXmlAnnotationDB)annotationDB).setResourceBeansXml(resourceUrl.toExternalForm(),
url.toExternalForm());
+                return null;
             }
+
             return resourceUrl.toExternalForm();
         }
 



Mime
View raw message