Search in sources :

Example 16 with ConfigurationBuilder

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;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Reflections(org.reflections.Reflections)

Example 17 with ConfigurationBuilder

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

Example 18 with ConfigurationBuilder

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());
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) JavaCodeSerializer(org.reflections.serializers.JavaCodeSerializer) FilterBuilder(org.reflections.util.FilterBuilder) TypeElementsScanner(org.reflections.scanners.TypeElementsScanner) BeforeClass(org.junit.BeforeClass)

Example 19 with ConfigurationBuilder

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));
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FilterBuilder(org.reflections.util.FilterBuilder) JsonSerializer(org.reflections.serializers.JsonSerializer) BeforeClass(org.junit.BeforeClass)

Example 20 with ConfigurationBuilder

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;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Aggregations

ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)29 Reflections (org.reflections.Reflections)26 SubTypesScanner (org.reflections.scanners.SubTypesScanner)16 URL (java.net.URL)7 ArrayList (java.util.ArrayList)7 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)7 FilterBuilder (org.reflections.util.FilterBuilder)7 HashSet (java.util.HashSet)5 List (java.util.List)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 Slf4j (lombok.extern.slf4j.Slf4j)5 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)4 ResourcesScanner (org.reflections.scanners.ResourcesScanner)4 ClasspathHelper (org.reflections.util.ClasspathHelper)4 Bean (org.springframework.context.annotation.Bean)4 File (java.io.File)3 Map (java.util.Map)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)3 IOException (java.io.IOException)2