tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [1/2] tomee git commit: adding @Default to application composer to scan runner jar automatically
Date Fri, 06 Feb 2015 09:03:08 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop da12fb12c -> 7da9d6f08


adding @Default to application composer to scan runner jar automatically


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a0c37da9
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a0c37da9
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a0c37da9

Branch: refs/heads/develop
Commit: a0c37da955c1f40652862fb8847d497838e47d66
Parents: da12fb1
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Fri Feb 6 09:55:14 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Fri Feb 6 09:55:14 2015 +0100

----------------------------------------------------------------------
 .../openejb/testing/ApplicationComposers.java   | 64 +++++++++++++++++---
 .../org/apache/openejb/testing/Default.java     | 31 ++++++++++
 2 files changed, 85 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a0c37da9/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
index 3c41676..43543e6 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
@@ -88,6 +88,7 @@ import org.apache.xbean.finder.UrlSet;
 import org.apache.xbean.finder.archive.Archive;
 import org.apache.xbean.finder.archive.ClassesArchive;
 import org.apache.xbean.finder.archive.CompositeArchive;
+import org.apache.xbean.finder.archive.FileArchive;
 import org.apache.xbean.finder.archive.JarArchive;
 import org.xml.sax.InputSource;
 
@@ -124,6 +125,7 @@ import java.util.concurrent.CountDownLatch;
 
 import static java.util.Arrays.asList;
 import static org.apache.openejb.config.DeploymentFilterable.DEPLOYMENTS_CLASSPATH_PROPERTY;
+import static org.apache.openejb.loader.JarLocation.jarLocation;
 import static org.apache.openejb.util.Classes.ancestors;
 
 @SuppressWarnings("deprecation")
@@ -306,7 +308,7 @@ public final class ApplicationComposers {
             errors.add(new Exception(gripe));
         }
 
-        if (modules < 1 && testClass.getAnnotation(Classes.class) == null) {
+        if (modules < 1 && testClass.getAnnotation(Classes.class) == null &&
testClass.getAnnotation(Default.class) == null) {
             final String gripe = "Test class should have at least one @Module method";
             errors.add(new Exception(gripe));
         }
@@ -529,6 +531,7 @@ public final class ApplicationComposers {
                 final Jars jarsAnnotation = method.getAnnotation(Jars.class);
                 final Classes classesAnnotation = method.getAnnotation(Classes.class);
                 final org.apache.openejb.junit.Classes classesAnnotationOld = method.getAnnotation(org.apache.openejb.junit.Classes.class);
+                final boolean defaultConfig = method.getAnnotation(Default.class) != null;
 
                 Class<?>[] classes = null;
                 Class<?>[] cdiInterceptors = null;
@@ -559,7 +562,8 @@ public final class ApplicationComposers {
                         method.getAnnotation(Descriptors.class), method.getAnnotation(JaxrsProviders.class),
                         webApp,
                         globalJarsAnnotation, jarsAnnotation,
-                        classes, cdiInterceptors, cdiAlternatives, cdiDecorators, cdi, innerClassesAsBean);
+                        classes, cdiInterceptors, cdiAlternatives, cdiDecorators, cdi, innerClassesAsBean,
+                        defaultConfig);
                 } else if (obj instanceof WebModule) { // will add the ejbmodule too
                     webModulesNb++;
 
@@ -574,7 +578,11 @@ public final class ApplicationComposers {
                         ejbModule.setBeans(beans(new Beans(), cdiDecorators, cdiInterceptors,
cdiAlternatives));
                     }
 
-                    webModule.setFinder(finderFromClasses(webModule, classes, findFiles(jarsAnnotation)));
+                    Collection<File> files = findFiles(jarsAnnotation);
+                    if (defaultConfig) {
+                        (files == null ? files = new LinkedList<>() : files).add(jarLocation(testClass));
+                    }
+                    webModule.setFinder(finderFromClasses(webModule, classes, files));
                     ejbModule.setFinder(webModule.getFinder());
                 } else if (obj instanceof EjbModule) {
                     final EjbModule ejbModule = (EjbModule) obj;
@@ -588,7 +596,11 @@ public final class ApplicationComposers {
                         ejbModule.setBeans(beans(new Beans(), cdiDecorators, cdiInterceptors,
cdiAlternatives));
                     }
 
-                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, findFiles(jarsAnnotation)));
+                    Collection<File> files = findFiles(jarsAnnotation);
+                    if (defaultConfig) {
+                        (files == null ? files = new LinkedList<>() : files).add(jarLocation(testClass));
+                    }
+                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, files));
                 } else if (obj instanceof EjbJar) {
 
                     final EjbJar ejbJar = (EjbJar) obj;
@@ -604,7 +616,11 @@ public final class ApplicationComposers {
                         ejbModule.setBeans(beans(new Beans(), cdiDecorators, cdiInterceptors,
cdiAlternatives));
                     }
 
-                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, findFiles(jarsAnnotation)));
+                    Collection<File> files = findFiles(jarsAnnotation);
+                    if (defaultConfig) {
+                        (files == null ? files = new LinkedList<>() : files).add(jarLocation(testClass));
+                    }
+                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, files));
                 } else if (obj instanceof EnterpriseBean) {
 
                     final EnterpriseBean bean = (EnterpriseBean) obj;
@@ -618,7 +634,11 @@ public final class ApplicationComposers {
                     if (cdi) {
                         ejbModule.setBeans(beans(new Beans(), cdiDecorators, cdiInterceptors,
cdiAlternatives));
                     }
-                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, findFiles(jarsAnnotation)));
+                    Collection<File> files = findFiles(jarsAnnotation);
+                    if (defaultConfig) {
+                        (files == null ? files = new LinkedList<>() : files).add(jarLocation(testClass));
+                    }
+                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, files));
                 } else if (obj instanceof Application) {
 
                     application = (Application) obj;
@@ -649,7 +669,11 @@ public final class ApplicationComposers {
                     if (cdi) {
                         ejbModule.setBeans(beans(beans, cdiDecorators, cdiInterceptors, cdiAlternatives));
                     }
-                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, findFiles(jarsAnnotation)));
+                    Collection<File> files = findFiles(jarsAnnotation);
+                    if (defaultConfig) {
+                        (files == null ? files = new LinkedList<>() : files).add(jarLocation(testClass));
+                    }
+                    ejbModule.setFinder(finderFromClasses(ejbModule, classes, files));
                 } else if (obj instanceof Class[]) {
 
                     final Class[] beans = (Class[]) obj;
@@ -711,7 +735,7 @@ public final class ApplicationComposers {
                     null, null,
                     webapp, globalJarsAnnotation, null, classClasses.value(),
                     classClasses.cdiInterceptors(), classClasses.cdiAlternatives(), classClasses.cdiDecorators(),
-                    classClasses.cdi(), classClasses.innerClassesAsBean());
+                    classClasses.cdi(), classClasses.innerClassesAsBean(), testClass.getAnnotation(Default.class)
!= null);
             webModulesNb++;
         }
 
@@ -880,7 +904,8 @@ public final class ApplicationComposers {
                           final Class<?>[] cdiAlternatives,
                           final Class<?>[] cdiDecorators,
                           final boolean cdi,
-                          final boolean innerClassesAsBean) throws OpenEJBException {
+                          final boolean innerClassesAsBean,
+                          final boolean autoConfig) throws OpenEJBException {
         String root = webapp.getContextRoot();
         if (root == null) {
             root = "/openejb";
@@ -890,6 +915,18 @@ public final class ApplicationComposers {
 
         final WebModule webModule = new WebModule(webapp, root, Thread.currentThread().getContextClassLoader(),
"", root);
 
+        final File thisJar;
+        if (autoConfig) {
+            thisJar = jarLocation(testClass);
+            try {
+                webModule.getAltDDs().putAll(DeploymentLoader.mapDescriptors(new ResourceFinder("",
webModule.getClassLoader(), thisJar.toURI().toURL())));
+            } catch (final IOException e) {
+                throw new IllegalStateException(e);
+            }
+        } else {
+            thisJar = null;
+        }
+
         webModule.getAltDDs().putAll(additionalDescriptors);
         for (final Descriptors d : asList(testClass.getAnnotation(Descriptors.class), descriptors))
{
             if (d != null) {
@@ -946,6 +983,13 @@ public final class ApplicationComposers {
                 libs.addAll(files);
             }
         }
+        if (autoConfig) {
+            if (libs == null) {
+                libs = new LinkedList<>();
+            }
+            libs.add(thisJar);
+        }
+
         final IAnnotationFinder finder = finderFromClasses(webModule, classes, libs);
         webModule.setFinder(finder);
         ejbModule.setFinder(webModule.getFinder());
@@ -1224,7 +1268,7 @@ public final class ApplicationComposers {
             final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
             for (final File f : others) {
                 try {
-                    archives.add(new JarArchive(classLoader, f.toURI().toURL()));
+                    archives.add(f.isDirectory() ? new FileArchive(classLoader, f) : new
JarArchive(classLoader, f.toURI().toURL()));
                 } catch (final MalformedURLException e) {
                     throw new IllegalArgumentException(e);
                 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a0c37da9/container/openejb-core/src/main/java/org/apache/openejb/testing/Default.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/Default.java
b/container/openejb-core/src/main/java/org/apache/openejb/testing/Default.java
new file mode 100644
index 0000000..91ea33b
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/Default.java
@@ -0,0 +1,31 @@
+/*
+ * 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.openejb.testing;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Add jar containing the running class to the scanned jars.
+ */
+@Target({ ElementType.TYPE, ElementType.METHOD })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Default {
+}


Mime
View raw message