Search in sources :

Example 21 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project swagger-core by swagger-api.

the class ReflectiveJaxrsScanner method getReflections.

protected Reflections getReflections() {
    if (reflections == null) {
        ConfigurationBuilder config = new ConfigurationBuilder();
        acceptablePackages = new HashSet<String>();
        if (resourcePackage != "") {
            String[] parts = resourcePackage.split(",");
            for (String pkg : parts) {
                if (!"".equals(pkg)) {
                    acceptablePackages.add(pkg);
                    config.addUrls(ClasspathHelper.forPackage(pkg));
                }
            }
        }
        config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());
        this.reflections = new Reflections(config);
    }
    return this.reflections;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 22 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project ninja by ninjaframework.

the class JaxyRoutes method configureReflections.

private void configureReflections() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    Set<URL> packagesToScan = getPackagesToScanForRoutes();
    builder.addUrls(packagesToScan);
    builder.addScanners(new MethodAnnotationsScanner());
    reflections = new Reflections(builder);
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) URL(java.net.URL) Reflections(org.reflections.Reflections)

Example 23 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project cloudstack by apache.

the class ReflectUtil method getClassesWithAnnotation.

// Gets all classes with some annotation from a package
public static Set<Class<?>> getClassesWithAnnotation(Class<? extends Annotation> annotation, String[] packageNames) {
    Reflections reflections;
    Set<Class<?>> classes = new HashSet<Class<?>>();
    ConfigurationBuilder builder = new ConfigurationBuilder();
    for (String packageName : packageNames) {
        builder.addUrls(ClasspathHelper.forPackage(packageName));
    }
    builder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
    reflections = new Reflections(builder);
    classes.addAll(reflections.getTypesAnnotatedWith(annotation));
    return classes;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Example 24 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project flink by apache.

the class CheckForbiddenMethodsUsage method testNoDefaultEncoding.

@Test
public void testNoDefaultEncoding() throws Exception {
    final Reflections reflections = new Reflections(new ConfigurationBuilder().useParallelExecutor(Runtime.getRuntime().availableProcessors()).addUrls(ClasspathHelper.forPackage("org.apache.flink")).addScanners(new MemberUsageScanner()));
    for (ForbiddenCall forbiddenCall : forbiddenCalls) {
        final Set<Member> methodUsages = forbiddenCall.getUsages(reflections);
        methodUsages.removeAll(forbiddenCall.getExclusions());
        assertEquals("Unexpected calls: " + methodUsages, 0, methodUsages.size());
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) MemberUsageScanner(org.reflections.scanners.MemberUsageScanner) Member(java.lang.reflect.Member) Reflections(org.reflections.Reflections) Test(org.junit.Test) FieldParserTest(org.apache.flink.types.parser.FieldParserTest)

Example 25 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project cas by apereo.

the class ConfigurationMetadataGenerator method locatePropertiesClassForType.

private Class locatePropertiesClassForType(final ClassOrInterfaceType type) {
    if (cachedPropertiesClasses.containsKey(type.getNameAsString())) {
        return cachedPropertiesClasses.get(type.getNameAsString());
    }
    final Predicate<String> filterInputs = s -> s.contains(type.getNameAsString());
    final Predicate<String> filterResults = s -> s.endsWith(type.getNameAsString());
    final String packageName = ConfigurationMetadataGenerator.class.getPackage().getName();
    final Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filterInputs).setUrls(ClasspathHelper.forPackage(packageName)).setScanners(new TypeElementsScanner().includeFields(false).includeMethods(false).includeAnnotations(false).filterResultsBy(filterResults), new SubTypesScanner(false)));
    final Class clz = reflections.getSubTypesOf(Serializable.class).stream().filter(c -> c.getSimpleName().equalsIgnoreCase(type.getNameAsString())).findFirst().orElseThrow(() -> new IllegalArgumentException("Cant locate class for " + type.getNameAsString()));
    cachedPropertiesClasses.put(type.getNameAsString(), clz);
    return clz;
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Arrays(java.util.Arrays) SneakyThrows(lombok.SneakyThrows) VoidVisitorAdapter(com.github.javaparser.ast.visitor.VoidVisitorAdapter) Reflections(org.reflections.Reflections) StringUtils(org.apache.commons.lang3.StringUtils) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) LiteralStringValueExpr(com.github.javaparser.ast.expr.LiteralStringValueExpr) ClassUtils(org.apache.commons.lang3.ClassUtils) QueryType(org.apereo.services.persondir.support.QueryType) Matcher(java.util.regex.Matcher) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) CompilationUnit(com.github.javaparser.ast.CompilationUnit) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Resource(org.springframework.core.io.Resource) ValueHint(org.springframework.boot.configurationmetadata.ValueHint) Unchecked(org.jooq.lambda.Unchecked) Collection(java.util.Collection) Set(java.util.Set) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) Collectors(java.util.stream.Collectors) PasswordPolicyProperties(org.apereo.cas.configuration.model.core.authentication.PasswordPolicyProperties) ClasspathHelper(org.reflections.util.ClasspathHelper) Modifier(com.github.javaparser.ast.Modifier) Serializable(java.io.Serializable) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Predicate(com.google.common.base.Predicate) Pattern(java.util.regex.Pattern) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) TypeElementsScanner(org.reflections.scanners.TypeElementsScanner) RequiresModule(org.apereo.cas.configuration.support.RequiresModule) HashMap(java.util.HashMap) PrincipalTransformationProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalTransformationProperties) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) HashSet(java.util.HashSet) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) StreamSupport(java.util.stream.StreamSupport) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) LinkedHashSet(java.util.LinkedHashSet) RelaxedNames(org.springframework.boot.bind.RelaxedNames) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) RequiredProperty(org.apereo.cas.configuration.support.RequiredProperty) CaseCanonicalizationMode(org.apereo.services.persondir.util.CaseCanonicalizationMode) File(java.io.File) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) ReflectionUtils(org.springframework.util.ReflectionUtils) LdapSearchEntryHandlersProperties(org.apereo.cas.configuration.model.support.ldap.LdapSearchEntryHandlersProperties) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) PrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeElementsScanner(org.reflections.scanners.TypeElementsScanner) Reflections(org.reflections.Reflections)

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