Search in sources :

Example 86 with Reflections

use of org.reflections.Reflections in project asterixdb by apache.

the class EvaluatorGeneratorMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    baseDir = project.getBuild().getDirectory() + File.separator + "classes";
    try {
        // Finds all sub-classes of AbstractScalarFunctionDynamicDescriptor with in the package
        // org.apache.asterix.runtime.evaluators.
        Reflections reflections = new Reflections(evaluatorPackagePrefix);
        Set<Class<? extends AbstractScalarFunctionDynamicDescriptor>> allClasses = reflections.getSubTypesOf(AbstractScalarFunctionDynamicDescriptor.class);
        // Generates byte code for all sub-classes of AbstractScalarFunctionDynamicDescriptor.
        for (Class<?> cl : allClasses) {
            getLog().info("Generating byte code for " + cl.getName());
            CodeGenUtil.generateScalarFunctionDescriptorBinary(evaluatorPackagePrefix, cl.getName(), CodeGenUtil.DEFAULT_SUFFIX_FOR_GENERATED_CLASS, reflections.getClass().getClassLoader(), (name, bytes) -> writeFile(name, bytes));
        }
    } catch (Exception e) {
        getLog().error(e);
        throw new MojoFailureException(e.toString());
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) AbstractScalarFunctionDynamicDescriptor(org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Reflections(org.reflections.Reflections)

Example 87 with Reflections

use of org.reflections.Reflections in project flink by apache.

the class RpcCompletenessTest method testRpcCompleteness.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRpcCompleteness() {
    Reflections reflections = new Reflections("org.apache.flink");
    Set<Class<? extends RpcEndpoint>> classes = reflections.getSubTypesOf(RpcEndpoint.class);
    Class<? extends RpcEndpoint> c;
    mainloop: for (Class<? extends RpcEndpoint> rpcEndpoint : classes) {
        c = rpcEndpoint;
        LOG.debug("-------------");
        LOG.debug("c: {}", c);
        // skip abstract classes
        if (Modifier.isAbstract(c.getModifiers())) {
            LOG.debug("Skipping abstract class");
            continue;
        }
        // check for type parameter bound to RpcGateway
        // skip if one is found because a subclass will provide the concrete argument
        TypeVariable<? extends Class<? extends RpcEndpoint>>[] typeParameters = c.getTypeParameters();
        LOG.debug("Checking {} parameters.", typeParameters.length);
        for (int i = 0; i < typeParameters.length; i++) {
            for (Type bound : typeParameters[i].getBounds()) {
                LOG.debug("checking bound {} of type parameter {}", bound, typeParameters[i]);
                if (bound.toString().equals("interface " + RpcGateway.class.getName())) {
                    if (i > 0) {
                        fail("Type parameter for RpcGateway should come first in " + c);
                    }
                    LOG.debug("Skipping class with type parameter bound to RpcGateway.");
                    // Type parameter is bound to RpcGateway which a subclass will provide
                    continue mainloop;
                }
            }
        }
        // check if this class or any super class contains the RpcGateway argument
        Class<?> rpcGatewayType;
        do {
            LOG.debug("checking type argument of class: {}", c);
            rpcGatewayType = ReflectionUtil.getTemplateType1(c);
            LOG.debug("type argument is: {}", rpcGatewayType);
            c = (Class<? extends RpcEndpoint>) c.getSuperclass();
        } while (!RpcGateway.class.isAssignableFrom(rpcGatewayType));
        LOG.debug("Checking RRC completeness of endpoint '{}' with gateway '{}'", rpcEndpoint.getSimpleName(), rpcGatewayType.getSimpleName());
        checkCompleteness(rpcEndpoint, (Class<? extends RpcGateway>) rpcGatewayType);
    }
}
Also used : Type(java.lang.reflect.Type) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Example 88 with Reflections

use of org.reflections.Reflections in project sling by apache.

the class OsgiMetadataUtil method initMetadataDocumentCache.

/**
     * Reads all SCR metadata XML documents located at OSGI-INF/ and caches them with quick access by implementation class.
     * @return Cache map
     */
private static Map<String, Document> initMetadataDocumentCache() {
    Map<String, Document> cacheMap = new HashMap<>();
    XPath xpath = XPATH_FACTORY.newXPath();
    xpath.setNamespaceContext(NAMESPACE_CONTEXT);
    XPathExpression xpathExpression;
    try {
        xpathExpression = xpath.compile("//*[implementation/@class]");
    } catch (XPathExpressionException ex) {
        throw new RuntimeException("Compiling XPath expression failed.", ex);
    }
    Reflections reflections = new Reflections(METADATA_PATH, new ResourcesScanner());
    Set<String> paths = reflections.getResources(Pattern.compile("^.*\\.xml$"));
    for (String path : paths) {
        parseMetadataDocuments(cacheMap, path, xpathExpression);
    }
    return cacheMap;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Document(org.w3c.dom.Document) Reflections(org.reflections.Reflections)

Example 89 with Reflections

use of org.reflections.Reflections 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)

Example 90 with Reflections

use of org.reflections.Reflections in project cas by apereo.

the class JpaServiceRegistryConfiguration method jpaServicePackagesToScan.

@Bean
public List<String> jpaServicePackagesToScan() {
    final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(CentralAuthenticationService.NAMESPACE)).setScanners(new SubTypesScanner(false)));
    final Set<Class<? extends AbstractRegisteredService>> subTypes = reflections.getSubTypesOf(AbstractRegisteredService.class);
    return subTypes.stream().map(t -> t.getPackage().getName()).collect(Collectors.toList());
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Autowired(org.springframework.beans.factory.annotation.Autowired) Reflections(org.reflections.Reflections) EnableTransactionManagement(org.springframework.transaction.annotation.EnableTransactionManagement) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) ServiceRegistryExecutionPlan(org.apereo.cas.services.ServiceRegistryExecutionPlan) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) JpaServiceRegistry(org.apereo.cas.services.JpaServiceRegistry) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DataSource(javax.sql.DataSource) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) JpaConfigDataHolder(org.apereo.cas.configuration.model.support.jpa.JpaConfigDataHolder) Set(java.util.Set) Collectors(java.util.stream.Collectors) ServiceRegistry(org.apereo.cas.services.ServiceRegistry) ClasspathHelper(org.reflections.util.ClasspathHelper) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) EntityManagerFactory(javax.persistence.EntityManagerFactory) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean) ServiceRegistryExecutionPlanConfigurer(org.apereo.cas.services.ServiceRegistryExecutionPlanConfigurer) JpaBeans(org.apereo.cas.configuration.support.JpaBeans) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Reflections(org.reflections.Reflections) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

Reflections (org.reflections.Reflections)160 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)54 SubTypesScanner (org.reflections.scanners.SubTypesScanner)41 ArrayList (java.util.ArrayList)26 Set (java.util.Set)23 ResourcesScanner (org.reflections.scanners.ResourcesScanner)21 Test (org.junit.Test)20 FilterBuilder (org.reflections.util.FilterBuilder)20 HashSet (java.util.HashSet)19 URL (java.net.URL)18 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)18 IOException (java.io.IOException)17 Collectors (java.util.stream.Collectors)17 Method (java.lang.reflect.Method)16 List (java.util.List)15 File (java.io.File)13 InputStream (java.io.InputStream)9 Field (java.lang.reflect.Field)9 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)9 ClasspathHelper (org.reflections.util.ClasspathHelper)9