Java Code Examples for io.github.lukehutch.fastclasspathscanner.FastClasspathScanner#scan()

The following examples show how to use io.github.lukehutch.fastclasspathscanner.FastClasspathScanner#scan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractServiceAutomaticHandlerRegistrationTest.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
@Test
public void it_should_find_handlers() throws Exception {
    TestService service = new TestService();
    service.initializeGuice();

    FastClasspathScanner scanner = new FastClasspathScanner();
    ScanResult scanResult = scanner.scan();
    List<String> rpcHandlers = scanResult.getNamesOfClassesWithAnnotation(RpcHandler.class);

    service.registerMethodHandlers(rpcHandlers);

    Map<String, ServiceMethodHandler<? extends Message, ? extends Message>> s = service.getMethodHandlers();
    assertThat(s.size() == 2);
    assertThat(s.containsKey("Test.handler1"));
    assertThat(s.containsKey("Test.handler2"));
    assertThat(s.get("Test.handler1").getClass().equals(TestHandler.class));
    assertThat(s.get("Test.handler2").getClass().equals(TestHandler2.class));
}
 
Example 2
Source File: JsonldContextFactory.java    From jackson-jsonld with MIT License 6 votes vote down vote up
public static ObjectNode fromPackage(String packageName) {
    ObjectNode generatedContext = JsonNodeFactory.withExactBigDecimals(true).objectNode();
    FastClasspathScanner scanner = new FastClasspathScanner(packageName);
    scanner.matchAllStandardClasses((clazz) -> {
        if(!Modifier.isAbstract(clazz.getModifiers()) && AnnotationsUtils.isAnnotationPresent(clazz, JsonldTypeFromJavaClass.class)) {
            Optional<String> type = JsonldResourceUtils.dynamicTypeLookup(clazz);
            type.ifPresent(t ->generatedContext.set(clazz.getSimpleName(), TextNode.valueOf(t)));
        }
        if(AnnotationsUtils.isAnnotationPresent(clazz, ioinformarics.oss.jackson.module.jsonld.annotation.JsonldResource.class)) {
            Optional<ObjectNode> resourceContext = fromAnnotations(clazz);
            resourceContext.ifPresent((context) -> JsonUtils.merge(generatedContext, context));
        }
    });
    scanner.scan();
    return (ObjectNode) JsonNodeFactory.withExactBigDecimals(true).objectNode().set("@context", generatedContext);
}
 
Example 3
Source File: RpcMethodScanner.java    From ja-micro with Apache License 2.0 5 votes vote down vote up
public List<String> getGeneratedProtoClasses(String serviceName) {
    FastClasspathScanner cpScanner = new FastClasspathScanner();
    ScanResult scanResult = cpScanner.scan();
    List<String> oldProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessage.class);
    List<String> newProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessageV3.class);
    List<String> retval = Stream.concat(oldProtobuf.stream(),
            newProtobuf.stream()).collect(Collectors.toList());
    String[] packageTokens = serviceName.split("\\.");
    return retval.stream().filter(s -> protoFilePackageMatches(s, packageTokens)).collect(Collectors.toList());
}
 
Example 4
Source File: WebServiceListener.java    From uavstack with Apache License 2.0 5 votes vote down vote up
public void doInstallDProxy(ClassLoader webapploader, final String appid, String contextPath) {

        // like SMS, which uses the sun jax-ws RI/Metro-jax-ws RI bind webservices when the servlet starts should
        // profile in ComponentProfileHandler

        FastClasspathScanner fcs = new FastClasspathScanner(new ClassLoader[] { webapploader });
        fcs.scan();
        List<String> endPoints = fcs.getNamesOfDirectSubclassesOf("javax.xml.ws.Endpoint");

        if (!endPoints.isEmpty()) {
            dpInstall.setTargetClassLoader(webapploader);

            for (int i = 0; i < endPoints.size(); i++) {

                dpInstall.installProxy(endPoints.get(i),
                        new String[] { "com.creditease.uav.monitorframework.webservice.interceptors" },
                        new DynamicProxyProcessor() {

                            @Override
                            public void process(DPMethod m) throws Exception {

                                if ("publish".equals(m.getName()) && m.getParameterTypes().length > 0
                                        && m.getParameterTypes()[0].getSimpleName().equals("String")) {

                                    dpInstall.defineLocalVal(m, "mObj", WebServiceListenerIT.class);
                                    m.insertBefore("{mObj=new WebServiceListenerIT(\"" + appid
                                            + "\");mObj.obtainWsInfo($1,getImplementor());}");

                                }

                            }
                        }, false);
            }

            // release loader
            dpInstall.releaseTargetClassLoader();
        }

    }
 
Example 5
Source File: FastclassPathScannerProvider.java    From nubes with Apache License 2.0 5 votes vote down vote up
public FastclassPathScannerProvider(String ppackage){
    packageName = ppackage;

    if (cachedScans.containsKey(ppackage)){
    }else{
        FastClasspathScanner fastClasspathScanner = new FastClasspathScanner(ppackage);
        ScanResult scanResult = fastClasspathScanner.scan();
        cachedScans.put(ppackage, scanResult);
    }
}
 
Example 6
Source File: MSCPProfileHandler.java    From uavstack with Apache License 2.0 4 votes vote down vote up
@Override
public void doProfiling(ProfileElement elem, ProfileContext context) {

    UAVServer.ServerVendor sv = (UAVServer.ServerVendor) UAVServer.instance()
            .getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);

    // only support MSCP Application
    if (sv != UAVServer.ServerVendor.MSCP) {
        return;
    }

    if (!ProfileConstants.PROELEM_COMPONENT.equals(elem.getElemId())) {
        return;
    }

    InterceptContext ic = context.get(InterceptContext.class);

    if (ic == null) {
        this.logger.warn("Profile:Annotation FAILs as No InterceptContext available", null);
        return;
    }

    /**
     * 1. get webappclassloader
     */
    ClassLoader webappclsLoader = (ClassLoader) ic.get(InterceptConstants.WEBAPPLOADER);

    if (null == webappclsLoader) {
        this.logger.warn("Profile:JARS FAILs as No webappclsLoader available", null);
        return;
    }

    Collection<ClassLoader> clList = ConfigurationManager.getInstance().getFeatureClassLoader();
    clList.add(webappclsLoader);

    ClassLoader[] allcl = new ClassLoader[clList.size()];
    allcl = clList.toArray(allcl);

    /**
     * 2. see what kind of components we could get via annotations or interface or parentClass
     */
    FastClasspathScanner fcs = new FastClasspathScanner(allcl, "com.creditease.uav", "com.creditease.agent",
            "org.uavstack");
    fcs.scan();

    /**
     * 3. get MSCPServlets profile info
     */

    InterceptContext itContext = context.get(InterceptContext.class);
    String appRootPath = (String) itContext.get(InterceptConstants.BASEPATH);
    String appName = (String) itContext.get(InterceptConstants.APPNAME);

    for (String componentClassName : componentClassMap.keySet()) {

        // set the instance id = simple name of the annotation class
        ProfileElementInstance inst = elem.getInstance(componentClassName);

        ComponentProcessor cp = componentClassMap.get(componentClassName);

        cp.handle(componentClassName, appName, inst, fcs);

    }

    /**
     * 4. load application info
     */
    loadAppInfo(elem, appRootPath, appName);
}