/** * Scan the given packages. * * @param annotation The annotation to scan for * @param pkg The package to scan * @return A stream of classes */ @Override public Stream<Class> scan(String annotation, String pkg) { if (pkg == null) { return Stream.empty(); } List<Class> classes = doScan(annotation, pkg); return classes.stream(); }
/** * @param annotation The annotation * @param classes The classes * @param file The file */ protected void traverseFile(String annotation, List<Class> classes, File file) { if (file.isDirectory()) { try (DirectoryStream<Path> dirs = Files.newDirectoryStream(file.toPath())) { dirs.forEach(path -> { File f = path.toFile(); if (f.isDirectory()) { traverseFile(annotation, classes, f); } else { scanFile(annotation, f, classes); } }); } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring directory [" + file + "] due to I/O error: " + e.getMessage(), e); } } } else { scanFile(annotation, file, classes); } }
try { File file = new File(url.toURI()); traverseFile(annotation, classes, file); } catch (URISyntaxException e) { if (LOG.isDebugEnabled()) { .forEach(entry -> { try (InputStream inputStream = jarFile.getInputStream(entry)) { scanInputStream(annotation, inputStream, classes); } catch (IOException e) { if (LOG.isDebugEnabled()) {
/** * Scan the current environment for classes annotated with the given annotation. Use with care, repeated * invocations should be avoided for performance reasons. * * @param annotation The annotation to scan * @param packages The packages to scan * @return The classes */ default Stream<Class> scan(Class<? extends Annotation> annotation, String... packages) { ClassPathAnnotationScanner scanner = new ClassPathAnnotationScanner(getClassLoader()); return scanner.scan(annotation, Arrays.asList(packages)); }
@Override public Stream<Class> scan(Class<? extends Annotation> annotation, String... packages) { return annotationScanner.scan(annotation, packages); }
/** * @param annotation The annotation * @param file The file * @param classes The classes */ protected void scanFile(String annotation, File file, List<Class> classes) { String fileName = file.getName(); if (fileName.endsWith(".class")) { // ignore generated classes if (fileName.indexOf('$') == -1) { try (InputStream inputStream = Files.newInputStream(file.toPath())) { scanInputStream(annotation, inputStream, classes); } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring file [" + file.getName() + "] due to I/O error: " + e.getMessage(), e); } } catch (ClassNotFoundException e) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring file [" + file.getName() + "]. Class not found: " + e.getMessage(), e); } } } } }
/** * Scan the current environment for classes annotated with the given annotation. Use with care, repeated * invocations should be avoided for performance reasons. * * @param annotation The annotation to scan * @param packages The packages to scan * @return The classes */ default Stream<Class> scan(Class<? extends Annotation> annotation, String... packages) { ClassPathAnnotationScanner scanner = new ClassPathAnnotationScanner(getClassLoader()); return scanner.scan(annotation, Arrays.asList(packages)); }
@Override public Stream<Class> scan(Class<? extends Annotation> annotation, String... packages) { return annotationScanner.scan(annotation, packages); }
/** * Scan the current environment for classes annotated with the given annotation. Use with care, repeated * invocations should be avoided for performance reasons. * * @param annotation The annotation to scan * @return The classes */ default Stream<Class> scan(Class<? extends Annotation> annotation) { ClassPathAnnotationScanner scanner = new ClassPathAnnotationScanner(getClassLoader()); return scanner.scan(annotation, getPackages()); }
@Override public Stream<Class> scan(Class<? extends Annotation> annotation) { return annotationScanner.scan(annotation, getPackages()); }
@Override protected List<Class> doScan(String annotation, String pkg) { return initializedObjectsByType.computeIfAbsent(new CacheKey(annotation, pkg), (key) -> super.doScan(annotation, pkg)); }
/** * Scan the current environment for classes annotated with the given annotation. Use with care, repeated * invocations should be avoided for performance reasons. * * @param annotation The annotation to scan * @return The classes */ default Stream<Class> scan(Class<? extends Annotation> annotation) { ClassPathAnnotationScanner scanner = new ClassPathAnnotationScanner(getClassLoader()); return scanner.scan(annotation, getPackages()); }
@Override public Stream<Class> scan(Class<? extends Annotation> annotation) { return annotationScanner.scan(annotation, getPackages()); }