Search in sources :

Example 6 with JarArchive

use of org.apache.xbean.finder.archive.JarArchive in project component-runtime by Talend.

the class Generator method generatedActions.

private static void generatedActions(final File generatedDir) throws Exception {
    final File file = new File(generatedDir, "generated_actions.adoc");
    try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
        stream.println("");
        stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
        stream.println("|====");
        stream.println("|API|Type|Description|Return type|Sample returned type");
        final File api = jarLocation(ActionType.class);
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
        finder.findAnnotatedClasses(ActionType.class).stream().sorted(Comparator.comparing(t -> t.getAnnotation(ActionType.class).value() + "#" + t.getSimpleName())).forEach(type -> {
            final ActionType actionType = type.getAnnotation(ActionType.class);
            final Class<?> returnedType = actionType.expectedReturnedType();
            stream.println("|@" + type.getName() + "|" + actionType.value() + "|" + extractDoc(type) + "|" + (returnedType == Object.class ? "any" : returnedType.getSimpleName()) + "|" + (returnedType != Object.class ? "`" + sample(returnedType).replace("\n", "") + "`" : "-"));
        });
        stream.println("|====");
        stream.println();
    }
}
Also used : PrintStream(java.io.PrintStream) ActionType(org.talend.sdk.component.api.service.ActionType) JarArchive(org.apache.xbean.finder.archive.JarArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive) File(java.io.File) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder)

Example 7 with JarArchive

use of org.apache.xbean.finder.archive.JarArchive in project stdlib by petergeneric.

the class ClassScannerFactory method getArchivesForPackage.

private static CompositeArchive getArchivesForPackage(final ClassLoader classloader, final String... packages) {
    try {
        final List<Archive> archives = new ArrayList<>();
        for (String pkg : packages) {
            if (!pkg.endsWith("."))
                // Add a trailing dot for easier package matching
                pkg += ".";
            final String baseFolder = pkg.replace('.', '/');
            final Enumeration<URL> urls = classloader.getResources(baseFolder);
            while (urls.hasMoreElements()) {
                final URL url = urls.nextElement();
                if (log.isTraceEnabled())
                    log.trace("Found source: " + url);
                if (url.getProtocol() != null && (url.getProtocol().equals("zip") || url.getProtocol().equals("jar")))
                    archives.add(new FilteredArchive(new JarArchive(classloader, url), new PrefixFilter(pkg)));
                else
                    archives.add(new FileArchive(classloader, url, pkg));
            }
        }
        return new CompositeArchive(archives);
    } catch (IOException e) {
        throw new IllegalArgumentException("Error loading archives for packages: " + Arrays.asList(packages), e);
    }
}
Also used : JarArchive(org.apache.xbean.finder.archive.JarArchive) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) Archive(org.apache.xbean.finder.archive.Archive) PrefixFilter(org.apache.xbean.finder.filter.PrefixFilter) ArrayList(java.util.ArrayList) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) IOException(java.io.IOException) URL(java.net.URL) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) JarArchive(org.apache.xbean.finder.archive.JarArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive)

Example 8 with JarArchive

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

the class FileDecodeFinderTest method doTest.

private void doTest(final File lib) throws MalformedURLException {
    final AnnotationFinder all = new AnnotationFinder(new JarArchive(Thread.currentThread().getContextClassLoader(), lib.toURI().toURL()));
    assertEquals(1, all.findAnnotatedClasses(Marker.class).size());
}
Also used : JarArchive(org.apache.xbean.finder.archive.JarArchive)

Example 9 with JarArchive

use of org.apache.xbean.finder.archive.JarArchive 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)

Example 10 with JarArchive

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

the class ScanJarService method ensureInit.

private void ensureInit() throws Exception {
    if (beans != null) {
        return;
    }
    synchronized (this) {
        if (beans != null) {
            return;
        }
        final ClassLoader loader = ParentClassLoaderFinder.Helper.get();
        final CompositeBeans mergedModel = new CompositeBeans();
        for (final File file : findFiles()) {
            final URL url = file.toURI().toURL();
            if (file.isDirectory()) {
                final FinderFactory.OpenEJBAnnotationFinder finder = new FinderFactory.OpenEJBAnnotationFinder(new FileArchive(loader, file));
                mergedModel.getManagedClasses().put(url, finder.getAnnotatedClassNames());
                final File beansXml = new File(file, "META-INF/beans.xml");
                if (beansXml.exists()) {
                    try (final FileInputStream inputStream = new FileInputStream(beansXml)) {
                        final Beans beansModel = ReadDescriptors.readBeans(inputStream);
                        mergedModel.mergeClasses(url, beansModel);
                    }
                }
            } else {
                final FinderFactory.OpenEJBAnnotationFinder finder = new FinderFactory.OpenEJBAnnotationFinder(new JarArchive(loader, url));
                mergedModel.getManagedClasses().put(url, finder.getAnnotatedClassNames());
                try (final URLClassLoader cl = new URLClassLoader(new URL[] { url })) {
                    try (final InputStream is = cl.getResourceAsStream("META-INF/beans.xml")) {
                        if (is != null) {
                            final Beans beansModel = ReadDescriptors.readBeans(is);
                            mergedModel.mergeClasses(url, beansModel);
                        }
                    }
                }
            }
        }
        beans = mergedModel;
    }
}
Also used : CompositeBeans(org.apache.openejb.cdi.CompositeBeans) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FinderFactory(org.apache.openejb.config.FinderFactory) URL(java.net.URL) FileInputStream(java.io.FileInputStream) Beans(org.apache.openejb.jee.Beans) CompositeBeans(org.apache.openejb.cdi.CompositeBeans) JarArchive(org.apache.xbean.finder.archive.JarArchive) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) FileArchive(org.apache.xbean.finder.archive.FileArchive) File(java.io.File)

Aggregations

JarArchive (org.apache.xbean.finder.archive.JarArchive)12 File (java.io.File)10 FileArchive (org.apache.xbean.finder.archive.FileArchive)10 PrintStream (java.io.PrintStream)7 AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 Mapper (org.apache.johnzon.mapper.Mapper)5 MapperBuilder (org.apache.johnzon.mapper.MapperBuilder)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Map (java.util.Map)4 Condition (org.talend.sdk.component.api.configuration.condition.meta.Condition)4 ConfigurationType (org.talend.sdk.component.api.configuration.type.meta.ConfigurationType)4 ActionType (org.talend.sdk.component.api.service.ActionType)4 ConditionParameterEnricher (org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ConditionParameterEnricher)4 ConfigurationTypeParameterEnricher (org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ConfigurationTypeParameterEnricher)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 FilterOutputStream (java.io.FilterOutputStream)3