use of org.reflections.util.FilterBuilder in project metron by apache.
the class ClasspathFunctionResolver method resolvables.
/**
* Returns a set of classes that should undergo further interrogation for resolution
* (aka discovery) of Stellar functions.
*/
@Override
@SuppressWarnings("unchecked")
public Set<Class<? extends StellarFunction>> resolvables() {
ClassLoader[] cls = null;
if (this.classLoaders.size() == 0) {
LOG.warn("Using System classloader");
cls = new ClassLoader[] { getClass().getClassLoader() };
} else {
List<ClassLoader> classLoaderList = new ArrayList<>();
for (int i = 0; i < this.classLoaders.size(); ++i) {
ClassLoader cl = this.classLoaders.get(i);
if (null != cl) {
LOG.debug("Using classloader: {}", cl.getClass().getCanonicalName());
classLoaderList.add(cl);
} else {
LOG.error("This should not happen, so report a bug if you see this error - Classloader {} of {} was null. Classloader list is: {}", i, this.classLoaders.size(), this.classLoaders);
}
}
cls = classLoaderList.toArray(new ClassLoader[0]);
}
FilterBuilder filterBuilder = new FilterBuilder();
excludes.forEach(excl -> {
if (excl != null) {
filterBuilder.exclude(excl);
}
});
includes.forEach(incl -> {
if (incl != null) {
filterBuilder.include(incl);
}
});
Set<String> classes = new HashSet<>();
Set<Class<? extends StellarFunction>> ret = new HashSet<>();
for (ClassLoader cl : cls) {
for (Class<?> c : getStellarClasses(cl)) {
try {
LOG.debug("{}: Found class: {}", cl.getClass().getCanonicalName(), c.getCanonicalName());
if (includeClass(c, filterBuilder)) {
String className = c.getName();
if (!classes.contains(className)) {
LOG.debug("{}: Added class: {}", cl.getClass().getCanonicalName(), className);
ret.add((Class<? extends StellarFunction>) c);
classes.add(className);
}
}
} catch (Error le) {
// the classpath is unstable (e.g. old copies of jars are on the classpath).
try {
LOG.error("Skipping class " + c.getName() + ": " + le.getMessage() + ", please check that there are not old versions of stellar functions on the classpath.", le);
} catch (Error ie) {
// it's possible that getName() will throw an exception if the class is VERY malformed.
LOG.error("Skipping class: " + le.getMessage() + ", please check that there are not old versions of stellar functions on the classpath.", le);
}
}
}
}
return ret;
}
use of org.reflections.util.FilterBuilder in project reflections by ronmamo.
the class FilterBuilderTest method includeExcludePattern.
@Test
public void includeExcludePattern() {
FilterBuilder filter = new FilterBuilder().includePattern("org\\.reflections\\..*").excludePattern("org\\.reflections\\.exclude\\..*").includePattern("org\\.foo\\..*");
doAssert(filter);
}
use of org.reflections.util.FilterBuilder in project reflections by ronmamo.
the class FilterBuilderTest method includeExcludePackage.
@Test
public void includeExcludePackage() {
FilterBuilder filter = new FilterBuilder().includePackage("org.reflections").excludePackage("org.reflections.exclude").includePackage("org.foo");
doAssert(filter);
}
use of org.reflections.util.FilterBuilder in project sldeditor by robward-scisys.
the class RegisterClasses method registerRenderers.
/**
* Register renderer converters.
*
* @param classLoadersList the class loaders list
* @param data the data
*/
private static void registerRenderers(List<ClassLoader> classLoadersList, ConversionData data) {
logger.info("Renderers supported:");
Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner()).setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))).filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.sldeditor.importdata.esri.renderer"))));
Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
for (Class<? extends Object> claszz : allClasses) {
try {
if (validClass(claszz, EsriRendererInterface.class)) {
EsriRendererInterface rendererObj = (EsriRendererInterface) claszz.newInstance();
logger.info(rendererObj.getRendererClass().getName());
data.addRenderer(rendererObj);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of org.reflections.util.FilterBuilder in project sldeditor by robward-scisys.
the class RegisterClasses method registerTextBackground.
/**
* Register text background converters.
*
* @param classLoadersList the class loaders list
* @param data the data
*/
private static void registerTextBackground(List<ClassLoader> classLoadersList, ConversionData data) {
logger.info("Text backgrounds supported:");
Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner()).setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))).filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.sldeditor.importdata.esri.textbackground"))));
Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
for (Class<? extends Object> claszz : allClasses) {
try {
if (validClass(claszz, EsriTextBackgroundInterface.class)) {
EsriTextBackgroundInterface textBackgroundObj = (EsriTextBackgroundInterface) claszz.newInstance();
logger.info(textBackgroundObj.getBackgroundClass().getName());
data.addTextBackground(textBackgroundObj);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
Aggregations