use of org.apache.webbeans.spi.ScannerService in project meecrowave by apache.
the class OWBJarScanner method scan.
@Override
public void scan(final JarScanType jarScanType, final ServletContext servletContext, final JarScannerCallback callback) {
switch(jarScanType) {
case PLUGGABILITY:
final WebBeansContext owb = WebBeansContext.getInstance();
final ScannerService scannerService = owb.getScannerService();
if (!WebScannerService.class.isInstance(scannerService)) {
return;
}
final OwbAnnotationFinder finder = WebScannerService.class.cast(scannerService).getFinder();
if (finder == null) {
return;
}
CdiArchive.class.cast(finder.getArchive()).classesByUrl().keySet().stream().filter(// not a fake in memory url
u -> !"jar:file://!/".equals(u)).forEach(u -> {
try {
final URL url = new URL(u);
final File asFile = Files.toFile(url);
if (!asFile.exists()) {
return;
}
if (filter != null && !filter.check(jarScanType, asFile.getName())) {
return;
}
if (asFile.getName().endsWith(Constants.JAR_EXT)) {
try (final Jar jar = JarFactory.newInstance(asFile.toURI().toURL())) {
callback.scan(jar, u, true);
}
} else if (asFile.isDirectory()) {
callback.scan(asFile, asFile.getAbsolutePath(), true);
}
} catch (final MalformedURLException e) {
// skip
} catch (final IOException ioe) {
throw new IllegalArgumentException(ioe);
}
});
return;
case TLD:
default:
}
}
use of org.apache.webbeans.spi.ScannerService 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