in meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java [237:282]
private void addClassesToDefault(final Class<?>[] all) throws Exception {
if (all == null || all.length == 0) {
return;
}
final Field linking = AnnotationFinder.class.getDeclaredField("linking");
final Method readClassDef = AnnotationFinder.class.getDeclaredMethod("readClassDef", Class.class);
if (!readClassDef.isAccessible()) {
readClassDef.setAccessible(true);
}
if (!linking.isAccessible()) {
linking.setAccessible(true);
}
final URI uri = URI.create("jar:file://!/"); // we'll never find it during scanning and it avoids to create a custom handler
final URL url = uri.toURL();
final String key = uri.toASCIIString();
CdiArchive.FoundClasses foundClasses = archive.classesByUrl().get(key);
if (foundClasses == null) {
final BeanArchiveService beanArchiveService = webBeansContext().getBeanArchiveService();
foundClasses = new CdiArchive.FoundClasses(url, new HashSet<>(), beanArchiveService.getBeanArchiveInformation(url));
archive.classesByUrl().put(key, foundClasses);
}
foundClasses.getClassNames().addAll(Stream.of(all).map(Class::getName).collect(toSet()));
try {
linking.set(finder, true);
Stream.of(all).forEach(c -> { // populate classInfos map to support annotated mode which relies on ClassInfo
try {
readClassDef.invoke(finder, c);
} catch (final IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (final InvocationTargetException e) {
throw new IllegalStateException(e.getCause());
}
});
} finally {
try {
linking.set(finder, false);
} catch (final IllegalAccessException e) {
// no-op
}
}
}