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();
}
}
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);
}
}
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());
}
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();
}
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;
}
}
Aggregations