Search in sources :

Example 31 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 32 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 33 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 34 with Reflections

use of org.reflections.Reflections in project japid42 by branaway.

the class JaxrsRouter method getControllersWithPath.

public static Set<Class<?>> getControllersWithPath() {
    Reflections reflections = new Reflections(routerPackage);
    Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Path.class);
    return annotated;
}
Also used : Reflections(org.reflections.Reflections)

Example 35 with Reflections

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

the class XmlSerializer method read.

public Reflections read(InputStream inputStream) {
    Reflections reflections;
    try {
        Constructor<Reflections> constructor = Reflections.class.getDeclaredConstructor();
        constructor.setAccessible(true);
        reflections = constructor.newInstance();
    } catch (Exception e) {
        reflections = new Reflections(new ConfigurationBuilder());
    }
    try {
        Document document = new SAXReader().read(inputStream);
        for (Object e1 : document.getRootElement().elements()) {
            Element index = (Element) e1;
            for (Object e2 : index.elements()) {
                Element entry = (Element) e2;
                Element key = entry.element("key");
                Element values = entry.element("values");
                for (Object o3 : values.elements()) {
                    Element value = (Element) o3;
                    reflections.getStore().getOrCreate(index.getName()).put(key.getText(), value.getText());
                }
            }
        }
    } catch (DocumentException e) {
        throw new ReflectionsException("could not read.", e);
    } catch (Throwable e) {
        throw new RuntimeException("Could not read. Make sure relevant dependencies exist on classpath.", e);
    }
    return reflections;
}
Also used : ReflectionsException(org.reflections.ReflectionsException) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document) ReflectionsException(org.reflections.ReflectionsException) DocumentException(org.dom4j.DocumentException) Reflections(org.reflections.Reflections)

Aggregations

Reflections (org.reflections.Reflections)60 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)26 SubTypesScanner (org.reflections.scanners.SubTypesScanner)20 ArrayList (java.util.ArrayList)10 URL (java.net.URL)9 Test (org.junit.Test)9 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)9 HashSet (java.util.HashSet)7 Set (java.util.Set)6 IOException (java.io.IOException)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 ResourcesScanner (org.reflections.scanners.ResourcesScanner)5 Slf4j (lombok.extern.slf4j.Slf4j)4 ClasspathHelper (org.reflections.util.ClasspathHelper)4 FilterBuilder (org.reflections.util.FilterBuilder)4 Bean (org.springframework.context.annotation.Bean)4 File (java.io.File)3 Method (java.lang.reflect.Method)3 HashMap (java.util.HashMap)3