Search in sources :

Example 1 with OwbAnnotationFinder

use of org.apache.webbeans.corespi.scanner.xbean.OwbAnnotationFinder 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:
    }
}
Also used : ScannerService(org.apache.webbeans.spi.ScannerService) Jar(org.apache.tomcat.Jar) OwbAnnotationFinder(org.apache.webbeans.corespi.scanner.xbean.OwbAnnotationFinder) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) JarScannerCallback(org.apache.tomcat.JarScannerCallback) Constants(org.apache.tomcat.util.scan.Constants) JarFactory(org.apache.tomcat.util.scan.JarFactory) JarScanType(org.apache.tomcat.JarScanType) IOException(java.io.IOException) File(java.io.File) JarScanner(org.apache.tomcat.JarScanner) Files(org.apache.xbean.finder.util.Files) WebBeansContext(org.apache.webbeans.config.WebBeansContext) JarScanFilter(org.apache.tomcat.JarScanFilter) ServletContext(javax.servlet.ServletContext) WebScannerService(org.apache.webbeans.web.scanner.WebScannerService) CdiArchive(org.apache.webbeans.corespi.scanner.xbean.CdiArchive) MalformedURLException(java.net.MalformedURLException) WebBeansContext(org.apache.webbeans.config.WebBeansContext) WebScannerService(org.apache.webbeans.web.scanner.WebScannerService) OwbAnnotationFinder(org.apache.webbeans.corespi.scanner.xbean.OwbAnnotationFinder) CdiArchive(org.apache.webbeans.corespi.scanner.xbean.CdiArchive) Jar(org.apache.tomcat.Jar) IOException(java.io.IOException) File(java.io.File) ScannerService(org.apache.webbeans.spi.ScannerService) WebScannerService(org.apache.webbeans.web.scanner.WebScannerService) URL(java.net.URL)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ServletContext (javax.servlet.ServletContext)1 Jar (org.apache.tomcat.Jar)1 JarScanFilter (org.apache.tomcat.JarScanFilter)1 JarScanType (org.apache.tomcat.JarScanType)1 JarScanner (org.apache.tomcat.JarScanner)1 JarScannerCallback (org.apache.tomcat.JarScannerCallback)1 Constants (org.apache.tomcat.util.scan.Constants)1 JarFactory (org.apache.tomcat.util.scan.JarFactory)1 WebBeansContext (org.apache.webbeans.config.WebBeansContext)1 CdiArchive (org.apache.webbeans.corespi.scanner.xbean.CdiArchive)1 OwbAnnotationFinder (org.apache.webbeans.corespi.scanner.xbean.OwbAnnotationFinder)1 ScannerService (org.apache.webbeans.spi.ScannerService)1 WebScannerService (org.apache.webbeans.web.scanner.WebScannerService)1 Files (org.apache.xbean.finder.util.Files)1