@Override public Set<Class<?>> classes() { ConfigurationBuilder config = new ConfigurationBuilder(); Set<String> acceptablePackages = new HashSet<String>(); Set<String> resourceClasses = new HashSet<String>(); if (!isIgnored(pkg)) { acceptablePackages.add(pkg); config.addUrls(ClasspathHelper.forPackage(pkg)); config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner()); final Reflections reflections = new Reflections(config); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(OpenAPIDefinition.class);
FilterBuilder filterBuilder = new FilterBuilder().includePackage(Constants.DISCONF_PACK_NAME); filterBuilder = filterBuilder.includePackage(packName); Set<URL> urls = ClasspathHelper.forPackage(packName); urlTotals.addAll(urls); Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filter) .setScanners(new SubTypesScanner().filterResultsBy(filter), new TypeAnnotationsScanner() .filterResultsBy(filter), new FieldAnnotationsScanner() .filterResultsBy(filter),
@SuppressWarnings({"unchecked"}) public void scan(final Object cls) { String className = getMetadataAdapter().getClassName(cls); String superclass = getMetadataAdapter().getSuperclassName(cls); if (acceptResult(superclass)) { getStore().put(superclass, className); } for (String anInterface : (List<String>) getMetadataAdapter().getInterfacesNames(cls)) { if (acceptResult(anInterface)) { getStore().put(anInterface, className); } } } }
private Reflections buildReflections(String packages) { String[] packagesArray = packages.replaceAll(" ", "").split(","); FilterBuilder filter = new FilterBuilder(); Set<URL> urls = new HashSet(); for (String packageStr : packagesArray) { urls.addAll(ClasspathHelper.forPackage(packageStr)); filter.include(FilterBuilder.prefix(packageStr)); } return new Reflections(new ConfigurationBuilder() .addUrls(urls) .filterInputsBy(filter) .setScanners(new TypeAnnotationsScanner(), new SubTypesScanner())); }
ConfigurationBuilder config = new ConfigurationBuilder(); Set<String> acceptablePackages = new HashSet<String>(); Set<Class<?>> output = new HashSet<Class<?>>(); if (!isIgnored(pkg)) { acceptablePackages.add(pkg); config.addUrls(ClasspathHelper.forPackage(pkg)); allowAllPackages = true; config.filterInputsBy(new FilterBuilder().exclude(".*json").exclude(".*yaml")); config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner()); final Reflections reflections; reflections = new Reflections(config); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class); classes.addAll(reflections.getTypesAnnotatedWith(OpenAPIDefinition.class));
org.reflections.Configuration rc = new org.reflections.util.ConfigurationBuilder() .setUrls(scanUrls) .setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()); Reflections reflections = new Reflections(rc); for (Class<?> c : reflections.getTypesAnnotatedWith(PreInitializeConfigOptions.class)) { try { loadCount += loadSingleClassUnsafe(c);
private void scanConceptsWithReflections() throws ObjectStoreConfigException { logger.debug("Search for concepts with reflections"); Set<URL> classpath = new HashSet<>(); classpath.addAll(ClasspathHelper.forClassLoader()); classpath.addAll(ClasspathHelper.forJavaClassPath()); classpath.addAll(ClasspathHelper.forManifest()); classpath.addAll(ClasspathHelper.forPackage("")); Reflections reflections = new Reflections(new ConfigurationBuilder() .setUrls(classpath) .useParallelExecutor() .filterInputsBy(FilterBuilder.parsePackages("-java, -javax, -sun, -com.sun")) .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner())); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Iri.class, true); logger.debug("Search for concepts with reflections resulted in " + annotated.size() + " classes"); for (Class clazz : annotated) { logger.debug("Found concept class: " + clazz.getCanonicalName()); roleMapper.addConcept(clazz); } }
public DefaultOpFactory() { opClazzes = new HashMap<>(); Reflections f = new Reflections(new ConfigurationBuilder().filterInputsBy( new FilterBuilder().include(FilterBuilder.prefix("org.nd4j")).exclude("^(?!.*\\.class$).*$") //Consider only .class files (to avoid debug messages etc. on .dlls, etc .exclude("^(?!org\\.nd4j\\.linalg\\.api\\.ops).*") //Exclude any not in the ops directory ) .setUrls(ClasspathHelper.forPackage("org.nd4j")).setScanners(new SubTypesScanner())); Set<Class<? extends Op>> clazzes = f.getSubTypesOf(Op.class); for (Class<? extends Op> clazz : clazzes) { if (Modifier.isAbstract(clazz.getModifiers()) || clazz.isInterface()) continue; try { opClazzes.put(clazz.newInstance().name(), clazz); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * 获取指定package下的接口实现类 * * @param scannerPackage 扫描的package * @return 实现类集合 */ public static Set<Class<? extends JobTrigger>> getJobs(String scannerPackage) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()); configurationBuilder.filterInputsBy(new FilterBuilder().includePackage(scannerPackage)); configurationBuilder.addUrls(ClasspathHelper.forPackage(scannerPackage)); Reflections reflections = new Reflections(scannerPackage); return reflections.getSubTypesOf(JobTrigger.class); } }
private static Set<Class<?>> findObjectMappers() { final Predicate<String> filter = new Predicate<String>() { @Override public boolean apply(final String input) { return GlobalObjectMapper.class.getCanonicalName().equals(input); } }; final String myNameSpaceToScan = getNameSpace(); final Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy( new FilterBuilder.Include(FilterBuilder.prefix(myNameSpaceToScan))).setUrls( ClasspathHelper.forPackage(myNameSpaceToScan)).setScanners(new TypeAnnotationsScanner() .filterResultsBy(filter), new SubTypesScanner())); final Set<Class<?>> objectMapper = reflections.getTypesAnnotatedWith(GlobalObjectMapper.class); return objectMapper; }
final ConfigurationBuilder conf = new ConfigurationBuilder(); conf.setScanners(new TypeElementsScanner(), new TypeAnnotationsScanner()); s.addAll(ClasspathHelper.forClassLoader()); s.addAll(ClasspathHelper.forJavaClassPath()); final Iterator<URL> iterator = s.iterator(); while (iterator.hasNext()) { conf.setUrls(new ArrayList<URL>(s)); conf.filterInputsBy(localPredicate); conf.addScanners(new SubTypesScanner()); final Reflections r = new Reflections(conf); final Set<Class<?>> entities = r.getTypesAnnotatedWith(Entity.class); for (final Class<?> c : entities) { m.map(c);
static Reflections reflections() { final Reflections cached = reflector; if (cached != null) return cached; final Reflections newInstance = new Reflections(new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage("org.intellivim")) .setScanners( new SubTypesScanner(), new TypeAnnotationsScanner()) .filterInputsBy(new FilterBuilder().include("org.intellivim.*")) ); reflector = newInstance; return newInstance; }
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 static Reflections createReflections() { List<ClassLoader> classLoadersList = new LinkedList<>(); classLoadersList.add(ClasspathHelper.contextClassLoader()); classLoadersList.add(ClasspathHelper.staticClassLoader()); return new Reflections(new ConfigurationBuilder() .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner()) .setUrls(ClasspathHelper.forManifest(ClasspathHelper.forClassLoader( classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))) .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.kakao.hbase.manager.command")))); }
public StreamsJacksonModule() { super(); Reflections reflections = new Reflections(new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage("org.apache.streams.jackson")) .setScanners(new SubTypesScanner())); Set<Class<? extends StreamsDateTimeFormat>> dateTimeFormatClasses = reflections.getSubTypesOf(StreamsDateTimeFormat.class); List<String> dateTimeFormats = new ArrayList<>(); for (Class dateTimeFormatClass : dateTimeFormatClasses) { try { dateTimeFormats.add(((StreamsDateTimeFormat) (dateTimeFormatClass.newInstance())).getFormat()); } catch (Exception ex) { LOGGER.warn("Exception getting format from " + dateTimeFormatClass); } } addSerializer(DateTime.class, new StreamsDateTimeSerializer(DateTime.class)); addDeserializer(DateTime.class, new StreamsDateTimeDeserializer(DateTime.class, dateTimeFormats)); addSerializer(Period.class, new StreamsPeriodSerializer(Period.class)); addDeserializer(Period.class, new StreamsPeriodDeserializer(Period.class)); }
/** * Scans the classpath to find all classes that are in the configured model packages. It ignores excluded classes. * * @return classes to parse * @see Options */ public Set<Class<?>> findClassesToParse() { Reflections reflections = new Reflections(new ConfigurationBuilder(). setUrls(buildClassLoaderUrls()).setScanners(new SubTypesScanner(false)).filterInputsBy(buildPackagePredicates())); return reflections.getSubTypesOf(Object.class); }
/** * Searches for Methods that have either a Path Annotation or a HTTP-Method Annotation */ @SuppressWarnings("unchecked") private Set<Method> findControllerMethods() { Set<Method> methods = Sets.newLinkedHashSet(); methods.addAll(reflections.getMethodsAnnotatedWith(Path.class)); Reflections annotationReflections = new Reflections("", new TypeAnnotationsScanner(), new SubTypesScanner()); for (Class<?> httpMethod : annotationReflections.getTypesAnnotatedWith(HttpMethod.class)) { if (httpMethod.isAnnotation()) { methods.addAll(reflections.getMethodsAnnotatedWith((Class<? extends Annotation>) httpMethod)); } } return methods; }
private Reflections createReflections(String... packageName) { if (packageName != null && packageName.length > 0) { ConfigurationBuilder configBuilder = new ConfigurationBuilder(); List<URL> urls = new ArrayList<>(); for (int i = 0; i < packageName.length; i++) { urls.addAll(ClasspathHelper.forPackage(packageName[i])); } configBuilder.setUrls(urls); configBuilder.setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner()); return new Reflections(configBuilder); } else return null; }
Reflections.log = log; reflections = new Reflections(new ConfigurationBuilder() { else if (classLoaders.length>0 && classLoaders[0]!=null) setUrls( ClasspathHelper.forPackage(Strings.isNonEmpty(optionalPrefix) ? optionalPrefix : "", asClassLoaderVarArgs(classLoaders[0]))); Scanner typeScanner = new TypeAnnotationsScanner(); if (filter!=null) typeScanner = typeScanner.filterResultsBy(filter); Scanner subTypeScanner = new SubTypesScanner(); if (filter!=null) subTypeScanner = subTypeScanner.filterResultsBy(filter); setScanners(typeScanner, subTypeScanner);
private Reflections createReflections() { Configuration config = new ConfigurationBuilder() .setScanners(new SubTypesScanner()) .addUrls(ClasspathHelper.getUrls()) .filterInputsBy(new FilterBuilder().include(".+\\.class")); return new Reflections(config); }