/** * Adds array of package names which will be used to scan for components. * <p/> * Package scanning ignores an inheritance and therefore {@link Path} annotation * on parent classes and interfaces will be ignored. * <p/> * @param recursive defines whether any nested packages in the collection of specified * package names should be recursively scanned (value of {@code true}) * as part of the package scanning or not (value of {@code false}). * @param packages array of package names. * @return updated resource configuration instance. * @see #packages(String...) */ public final ResourceConfig packages(final boolean recursive, final String... packages) { if (packages == null || packages.length == 0) { return this; } return registerFinder(new PackageNamesScanner(packages, recursive)); }
/** * Adds array of package names which will be used to scan for components. * <p/> * Package scanning ignores an inheritance and therefore {@link Path} annotation * on parent classes and interfaces will be ignored. * <p/> * @param recursive defines whether any nested packages in the collection of specified * package names should be recursively scanned (value of {@code true}) * as part of the package scanning or not (value of {@code false}). * @param packages array of package names. * @return updated resource configuration instance. * @see #packages(String...) */ public final ResourceConfig packages(final boolean recursive, final String... packages) { if (packages == null || packages.length == 0) { return this; } return registerFinder(new PackageNamesScanner(packages, recursive)); }
/** * Method scanning given directory for classes containing Hibernate @Entity annotation * * @param pckgs string array with packages containing Hibernate entities (classes annotated with @Entity annotation) * e.g. com.codahale.fake.db.directory.entities * @return ImmutableList with classes from given directory annotated with Hibernate @Entity annotation */ public static List<Class<?>> findEntityClassesFromDirectory(String[] pckgs) { @SuppressWarnings("unchecked") final AnnotationAcceptingListener asl = new AnnotationAcceptingListener(Entity.class); try (final PackageNamesScanner scanner = new PackageNamesScanner(pckgs, true)) { while (scanner.hasNext()) { final String next = scanner.next(); if (asl.accept(next)) { try (final InputStream in = scanner.open()) { asl.process(next, in); } catch (IOException e) { throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next); } } } } return new ArrayList<>(asl.getAnnotatedClasses()); } }
final Object p = getProperty(ServerProperties.PROVIDER_SCANNING_RECURSIVE); final boolean recursive = p == null || PropertiesHelper.isProperty(p); rfs.add(new PackageNamesScanner(packageNames, recursive));
final Object p = getProperty(ServerProperties.PROVIDER_SCANNING_RECURSIVE); final boolean recursive = p == null || PropertiesHelper.isProperty(p); rfs.add(new PackageNamesScanner(packageNames, recursive));
/** * Adds array of package names which will be used to scan for components. * <p/> * Package scanning ignores an inheritance and therefore {@link Path} annotation * on parent classes and interfaces will be ignored. * <p/> * @param recursive defines whether any nested packages in the collection of specified * package names should be recursively scanned (value of {@code true}) * as part of the package scanning or not (value of {@code false}). * @param packages array of package names. * @return updated resource configuration instance. * @see #packages(String...) */ public final ResourceConfig packages(final boolean recursive, final String... packages) { if (packages == null || packages.length == 0) { return this; } return registerFinder(new PackageNamesScanner(packages, recursive)); }
final Object p = getProperty(ServerProperties.PROVIDER_SCANNING_RECURSIVE); final boolean recursive = p == null || PropertiesHelper.isProperty(p); rfs.add(new PackageNamesScanner(packageNames, recursive));
/** * Adds array of package names which will be used to scan for components. * <p/> * Package scanning ignores an inheritance and therefore {@link Path} annotation * on parent classes and interfaces will be ignored. * <p/> * @param recursive defines whether any nested packages in the collection of specified * package names should be recursively scanned (value of {@code true}) * as part of the package scanning or not (value of {@code false}). * @param packages array of package names. * @return updated resource configuration instance. * @see #packages(String...) */ public final ResourceConfig packages(final boolean recursive, final String... packages) { if (packages == null || packages.length == 0) { return this; } return registerFinder(new PackageNamesScanner(packages, recursive)); }
/** * Adds array of package names which will be used to scan for components. * <p/> * Package scanning ignores an inheritance and therefore {@link Path} annotation * on parent classes and interfaces will be ignored. * <p/> * @param recursive defines whether any nested packages in the collection of specified * package names should be recursively scanned (value of {@code true}) * as part of the package scanning or not (value of {@code false}). * @param packages array of package names. * @return updated resource configuration instance. * @see #packages(String...) */ public final ResourceConfig packages(final boolean recursive, final String... packages) { if (packages == null || packages.length == 0) { return this; } return registerFinder(new PackageNamesScanner(packages, recursive)); }
/** * Adds array of package names which will be used to scan for components. * <p/> * Package scanning ignores an inheritance and therefore {@link Path} annotation * on parent classes and interfaces will be ignored. * <p/> * @param recursive defines whether any nested packages in the collection of specified * package names should be recursively scanned (value of {@code true}) * as part of the package scanning or not (value of {@code false}). * @param packages array of package names. * @return updated resource configuration instance. * @see #packages(String...) */ public final ResourceConfig packages(final boolean recursive, final String... packages) { if (packages == null || packages.length == 0) { return this; } return registerFinder(new PackageNamesScanner(packages, recursive)); }
/** * Adds array of package names which will be used to scan for components. * <p/> * Package scanning ignores an inheritance and therefore {@link Path} annotation * on parent classes and interfaces will be ignored. * <p/> * @param recursive defines whether any nested packages in the collection of specified * package names should be recursively scanned (value of {@code true}) * as part of the package scanning or not (value of {@code false}). * @param packages array of package names. * @return updated resource configuration instance. * @see #packages(String...) */ public final ResourceConfig packages(final boolean recursive, final String... packages) { if (packages == null || packages.length == 0) { return this; } return registerFinder(new PackageNamesScanner(packages, recursive)); }
final PackageNamesScanner scanner = new PackageNamesScanner( scanPkgs.toArray(new String[scanPkgs.size()]), true); while (scanner.hasNext()) {
/** * Method scanning given directory for classes containing Hibernate @Entity annotation * * @param pckgs string array with packages containing Hibernate entities (classes annotated with @Entity annotation) * e.g. com.codahale.fake.db.directory.entities * @return ImmutableList with classes from given directory annotated with Hibernate @Entity annotation */ public static ImmutableList<Class<?>> findEntityClassesFromDirectory(String[] pckgs) { @SuppressWarnings("unchecked") final AnnotationAcceptingListener asl = new AnnotationAcceptingListener(Entity.class); final PackageNamesScanner scanner = new PackageNamesScanner(pckgs, true); while (scanner.hasNext()) { final String next = scanner.next(); if (asl.accept(next)) { try (final InputStream in = scanner.open()) { asl.process(next, in); } catch (IOException e) { throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next); } } } final ImmutableList.Builder<Class<?>> builder = ImmutableList.builder(); for (Class<?> clazz : asl.getAnnotatedClasses()) { builder.add(clazz); } return builder.build(); } }
@SuppressWarnings("unchecked") final AnnotationAcceptingListener asl = new AnnotationAcceptingListener(Entity.class); try (final PackageNamesScanner scanner = new PackageNamesScanner(pckgs, true)) { while (scanner.hasNext()) { final String next = scanner.next();
final Object p = getProperty(ServerProperties.PROVIDER_SCANNING_RECURSIVE); final boolean recursive = p == null || PropertiesHelper.isProperty(p); rfs.add(new PackageNamesScanner(packageNames, recursive));
final Object p = getProperty(ServerProperties.PROVIDER_SCANNING_RECURSIVE); final boolean recursive = p == null || PropertiesHelper.isProperty(p); rfs.add(new PackageNamesScanner(packageNames, recursive));
final Object p = getProperty(ServerProperties.PROVIDER_SCANNING_RECURSIVE); final boolean recursive = p == null || PropertiesHelper.isProperty(p); rfs.add(new PackageNamesScanner(packageNames, recursive));
final Object p = getProperty(ServerProperties.PROVIDER_SCANNING_RECURSIVE); final boolean recursive = p == null || PropertiesHelper.isProperty(p); rfs.add(new PackageNamesScanner(packageNames, recursive));
.registerFinder(new PackageNamesScanner(restControllerPackages, true)) .registerResources(additionalResources) .register(NodeIdResponseFilter.class);
/** * Scans all classes accessible from the context class loader which belong to the given package and subpackages. * @param pckg package name * @param annotation Annotation to search * @return The classes */ static public List<Class<?>> getAnnotatedClasses(Package pckg, Class<? extends Annotation> annotation) { final AnnotationAcceptingListener annotationAcceptingListener = new AnnotationAcceptingListener(annotation); try (final PackageNamesScanner scanner = new PackageNamesScanner(new String[] { pckg.getName() }, true)) { while (scanner.hasNext()) { final String next = scanner.next(); if (annotationAcceptingListener.accept(next)) { try (final InputStream in = scanner.open()) { annotationAcceptingListener.process(next, in); } catch (IOException e) { throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next); } } } } return annotationAcceptingListener.getAnnotatedClasses() .stream().collect(Collectors.toCollection(ArrayList::new)); } }