use of org.reflections.util.ConfigurationBuilder 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.util.ConfigurationBuilder 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;
}
use of org.reflections.util.ConfigurationBuilder in project reflections by ronmamo.
the class JavaCodeSerializerTest method generateAndSave.
@BeforeClass
public static void generateAndSave() {
Predicate<String> filter = new FilterBuilder().include("org.reflections.TestModel\\$.*");
Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filter).setScanners(new TypeElementsScanner().includeFields().publicOnly(false)).setUrls(asList(ClasspathHelper.forClass(TestModel.class))));
//save
String filename = ReflectionsTest.getUserDir() + "/src/test/java/org.reflections.MyTestModelStore";
reflections.save(filename, new JavaCodeSerializer());
}
use of org.reflections.util.ConfigurationBuilder in project reflections by ronmamo.
the class ReflectionsCollectTest method init.
@BeforeClass
public static void init() {
Reflections ref = new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forClass(TestModel.class)).filterInputsBy(TestModelFilter).setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new MethodParameterNamesScanner(), new MemberUsageScanner()));
ref.save(getUserDir() + "/target/test-classes" + "/META-INF/reflections/testModel-reflections.xml");
ref = new Reflections(new ConfigurationBuilder().setUrls(asList(ClasspathHelper.forClass(TestModel.class))).filterInputsBy(TestModelFilter).setScanners(new MethodParameterScanner()));
final JsonSerializer serializer = new JsonSerializer();
ref.save(getUserDir() + "/target/test-classes" + "/META-INF/reflections/testModel-reflections.json", serializer);
reflections = Reflections.collect().merge(Reflections.collect("META-INF/reflections", new FilterBuilder().include(".*-reflections.json"), serializer));
}
use of org.reflections.util.ConfigurationBuilder 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;
}
Aggregations