Search in sources :

Example 21 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class ClassAnnotationFinderTest method checkClassAnnotationOnConstructorDefaults.

@Test
public void checkClassAnnotationOnConstructorDefaults() {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class));
    final List<Constructor> annotations = finder.findAnnotatedConstructors(ClassAnnotation.class);
    assertEquals(0, annotations.size());
}
Also used : ClassAnnotatedClass(org.acme.ClassAnnotatedClass) Constructor(java.lang.reflect.Constructor) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 22 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class ClassAnnotationFinderTest method checkClassAnnotationOnConstructor.

@Test
public void checkClassAnnotationOnConstructor() throws Exception {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class), false);
    final List<Constructor> annotations = finder.findAnnotatedConstructors(ClassAnnotation.class);
    assertEquals(1, annotations.size());
    assertEquals(ClassAnnotatedClass.class.getDeclaredConstructor(), annotations.get(0));
}
Also used : ClassAnnotatedClass(org.acme.ClassAnnotatedClass) Constructor(java.lang.reflect.Constructor) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 23 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class ClassAnnotationFinderTest method checkClassAnnotationIsNotFound.

@Test
public void checkClassAnnotationIsNotFound() {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class));
    final List<Class<?>> annotations = finder.findAnnotatedClasses(ClassAnnotation.class);
    assertEquals(0, annotations.size());
}
Also used : ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassMultipleAnnotatedClass(org.acme.ClassMultipleAnnotatedClass) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 24 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class ClassAnnotationFinderTest method checkClassAnnotationOnMethodDefaults.

@Test
public void checkClassAnnotationOnMethodDefaults() {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class));
    final List<Method> annotations = finder.findAnnotatedMethods(ClassAnnotation.class);
    assertEquals(0, annotations.size());
}
Also used : ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Method(java.lang.reflect.Method) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 25 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project tomee by apache.

the class ApplicationComposers method finderFromClasses.

private static IAnnotationFinder finderFromClasses(final DeploymentModule module, final Class<?>[] value, final Collection<File> others, final String[] excludes) {
    final Collection<Archive> archives = new ArrayList<>(1 + (others == null ? 0 : others.size()));
    final Filter filter = excludes == null || excludes.length == 0 ? null : Filters.invert(Filters.prefixes(excludes));
    final Collection<Class<?>> classes = new ArrayList<>(asList(FinderFactory.ensureMinimalClasses(module)));
    if (value != null) {
        classes.addAll(asList(value));
    }
    final ClassesArchive classesArchive = new ClassesArchive(classes);
    archives.add(filter == null ? classesArchive : new FilteredArchive(classesArchive, filter));
    if (others != null) {
        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        for (final File f : others) {
            try {
                final Archive archive = f.isDirectory() ? new FileArchive(classLoader, f) : new JarArchive(classLoader, f.toURI().toURL());
                archives.add(filter == null ? archive : new FilteredArchive(archive, filter));
            } catch (final MalformedURLException e) {
                throw new IllegalArgumentException(e);
            }
        }
    }
    return new FinderFactory.OpenEJBAnnotationFinder(new CompositeArchive(archives)).link();
}
Also used : MalformedURLException(java.net.MalformedURLException) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive) JarArchive(org.apache.xbean.finder.archive.JarArchive) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) Archive(org.apache.xbean.finder.archive.Archive) ArrayList(java.util.ArrayList) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) FinderFactory(org.apache.openejb.config.FinderFactory) Filter(org.apache.xbean.finder.filter.Filter) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) JarArchive(org.apache.xbean.finder.archive.JarArchive) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive) File(java.io.File)

Aggregations

ClassesArchive (org.apache.xbean.finder.archive.ClassesArchive)33 Test (org.junit.Test)14 AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)12 NotAnnotated (org.acme.NotAnnotated)10 ClassAnnotatedClass (org.acme.ClassAnnotatedClass)8 Method (java.lang.reflect.Method)7 URL (java.net.URL)7 CompositeArchive (org.apache.xbean.finder.archive.CompositeArchive)7 FilteredArchive (org.apache.xbean.finder.archive.FilteredArchive)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 EjbModule (org.apache.openejb.config.EjbModule)6 EjbJar (org.apache.openejb.jee.EjbJar)6 Archive (org.apache.xbean.finder.archive.Archive)6 MalformedURLException (java.net.MalformedURLException)5 AppModule (org.apache.openejb.config.AppModule)5 File (java.io.File)4 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4