use of org.apache.webbeans.corespi.scanner.xbean.CdiArchive in project meecrowave by apache.
the class MeecrowaveContextConfig method webConfig.
@Override
protected void webConfig() {
if (context.getServletContext().getAttribute("meecrowave.configuration") == null) {
// redeploy
context.getServletContext().setAttribute("meecrowave.configuration", configuration);
context.addServletContainerInitializer(intializer, emptySet());
}
if (!configuration.isTomcatScanning()) {
super.webConfig();
return;
}
// eagerly start CDI to scan only once and not twice (tomcat+CDI)
// should already be started at that point
final ClassLoader loader = context.getLoader().getClassLoader();
final Thread thread = Thread.currentThread();
final ClassLoader old = thread.getContextClassLoader();
thread.setContextClassLoader(loader);
try {
final OWBTomcatWebScannerService scannerService = OWBTomcatWebScannerService.class.cast(WebBeansContext.getInstance().getScannerService());
scannerService.setFilter(ofNullable(context.getJarScanner()).map(JarScanner::getJarScanFilter).orElse(null), context.getServletContext());
scannerService.setDocBase(context.getDocBase());
scannerService.setShared(configuration.getSharedLibraries());
if (configuration.getWatcherBouncing() > 0) {
// note that caching should be disabled with this config in most of the times
watcher = new ReloadOnChangeController(context, configuration.getWatcherBouncing());
scannerService.setFileVisitor(f -> watcher.register(f));
}
scannerService.scan();
finder = scannerService.getFinder();
finder.link();
final CdiArchive archive = CdiArchive.class.cast(finder.getArchive());
Stream.of(WebServlet.class, WebFilter.class, WebListener.class).forEach(marker -> finder.findAnnotatedClasses(marker).stream().filter(c -> !Modifier.isAbstract(c.getModifiers()) && Modifier.isPublic(c.getModifiers())).forEach(webComponent -> webClasses.computeIfAbsent(archive.classesByUrl().entrySet().stream().filter(e -> e.getValue().getClassNames().contains(webComponent.getName())).findFirst().get().getKey(), k -> new HashSet<>()).add(webComponent)));
} finally {
thread.setContextClassLoader(old);
}
try {
super.webConfig();
} finally {
webClasses.clear();
finder = null;
}
}
use of org.apache.webbeans.corespi.scanner.xbean.CdiArchive in project meecrowave by apache.
the class MeecrowaveContextConfig method webConfig.
@Override
protected void webConfig() {
if (context.getServletContext().getAttribute("meecrowave.configuration") == null) {
// redeploy
context.getServletContext().setAttribute("meecrowave.configuration", Meecrowave.Builder.class.isInstance(configuration) ? configuration : new Meecrowave.Builder(configuration));
context.addServletContainerInitializer(intializer, emptySet());
}
if (!configuration.isTomcatScanning()) {
super.webConfig();
return;
}
// eagerly start CDI to scan only once and not twice (tomcat+CDI)
// should already be started at that point
final ClassLoader loader = context.getLoader().getClassLoader();
final Thread thread = Thread.currentThread();
final ClassLoader old = thread.getContextClassLoader();
thread.setContextClassLoader(loader);
try {
final ScannerService service = WebBeansContext.getInstance().getScannerService();
if (OWBTomcatWebScannerService.class.isInstance(service)) {
final OWBTomcatWebScannerService scannerService = OWBTomcatWebScannerService.class.cast(service);
scannerService.setFilter(ofNullable(context.getJarScanner()).map(JarScanner::getJarScanFilter).orElse(null), context.getServletContext());
scannerService.setDocBase(context.getDocBase());
scannerService.setShared(configuration.getSharedLibraries());
if (configuration.getWatcherBouncing() > 0) {
// note that caching should be disabled with this config in most of the times
watcher = new ReloadOnChangeController(context, configuration.getWatcherBouncing(), redeployCallback);
scannerService.setFileVisitor(f -> watcher.register(f));
}
scannerService.scan();
finder = scannerService.getFinder();
finder.link();
final CdiArchive archive = CdiArchive.class.cast(finder.getArchive());
Stream.of(WebServlet.class, WebFilter.class, WebListener.class).forEach(marker -> finder.findAnnotatedClasses(marker).stream().filter(c -> !Modifier.isAbstract(c.getModifiers()) && Modifier.isPublic(c.getModifiers())).forEach(webComponent -> webClasses.computeIfAbsent(archive.classesByUrl().entrySet().stream().filter(e -> e.getValue().getClassNames().contains(webComponent.getName())).findFirst().get().getKey(), k -> new HashSet<>()).add(webComponent)));
}
super.webConfig();
} finally {
thread.setContextClassLoader(old);
webClasses.clear();
finder = null;
}
}
Aggregations