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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations