You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/11/15 18:38:48 UTC

svn commit: r1409894 - in /openejb/trunk/openejb: arquillian/arquillian-tomee-tests/ arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/ear/ container/openejb-core/src/main/java/org/apa...

Author: rmannibucau
Date: Thu Nov 15 17:38:47 2012
New Revision: 1409894

URL: http://svn.apache.org/viewvc?rev=1409894&view=rev
Log:
TOMEE-576 be a bit tolerant if @WebXXX classes are not well packaged in ear

Modified:
    openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/ear/EarTest.java
    openejb/trunk/openejb/arquillian/arquillian-tomee-tests/pom.xml
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java

Modified: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/ear/EarTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/ear/EarTest.java?rev=1409894&r1=1409893&r2=1409894&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/ear/EarTest.java (original)
+++ openejb/trunk/openejb/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/ear/EarTest.java Thu Nov 15 17:38:47 2012
@@ -62,7 +62,7 @@ public class EarTest {
         System.out.println();
 
         final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "red.ear").addAsModule(ejbJar).addAsModule(webapp);
-        //ear.addAsLibraries(JarLocation.jarLocation(Test.class));
+        ear.addAsLibraries(JarLocation.jarLocation(Test.class));
 
         System.out.println(ear.toString(true));
         System.out.println();

Modified: openejb/trunk/openejb/arquillian/arquillian-tomee-tests/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-tests/pom.xml?rev=1409894&r1=1409893&r2=1409894&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian/arquillian-tomee-tests/pom.xml (original)
+++ openejb/trunk/openejb/arquillian/arquillian-tomee-tests/pom.xml Thu Nov 15 17:38:47 2012
@@ -356,6 +356,7 @@
               <skip>true</skip>
               <parallel>none</parallel>
               <threadCount>1</threadCount>
+<includes><include>**/Ear*</include></includes>
             </configuration>
           </plugin>
         </plugins>

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1409894&r1=1409893&r2=1409894&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Thu Nov 15 17:38:47 2012
@@ -214,6 +214,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
@@ -1127,6 +1128,8 @@ public class AnnotationDeployer implemen
             /*
              * Servlet, Filter, Listener
              */
+
+            Map<URL, List<String>> urlByClasses = null;
             for (String apiClassName : WEB_CLASSES) {
                 final Class<? extends Annotation> clazz;
                 try {
@@ -1135,8 +1138,20 @@ public class AnnotationDeployer implemen
                     continue;
                 }
 
+                if (urlByClasses == null) { // try to reuse scanning info, maybe some better indexing can be a nice idea
+                    if (finder instanceof FinderFactory.ModuleLimitedFinder) {
+                        final IAnnotationFinder limitedFinder = ((FinderFactory.ModuleLimitedFinder) finder).getDelegate();
+                        if (limitedFinder instanceof AnnotationFinder) {
+                            final Archive archive = ((AnnotationFinder) limitedFinder).getArchive();
+                            if (archive instanceof WebappAggregatedArchive) {
+                                urlByClasses = ((WebappAggregatedArchive) archive).getClassesMap();
+                            }
+                        }
+                    }
+                }
+
                 final List<Annotated<Class<?>>> found = finder.findMetaAnnotatedClasses(clazz);
-                addWebAnnotatedClassInfo(webModule.getWebAnnotatedClasses(), found);
+                addWebAnnotatedClassInfo(urlByClasses, webModule.getWebAnnotatedClasses(), found);
             }
 
             return webModule;
@@ -5206,17 +5221,31 @@ public class AnnotationDeployer implemen
         return classes;
     }
 
-    private static Map<String, Set<String>> addWebAnnotatedClassInfo(final Map<String, Set<String>> classes, final List<Annotated<Class<?>>> found) {
+    private static Map<String, Set<String>> addWebAnnotatedClassInfo(final Map<URL, List<String>> urlByClasses, final Map<String, Set<String>> classes, final List<Annotated<Class<?>>> found) {
         for (Annotated<Class<?>> clazz : found) {
             final Class<?> loadedClass = clazz.get();
+            final String name = loadedClass.getName();
 
             // url of the jar/folder containing the class
-            String url;
-            try {
-                url = JarLocation.jarLocation(loadedClass).toURI().toURL().toExternalForm();
-            } catch (MalformedURLException e) {
-                url = classLocation(loadedClass).toExternalForm();
+            String url = null;
+            if (urlByClasses != null) {
+                for (Map.Entry<URL, List<String>> entry : urlByClasses.entrySet()) {
+                    for (String current : entry.getValue()) {
+                        if (name.equals(current)) {
+                            url = entry.getKey().toExternalForm();
+                        }
+                    }
+                }
+            }
+
+            if (url == null) {
+                try {
+                    url = JarLocation.jarLocation(loadedClass).toURI().toURL().toExternalForm();
+                } catch (MalformedURLException e) {
+                    url = classLocation(loadedClass).toExternalForm();
+                }
             }
+
             Set<String> list = classes.get(url);
             if (list == null) {
                 list = new HashSet<String>();
@@ -5224,7 +5253,20 @@ public class AnnotationDeployer implemen
             }
 
             // saving class url
-            list.add(classLocation(loadedClass).toExternalForm());
+            // first try the file approach (if the same class is in several classloaders it avoids weird errors)
+            try {
+                final File dir = new File(new URL(url).toURI());
+                if (dir.isDirectory()) {
+                    final File fileClazz = new File(dir, name.replace('.', '/') + ".class");
+                    if (fileClazz.exists()) {
+                        list.add(fileClazz.toURI().toURL().toExternalForm());
+                    } else {
+                        list.add(classLocation(loadedClass).toExternalForm());
+                    }
+                }
+            } catch (Exception e) {
+                list.add(classLocation(loadedClass).toExternalForm());
+            }
         }
         return classes;
     }

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java?rev=1409894&r1=1409893&r2=1409894&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java (original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java Thu Nov 15 17:38:47 2012
@@ -220,8 +220,6 @@ public class OpenEJBContextConfig extend
                 internalProcessAnnotationsStream(webAnnotated.list, fragment, handlesTypeOnly);
             } catch (MalformedURLException e) {
                 throw new IllegalArgumentException(e);
-            } catch (IOException e) {
-                throw new IllegalArgumentException(e);
             }
         }
     }