Search in sources :

Example 76 with Reflections

use of org.reflections.Reflections in project che by eclipse.

the class IDEInjectorGenerator method findGinModules.

/**
     * Find all the Java files that have ExtensionGinModule annotation
     *
     * @throws IOException
     */
@SuppressWarnings("unchecked")
public static void findGinModules(File rootFolder) throws IOException {
    Reflections reflection = new Reflections(getConfigurationBuilder());
    Set<Class<?>> classes = reflection.getTypesAnnotatedWith(ExtensionGinModule.class);
    for (Class clazz : classes) {
        EXTENSIONS_FQN.add(clazz.getCanonicalName());
        System.out.println(String.format("New Gin Module Found: %s", clazz.getCanonicalName()));
    }
    System.out.println(String.format("Found: %d Gin Modules", EXTENSIONS_FQN.size()));
}
Also used : Reflections(org.reflections.Reflections)

Example 77 with Reflections

use of org.reflections.Reflections in project Gaffer by gchq.

the class StreamUtil method openStreams.

public static InputStream[] openStreams(final Class clazz, final String folderPath, final boolean logErrors) {
    if (null == folderPath) {
        return new InputStream[0];
    }
    String folderPathChecked = folderPath;
    if (!folderPathChecked.endsWith("/")) {
        folderPathChecked = folderPathChecked + "/";
    }
    if (folderPathChecked.startsWith("/")) {
        folderPathChecked = folderPathChecked.substring(1);
    }
    final Set<String> schemaFiles = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()).setUrls(ClasspathHelper.forClass(clazz))).getResources(Pattern.compile(".*"));
    final Iterator<String> itr = schemaFiles.iterator();
    while (itr.hasNext()) {
        if (!itr.next().startsWith(folderPathChecked)) {
            itr.remove();
        }
    }
    int index = 0;
    final InputStream[] schemas = new InputStream[schemaFiles.size()];
    for (final String schemaFile : schemaFiles) {
        schemas[index] = openStream(clazz, schemaFile, logErrors);
        index++;
    }
    return schemas;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) InputStream(java.io.InputStream) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 78 with Reflections

use of org.reflections.Reflections in project kafka by apache.

the class PluginDiscovery method scanClasspathForPlugins.

public static synchronized void scanClasspathForPlugins() {
    if (scanned)
        return;
    ReflectionsUtil.registerUrlTypes();
    final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forJavaClassPath()));
    validConnectorPlugins = Collections.unmodifiableList(connectorPlugins(reflections));
    validTransformationPlugins = Collections.unmodifiableList(transformationPlugins(reflections));
    scanned = true;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Reflections(org.reflections.Reflections)

Example 79 with Reflections

use of org.reflections.Reflections in project deeplearning4j by deeplearning4j.

the class PlayUIServer method getCustomUIModules.

private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) {
    //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes
    List<String> classNames = Collections.singletonList(UIModule.class.getName());
    Reflections reflections = new Reflections();
    org.reflections.Store store = reflections.getStore();
    Iterable<String> subtypesByName = store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames);
    Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName));
    List<Class<?>> toCreate = new ArrayList<>();
    for (Class<?> c : subtypeClasses) {
        if (excludeClasses.contains(c))
            continue;
        ;
        toCreate.add(c);
    }
    List<UIModule> ret = new ArrayList<>(toCreate.size());
    for (Class<?> c : toCreate) {
        UIModule m;
        try {
            m = (UIModule) c.newInstance();
        } catch (Exception e) {
            log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e);
            continue;
        }
        log.debug("Created instance of custom UI module: {}", c);
        ret.add(m);
    }
    return ret;
}
Also used : ParameterException(com.beust.jcommander.ParameterException) UIModule(org.deeplearning4j.ui.api.UIModule) Reflections(org.reflections.Reflections)

Example 80 with Reflections

use of org.reflections.Reflections in project querydsl by querydsl.

the class ClassPathUtils method scanPackage.

/**
     * Return the classes from the given package and subpackages using the supplied classloader
     *
     * @param classLoader classloader to be used
     * @param pkg package to scan
     * @return set of found classes
     * @throws IOException
     */
public static Set<Class<?>> scanPackage(ClassLoader classLoader, String pkg) throws IOException {
    Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage(pkg, classLoader)).addClassLoader(classLoader).setScanners(new SubTypesScanner(false)));
    Set<Class<?>> classes = new HashSet<Class<?>>();
    for (String typeNames : reflections.getStore().get(SubTypesScanner.class.getSimpleName()).values()) {
        Class<?> clazz = safeClassForName(classLoader, typeNames);
        if (clazz != null) {
            classes.add(clazz);
        }
    }
    return classes;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Aggregations

Reflections (org.reflections.Reflections)160 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)54 SubTypesScanner (org.reflections.scanners.SubTypesScanner)41 ArrayList (java.util.ArrayList)26 Set (java.util.Set)23 ResourcesScanner (org.reflections.scanners.ResourcesScanner)21 Test (org.junit.Test)20 FilterBuilder (org.reflections.util.FilterBuilder)20 HashSet (java.util.HashSet)19 URL (java.net.URL)18 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)18 IOException (java.io.IOException)17 Collectors (java.util.stream.Collectors)17 Method (java.lang.reflect.Method)16 List (java.util.List)15 File (java.io.File)13 InputStream (java.io.InputStream)9 Field (java.lang.reflect.Field)9 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)9 ClasspathHelper (org.reflections.util.ClasspathHelper)9