tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1291681 - in /openejb/trunk/maven-plugins: ./ spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/ xbean-xml/ xbean-xml/src/main/java/org/apache/openejb/xbean/xml/ xbean-xml/src/test/java/org/ xbean-xml/src/test/java/...
Date Tue, 21 Feb 2012 10:04:07 GMT
Author: rmannibucau
Date: Tue Feb 21 10:04:06 2012
New Revision: 1291681

URL: http://svn.apache.org/viewvc?rev=1291681&view=rev
Log:
adding XMLAnnotationFinderHelper and a test

Added:
    openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/XmlAnnotationFinderHelperTest.java
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyAnnotation.java
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean1.java
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean2.java
    openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean3.java
    openejb/trunk/maven-plugins/xbean-xml/src/test/resources/
    openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml
Modified:
    openejb/trunk/maven-plugins/pom.xml
    openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java
    openejb/trunk/maven-plugins/xbean-xml/pom.xml

Modified: openejb/trunk/maven-plugins/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/pom.xml?rev=1291681&r1=1291680&r2=1291681&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/pom.xml (original)
+++ openejb/trunk/maven-plugins/pom.xml Tue Feb 21 10:04:06 2012
@@ -79,6 +79,11 @@
         <artifactId>xbean-finder-shaded</artifactId>
         <version>3.10-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>4.10</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 

Modified: openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java?rev=1291681&r1=1291680&r2=1291681&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java
(original)
+++ openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java
Tue Feb 21 10:04:06 2012
@@ -36,16 +36,54 @@ public class SpiMojo extends AbstractMoj
 
     static {
         final Profile jee6 = new Profile(
-                Arrays.asList( // annotations
+                Arrays.asList( // annotations, TODO: possibly remove some redundant annotations
+                        "javax.annotation.ManagedBean",
+                        "javax.annotation.PostConstruct",
+                        "javax.annotation.PreDestroy",
+                        "javax.annotation.Resource",
+                        "javax.annotation.Resources",
+                        "javax.annotation.security.DenyAll",
+                        "javax.annotation.security.PermitAll",
+                        "javax.annotation.security.RolesAllowed",
+                        "javax.annotation.sql.DataSourceDefinition",
+                        "javax.ejb.AfterBegin",
+                        "javax.ejb.AfterCompletion",
+                        "javax.ejb.ApplicationException",
+                        "javax.ejb.Asynchronous",
+                        "javax.ejb.BeforeCompletion",
+                        "javax.ejb.ConcurrencyManagement",
+                        "javax.ejb.DependsOn",
+                        "javax.ejb.EJB",
+                        "javax.ejb.EJBs",
+                        "javax.ejb.Init",
+                        "javax.ejb.LocalBean",
+                        "javax.ejb.LocalHome",
+                        "javax.ejb.MessageDriven",
+                        "javax.ejb.PostActivate",
+                        "javax.ejb.PrePassivate",
+                        "javax.ejb.RemoteHome",
+                        "javax.ejb.Remove",
+                        "javax.ejb.Schedule",
+                        "javax.ejb.Schedules",
                         "javax.ejb.Singleton",
                         "javax.ejb.Stateful",
                         "javax.ejb.Stateless",
+                        "javax.ejb.Timeout",
                         "javax.enterprise.inject.Specializes",
-                        "javax.annotation.ManagedBean",
-                        "javax.ejb.MessageDriven",
-
-                        "org.apache.openejb.api.LocalClient",
-                        "org.apache.openejb.api.RemoteClient"
+                        "javax.interceptor.AroundInvoke",
+                        "javax.interceptor.AroundTimeout",
+                        "javax.interceptor.ExcludeClassInterceptors",
+                        "javax.interceptor.ExcludeDefaultInterceptors",
+                        "javax.interceptor.Interceptors",
+                        "javax.jws.WebService",
+                        "javax.persistence.PersistenceContext",
+                        "javax.persistence.PersistenceContexts",
+                        "javax.persistence.PersistenceUnit",
+                        "javax.persistence.PersistenceUnits",
+                        "javax.ws.rs.Path",
+                        "javax.xml.ws.WebServiceProvider",
+                        "javax.xml.ws.WebServiceRef",
+                        "javax.xml.ws.WebServiceRefs"
                 ),
                 Arrays.asList( // subclasses
                         "javax.ws.rs.core.Application"

Modified: openejb/trunk/maven-plugins/xbean-xml/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/pom.xml?rev=1291681&r1=1291680&r2=1291681&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/pom.xml (original)
+++ openejb/trunk/maven-plugins/xbean-xml/pom.xml Tue Feb 21 10:04:06 2012
@@ -17,5 +17,9 @@
       <groupId>org.apache.xbean</groupId>
       <artifactId>xbean-finder-shaded</artifactId>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
   </dependencies>
 </project>

Added: openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java?rev=1291681&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java
(added)
+++ openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java
Tue Feb 21 10:04:06 2012
@@ -0,0 +1,49 @@
+package org.apache.openejb.xbean.xml;
+
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.IAnnotationFinder;
+import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.ClassesArchive;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+
+public final class XMLAnnotationFinderHelper {
+    private static final JAXBContext JAXB_CONTEXT;
+    static {
+        try {
+            JAXB_CONTEXT = JAXBContext.newInstance(Scan.class);
+        } catch (JAXBException e) {
+            throw new RuntimeException(e); // TODO: handle it with a custom exception
+        }
+    }
+
+    private XMLAnnotationFinderHelper() {
+        // no-op
+    }
+
+    public static IAnnotationFinder finderFromXml(final InputStream is, final ClassLoader
loader) throws JAXBException {
+        final Scan scan = (Scan) JAXB_CONTEXT.createUnmarshaller().unmarshal(new BufferedInputStream(is));
+
+        Class<?>[] classes = new Class<?>[scan.getClassname().size()];
+        int i = 0;
+        for (String clazz : scan.getClassname()) {
+            try {
+                classes[i++] = loader.loadClass(clazz);
+            } catch (ClassNotFoundException e) {
+                // ignored
+            }
+        }
+
+        if (i != classes.length) { // shouldn't occur
+            final Class<?>[] updatedClasses = new Class<?>[i];
+            System.arraycopy(classes, 0, updatedClasses, 0, i);
+            classes = updatedClasses;
+        }
+
+        final Archive archive = new ClassesArchive(classes);
+        return new AnnotationFinder(archive).link();
+    }
+}

Added: openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/XmlAnnotationFinderHelperTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/XmlAnnotationFinderHelperTest.java?rev=1291681&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/XmlAnnotationFinderHelperTest.java
(added)
+++ openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/XmlAnnotationFinderHelperTest.java
Tue Feb 21 10:04:06 2012
@@ -0,0 +1,51 @@
+package org.apache.openejb.xbean.xml;
+
+import org.apache.openejb.xbean.xml.bean.MyAnnotation;
+import org.apache.openejb.xbean.xml.bean.MyBean1;
+import org.apache.openejb.xbean.xml.bean.MyBean2;
+import org.apache.openejb.xbean.xml.bean.MyBean3;
+import org.apache.xbean.finder.IAnnotationFinder;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class XmlAnnotationFinderHelperTest {
+    private static IAnnotationFinder finder;
+
+    @BeforeClass
+    public static void initFinder() throws JAXBException {
+        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        finder = XMLAnnotationFinderHelper.finderFromXml(loader.getResourceAsStream("test-scan.xml"),
loader);
+    }
+
+    @Test
+    public void findClass() {
+        final List<Class<?>> myClassAnnotated = finder.findAnnotatedClasses(MyAnnotation.class);
+        assertEquals(1, myClassAnnotated.size());
+        assertEquals(MyBean1.class, myClassAnnotated.iterator().next());
+    }
+
+    @Test
+    public void findMethod() {
+        final List<Method> myMethodAnnotated = finder.findAnnotatedMethods(MyAnnotation.class);
+        assertEquals(1, myMethodAnnotated.size());
+        final Method method = myMethodAnnotated.iterator().next();
+        assertEquals(MyBean2.class, method.getDeclaringClass());
+        assertEquals("aMethod", method.getName());
+    }
+
+    @Test
+    public void findField() {
+        final List<Field> myFieldAnnotated = finder.findAnnotatedFields(MyAnnotation.class);
+        assertEquals(1, myFieldAnnotated.size());
+        final Field field = myFieldAnnotated.iterator().next();
+        assertEquals(MyBean3.class, field.getDeclaringClass());
+        assertEquals("aField", field.getName());
+    }
+}

Added: openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyAnnotation.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyAnnotation.java?rev=1291681&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyAnnotation.java
(added)
+++ openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyAnnotation.java
Tue Feb 21 10:04:06 2012
@@ -0,0 +1,11 @@
+package org.apache.openejb.xbean.xml.bean;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+public @interface MyAnnotation {
+}

Added: openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean1.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean1.java?rev=1291681&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean1.java
(added)
+++ openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean1.java
Tue Feb 21 10:04:06 2012
@@ -0,0 +1,5 @@
+package org.apache.openejb.xbean.xml.bean;
+
+@MyAnnotation
+public class MyBean1 {
+}

Added: openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean2.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean2.java?rev=1291681&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean2.java
(added)
+++ openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean2.java
Tue Feb 21 10:04:06 2012
@@ -0,0 +1,6 @@
+package org.apache.openejb.xbean.xml.bean;
+
+public class MyBean2 {
+    @MyAnnotation
+    public void aMethod() {}
+}

Added: openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean3.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean3.java?rev=1291681&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean3.java
(added)
+++ openejb/trunk/maven-plugins/xbean-xml/src/test/java/org/apache/openejb/xbean/xml/bean/MyBean3.java
Tue Feb 21 10:04:06 2012
@@ -0,0 +1,6 @@
+package org.apache.openejb.xbean.xml.bean;
+
+public class MyBean3 {
+    @MyAnnotation
+    private int aField;
+}

Added: openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml?rev=1291681&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml (added)
+++ openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml Tue Feb 21 10:04:06
2012
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<scan>
+  <classes>
+    <class>org.apache.openejb.xbean.xml.bean.MyBean1</class>
+    <class>org.apache.openejb.xbean.xml.bean.MyBean2</class>
+    <class>org.apache.openejb.xbean.xml.bean.MyBean3</class>
+  </classes>
+  <packages/>
+</scan>
\ No newline at end of file



Mime
View raw message