/** set the scanners instances for scanning different metadata */ public ConfigurationBuilder setScanners(@Nonnull final Scanner... scanners) { this.scanners.clear(); return addScanners(scanners); }
/** set the scanners instances for scanning different metadata */ public ConfigurationBuilder setScanners(@Nonnull final Scanner... scanners) { this.scanners.clear(); return addScanners(scanners); }
private void configureReflections() { ConfigurationBuilder builder = new ConfigurationBuilder(); Set<URL> packagesToScan = getPackagesToScanForRoutes(); builder.addUrls(packagesToScan); builder.addScanners(new MethodAnnotationsScanner()); reflections = new Reflections(builder); }
conf.addScanners(new SubTypesScanner());
try { builder.addScanners(((Scanner) ((Class) param).newInstance())); } catch (Exception e) { /*fallback*/ }
try { builder.addScanners(((Scanner) ((Class) param).newInstance())); } catch (Exception e) { /*fallback*/ }
@Test public void testNoDefaultEncoding() throws Exception { final Reflections reflections = new Reflections(new ConfigurationBuilder() .useParallelExecutor(Runtime.getRuntime().availableProcessors()) .addUrls(ClasspathHelper.forPackage("org.apache.flink")) .addScanners(new MemberUsageScanner())); for (ForbiddenCall forbiddenCall : forbiddenCalls) { final Set<Member> methodUsages = forbiddenCall.getUsages(reflections); methodUsages.removeAll(forbiddenCall.getExclusions()); assertEquals("Unexpected calls: " + methodUsages, 0, methodUsages.size()); } } }
/** set the scanners instances for scanning different metadata */ public ConfigurationBuilder setScanners(@Nonnull final Scanner... scanners) { this.scanners.clear(); return addScanners(scanners); }
/** set the scanners instances for scanning different metadata */ public ConfigurationBuilder setScanners(@Nonnull final Scanner... scanners) { this.scanners.clear(); return addScanners(scanners); }
public ConfigurationBuilder setScanners(@Nonnull final Scanner... scanners) { this.scanners.clear(); return addScanners(scanners); }
private static Reflections buildReflections(final Collection<URL> urls) { final ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread .currentThread().getContextClassLoader()); final ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addScanners(SCANNER).addClassLoader(classLoader).addUrls(urls); final Reflections reflections = new Reflections(builder); return reflections; }
Set<Class<? extends T>> scan(Class<? extends T> aClass) { Configuration configuration = ConfigurationBuilder.build((Object[]) packages).addClassLoaders(classLoaders) .addScanners(new AssignableScanner(aClass)); Reflections reflections = new Reflections(configuration); Predicate<Class<? extends T>> classPredicate = klass -> Modifier.isPublic(klass.getModifiers()) && (!klass.isMemberClass() || (klass.isMemberClass() && Modifier .isStatic(klass.getModifiers()))) && !Modifier.isInterface(klass.getModifiers()) && !Modifier.isAbstract(klass.getModifiers()); HashSet<Class<? extends T>> subtypes = Sets.newHashSet( ReflectionUtils.forNames( reflections.getStore() .getAll(AssignableScanner.class.getSimpleName(), Collections.singletonList(aClass.getName())), classLoaders)); return subtypes.stream().filter(classPredicate).collect(Collectors.toSet()); }
/** * Creates an instance of the scanner that scans only in the given packages. * * @param packages * Packages to limit scanning to. */ private DeploymentScanner(final String... packages) { final ConfigurationBuilder builder = ConfigurationBuilder.build((Object[]) packages); removeSysLibUrls(builder); builder.addScanners(new ResourcesScanner()); reflections = new Reflections(builder); }
/** * Creates a default instance of the scanner that scans through the whole classpath. */ private DeploymentScanner() { final ConfigurationBuilder builder = ConfigurationBuilder.build(""); addNestedClasspathUrls(builder); removeSysLibUrls(builder); builder.addScanners(new ResourcesScanner()); reflections = new Reflections(builder); }
public static <T extends BrooklynObject> Set<Class<? extends T>> findClasses(Collection<URL> urls, Class<T> clazz) { ClassLoader classLoader = new UrlClassLoader(urls.toArray(new URL[urls.size()])); Reflections reflections = new ConfigurationBuilder() .addClassLoader(classLoader) .addScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()) .addUrls(urls) .build(); Set<Class<? extends T>> types = reflections.getSubTypesOf(clazz); return types; } }
@Override public Reflections get() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder() .addUrls(forSinglePackage(applicationConfiguration.getApplicationPackage())) .addUrls(forSinglePackage(this.getClass().getPackage().getName())) .addUrls(forSinglePackage("com.manywho.sdk.services")) .addScanners(new SubTypesScanner(), new FieldAnnotationsScanner()); Reflections reflections = new Reflections(configurationBuilder); ReflectionsHelper.expandSupertypes(reflections, SubTypesScanner.class, new String[][]{ { applicationConfiguration.getApplicationPackage() }, { this.getClass().getPackage().getName() }, { "com.manywho.sdk.services" } }); return reflections; }
/** * the classes and the packages to be scanned. * * @param packages packages. */ public ClassPathScanHandler(String... packages) { this.reflections = new Reflections(new ConfigurationBuilder(). forPackages(packages). addScanners(new TypeAnnotationsScanner(), new SubTypesScanner())//.addUrls(urlList) ); }
private static Reflections reflections(ServletContext servletContext) { return new Reflections(new ConfigurationBuilder() .addUrls(ClasspathHelper.forWebInfClasses(servletContext)) .addUrls(ClasspathHelper.forWebInfLib(servletContext)) .addScanners(new TypeAnnotationsScanner())); }
private List<ScanResult> scanForSources(ClassLoader classLoader, URL[] downloadedUrls) throws Exception { Reflections reflections = new Reflections(new ConfigurationBuilder().addClassLoader(classLoader) .addScanners(new SubTypesScanner(), new TypeAnnotationsScanner()).addUrls(downloadedUrls)); Set<Class<?>> sources = Sets.intersection(reflections.getTypesAnnotatedWith(Source.class), reflections.getSubTypesOf(PipelineSource.class)); return sources.stream().map(source -> { Source sourceInfo = source.getAnnotation(Source.class); ComponentMetadata metadata = ComponentMetadata.builder().type(ComponentType.SOURCE).namespace(sourceInfo.namespace()) .name(sourceInfo.name()).version(sourceInfo.version()).description(sourceInfo.description()) .cpu(sourceInfo.cpu()).memory(sourceInfo.memory()) .requiredProperties(ImmutableList.copyOf(sourceInfo.requiredProperties())) .optionalProperties(ImmutableList.copyOf(sourceInfo.optionalProperties())).build(); return ScanResult.builder().metadata(metadata).componentClass(source).build(); }).collect(Collectors.toCollection(ArrayList::new)); }
private List<ScanResult> scanForProcessors(ClassLoader classLoader, URL[] downloadedUrls) throws Exception { Reflections reflections = new Reflections(new ConfigurationBuilder().addClassLoader(classLoader) .addScanners(new SubTypesScanner(), new TypeAnnotationsScanner()).addUrls(downloadedUrls)); Set<Class<?>> processors = Sets.intersection(reflections.getTypesAnnotatedWith(Processor.class), reflections.getSubTypesOf(ProcessorBase.class)); return processors.stream().map(processor -> { Processor processorInfo = processor.getAnnotation(Processor.class); ComponentMetadata metadata = ComponentMetadata.builder().type(ComponentType.PROCESSOR).namespace(processorInfo.namespace()) .name(processorInfo.name()).version(processorInfo.version()) .description(processorInfo.description()).cpu(processorInfo.cpu()) .memory(processorInfo.memory()).processorType(processorInfo.processorType()) .requiredProperties(ImmutableList.copyOf(processorInfo.requiredProperties())) .optionalProperties(ImmutableList.copyOf(processorInfo.optionalProperties())).build(); return ScanResult.builder().metadata(metadata).componentClass(processor).build(); }).collect(Collectors.toCollection(ArrayList::new)); }