List of usage examples for com.google.common.reflect ClassPath getTopLevelClasses
public ImmutableSet<ClassInfo> getTopLevelClasses(String packageName)
From source file:com.art4ul.loadinstead.bean.ClassMapper.java
private ClassMapper(List<String> packs) throws IOException { classMap = new HashMap<Class<?>, Class<?>>(); for (String pack : packs) { ClassPath classPath = ClassPath.from(getClass().getClassLoader()); Set<ClassPath.ClassInfo> classInfos = classPath.getTopLevelClasses(pack); for (ClassPath.ClassInfo info : classInfos) { processClass(info.load());/*from w w w . ja va2 s . co m*/ } } }
From source file:tk.vigaro.helix.config.ConfigurationEsperNet.java
public ConfigurationEsperNet() throws IllegalAccessException, InstantiationException, IOException { this.setName("true".equals(System.getProperty("helix.isDebug")) ? Helix.properties.getProperty("irc.nickname") + "|debug" : Helix.properties.getProperty("irc.nickname")); this.setFinger("VBot"); this.setVersion("VBot"); this.setRealName("VBot"); this.setAutoNickChange(true); this.setLogin(Helix.properties.getProperty("irc.nickserv.login")); this.setNickservPassword(Helix.properties.getProperty("irc.nickserv.pw")); this.setServer("irc.esper.net", 6697); this.setSocketFactory(new UtilSSLSocketFactory().trustAllCertificates()); this.setAutoReconnect(true); JSONArray chans = new JSONArray(Helix.properties.getProperty("irc.channels")); for (int i = 0; i < chans.length(); i++) this.addAutoJoinChannel(chans.getString(i)); this.setListenerManager(Helix.backgroundListenerManager); ClassPath classPath = ClassPath.from(Thread.currentThread().getContextClassLoader()); for (ClassPath.ClassInfo classInfo : classPath.getTopLevelClasses("tk.vigaro.helix.listener")) { this.addListener(((Class<? extends ListenerAdapter>) classInfo.load()).newInstance()); }/*from w w w .ja v a2 s . c o m*/ for (ClassPath.ClassInfo classInfo : classPath.getTopLevelClasses("tk.vigaro.helix.backgroundlistener")) { Helix.backgroundListenerManager .addListener(((Class<? extends ListenerAdapter>) classInfo.load()).newInstance(), true); } }
From source file:com.art4ul.jcoon.handlers.AnnotationProcessor.java
private AnnotationProcessor() { try {//from w w w.j av a 2 s . com ClassPath classPath = ClassPath.from(AnnotationProcessor.class.getClassLoader()); Set<ClassPath.ClassInfo> classInfo = classPath .getTopLevelClasses(AnnotationProcessor.class.getPackage().getName()); for (ClassPath.ClassInfo info : classInfo) { Class<?> clazz = info.load(); if (ParamAnnotationHandler.class.isAssignableFrom(clazz) && !clazz.isInterface()) { Class<? extends ParamAnnotationHandler> handlerClass = (Class<? extends ParamAnnotationHandler>) clazz; ProcessAnnotation annotationHandler = handlerClass.getAnnotation(ProcessAnnotation.class); if (annotationHandler != null) { if (handlerClass.isAnnotationPresent(Before.class)) { paramAnnotationBeforeHandlerMap.put(annotationHandler.value(), handlerClass.newInstance()); } else if (handlerClass.isAnnotationPresent(After.class)) { paramAnnotationAfterHandlerMap.put(annotationHandler.value(), handlerClass.newInstance()); } } } } } catch (Exception e) { throw new InitializationException("Exception during creating new instance of ParamAnnotationHandler"); } }
From source file:com.github.bpark.vertx.pico.ApplicationContext.java
public ApplicationContext build() { try {// w w w .j a v a 2 s . c o m if (injectAnnotation != null) { pico = new PicoBuilder().withAnnotatedFieldInjection(injectAnnotation).build(); } else { pico = new PicoBuilder().withAnnotatedFieldInjection().build(); } for (String scan : scans) { ClassPath classpath = ClassPath.from(ApplicationContext.class.getClassLoader()); for (ClassPath.ClassInfo classInfo : classpath.getTopLevelClasses(scan)) { Class<?> loadedClass = classInfo.load(); classes.add(loadedClass); } } for (Class<?> aClass : classes) { pico.addComponent(aClass); } pico.addComponent(this); pico.addAdapter(new ContextInjector(vertx, container)); pico.addAdapter(new VertxInjector(vertx)); pico.addAdapter(new ContainerInjector(container)); pico.addAdapter(new LoggerInjector(container.logger())); pico.addAdapter(new EventBusInjector(vertx.eventBus())); pico.addAdapter(new BusModInjector(container)); for (ComponentAdapter<?> componentAdapter : componentAdapters) { pico.addAdapter(componentAdapter); } return this; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:nl.knaw.huygens.timbuctoo.vre.PackageScope.java
private final void addPackage(String name) throws IOException { ClassPath classPath = ClassPath.from(PackageScope.class.getClassLoader()); String packageName = name.replaceFirst("^timbuctoo", "nl.knaw.huygens.timbuctoo"); for (ClassInfo info : classPath.getTopLevelClasses(packageName)) { addClass(info.load());/*from w w w . j av a 2 s .c o m*/ } }
From source file:ch.ifocusit.plantuml.classdiagram.ClassDiagramBuilder.java
public void addPackages() { packages.stream().forEach(pkg -> { try {//from ww w .j av a 2 s . com ClassPath classPath = ClassPath.from(Thread.currentThread().getContextClassLoader()); Clazz[] classes = classPath.getTopLevelClasses(pkg.getName()).stream() .map(ClassPath.ClassInfo::load).map(this::createJavaClass).sorted().toArray(Clazz[]::new); builder.addPackage(Package.from(pkg), classes); } catch (IOException e) { throw new IllegalStateException("Cannot load classesRepository from package " + pkg, e); } }); }
From source file:com.github.easyjsonapi.core.EasyJsonApiConfig.java
/** * Set the packages to search/*from w ww. j a v a2 s. c o m*/ * * @param packages * the packages needs to be search and parsing * @throws EasyJsonApiInvalidPackageException */ public void setPackagesToSearch(String... packages) throws EasyJsonApiInvalidPackageException { this.packagesSearched = packages; for (String packageToSearch : packages) { try { ClassPath classpath = ClassPath.from(getClass().getClassLoader()); List<Class<?>> attrClasses = new ArrayList<>(); List<Class<?>> metaClasses = new ArrayList<>(); List<Class<?>> metaRelationshipsClasses = new ArrayList<>(); for (ClassPath.ClassInfo classInfo : classpath.getTopLevelClasses(packageToSearch)) { Class<?> clazz = classInfo.load(); if (Assert.notNull(clazz.getAnnotation(Attributes.class))) { attrClasses.add(clazz); } else if (Assert.notNull(clazz.getAnnotation(Meta.class))) { metaClasses.add(clazz); } else if (Assert.notNull(clazz.getAnnotation(MetaRelationship.class))) { metaRelationshipsClasses.add(clazz); } } this.classesParsed.put(EasyJsonApiTypeToken.TOKEN_ATTR, attrClasses); this.classesParsed.put(EasyJsonApiTypeToken.TOKEN_META, metaClasses); this.classesParsed.put(EasyJsonApiTypeToken.TOKEN_META_RELATIONSHIP, metaRelationshipsClasses); } catch (IOException ex) { throw new EasyJsonApiInvalidPackageException("Invalid packages inserted!", ex); } } }
From source file:com.phoenixnap.oss.ramlapisync.plugin.CommonApiSyncMojo.java
protected void scanPack(String pack, ClassPath classPath) throws MojoExecutionException, IOException { this.getLog().info("Scanning package " + pack); if (Strings.isNullOrEmpty(pack)) { ClassLoaderUtils.restoreOriginalClassLoader(); throw new MojoExecutionException("Invalid target package: " + pack); }/* www. jav a2s . co m*/ for (ClassPath.ClassInfo classInfo : classPath.getTopLevelClasses(pack)) { try { Class<?> c = classInfo.load(); if (!ignoredList.contains(c.getPackage().getName()) && !ignoredList.contains(c.getName())) { scanClass(c); } } catch (Throwable ex) { this.getLog().warn("Skipping Class: Unable to load" + classInfo.getName(), ex); } } }
From source file:nl.knaw.huygens.timbuctoo.config.TypeRegistry.java
private Set<ClassInfo> getClassInfoSet(ClassPath classPath, String packageName) { if (packageName.endsWith(".*")) { return classPath.getTopLevelClassesRecursive(StringUtils.chomp(packageName, ".*")); } else {/*w w w . j ava 2s .c o m*/ return classPath.getTopLevelClasses(packageName); } }
From source file:net.pravian.aero.command.handler.SimpleCommandHandler.java
@Override @SuppressWarnings("unchecked") public void loadFrom(Package pack) { ClassPath classPath; try {//from w w w. j a v a 2 s . c om classPath = ClassPath.from(plugin.getClass().getClassLoader()); } catch (Exception ex) { plugin.logger.severe("Could not load commands from package: " + pack.getName()); plugin.logger.severe(ex); return; } for (ClassInfo info : classPath.getTopLevelClasses(pack.getName())) { if (!info.getSimpleName().startsWith(commandClassPrefix)) { logger.debug("Skipping class in command package: " + info.getSimpleName() + ". Class does not have required prefix."); continue; } final String name = info.getSimpleName().substring(commandClassPrefix.length()).toLowerCase(); if (commands.containsKey(name)) { logger.warning( "Skipping class in command package: " + info.getSimpleName() + ". Command name conflict!"); continue; } final Class<?> clazz = info.load(); if (!AeroCommandBase.class.isAssignableFrom(clazz)) { logger.debug("Skipping class in command package: " + info.getSimpleName() + ". Class does can not be assigned to CommandBase."); continue; } AeroCommandBase<T> command; try { command = (AeroCommandBase<T>) clazz.newInstance(); } catch (Exception ex) { plugin.handleException("Could not instantiate command class: " + info.getSimpleName(), ex); continue; } try { command.register(this); } catch (Exception ex) { plugin.handleException("Could not register command: " + name, ex); return; } commands.put(name, getExecutorFactory().newExecutor(this, name, command)); } }