Search in sources :

Example 1 with ScanStaticModel

use of com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel in project disconf by knightliao.

the class ReflectionScanStatic method scanBasicInfo.

/**
     * 扫描基本信息
     */
private ScanStaticModel scanBasicInfo(List<String> packNameList) {
    ScanStaticModel scanModel = new ScanStaticModel();
    //
    // 扫描对象
    //
    Reflections reflections = getReflection(packNameList);
    scanModel.setReflections(reflections);
    //
    // 获取DisconfFile class
    //
    Set<Class<?>> classdata = reflections.getTypesAnnotatedWith(DisconfFile.class);
    scanModel.setDisconfFileClassSet(classdata);
    //
    // 获取DisconfFileItem method
    //
    Set<Method> af1 = reflections.getMethodsAnnotatedWith(DisconfFileItem.class);
    scanModel.setDisconfFileItemMethodSet(af1);
    //
    // 获取DisconfItem method
    //
    af1 = reflections.getMethodsAnnotatedWith(DisconfItem.class);
    scanModel.setDisconfItemMethodSet(af1);
    //
    // 获取DisconfActiveBackupService
    //
    classdata = reflections.getTypesAnnotatedWith(DisconfActiveBackupService.class);
    scanModel.setDisconfActiveBackupServiceClassSet(classdata);
    //
    // 获取DisconfUpdateService
    //
    classdata = reflections.getTypesAnnotatedWith(DisconfUpdateService.class);
    scanModel.setDisconfUpdateService(classdata);
    // update pipeline
    Set<Class<? extends IDisconfUpdatePipeline>> iDisconfUpdatePipeline = reflections.getSubTypesOf(IDisconfUpdatePipeline.class);
    if (iDisconfUpdatePipeline != null && iDisconfUpdatePipeline.size() != 0) {
        scanModel.setiDisconfUpdatePipeline((Class<IDisconfUpdatePipeline>) iDisconfUpdatePipeline.toArray()[0]);
    }
    return scanModel;
}
Also used : DisconfActiveBackupService(com.baidu.disconf.client.common.annotations.DisconfActiveBackupService) IDisconfUpdatePipeline(com.baidu.disconf.client.common.update.IDisconfUpdatePipeline) ScanStaticModel(com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel) Method(java.lang.reflect.Method) DisconfUpdateService(com.baidu.disconf.client.common.annotations.DisconfUpdateService) Reflections(org.reflections.Reflections) DisconfItem(com.baidu.disconf.client.common.annotations.DisconfItem)

Example 2 with ScanStaticModel

use of com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel in project disconf by knightliao.

the class ReflectionScanStatic method scan.

/**
     * 扫描想要的类
     */
@Override
public ScanStaticModel scan(List<String> packNameList) {
    // 基本信息
    ScanStaticModel scanModel = scanBasicInfo(packNameList);
    // 分析
    analysis(scanModel);
    return scanModel;
}
Also used : ScanStaticModel(com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel)

Example 3 with ScanStaticModel

use of com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel in project disconf by knightliao.

the class ScanPackTestCase method scan.

@Test
public void scan() {
    try {
        ScanStaticStrategy scanStaticStrategy = new ReflectionScanStatic();
        ScanStaticModel scanModel = scanStaticStrategy.scan(SCAN_PACK_NAME_LIST);
        // PRINT SCAN STORE
        ScanPrinterUtils.printStoreMap(scanModel.getReflections());
        // disconf file item
        LOGGER.info("=============DISCONF FILE ITEM===================");
        Set<Method> methods = scanModel.getDisconfFileItemMethodSet();
        ScanPrinterUtils.printFileItemMethod(methods);
        Assert.assertEquals(6, methods.size());
        Assert.assertEquals(4, scanModel.getDisconfFileClassSet().size());
        // disconf file item
        LOGGER.info("=============DISCONF FILE===================");
        Map<Class<?>, Set<Method>> fileMap = scanModel.getDisconfFileItemMap();
        Assert.assertEquals(4, fileMap.size());
        // disconf item
        LOGGER.info("=============DISCONF ITEM===================");
        methods = scanModel.getDisconfItemMethodSet();
        ScanPrinterUtils.printFileItemMethod(methods);
        Assert.assertEquals(1, methods.size());
        // Active backup
        LOGGER.info("=============DISCONF ACTIVE BACKUP===================");
        Set<Class<?>> classSet = scanModel.getDisconfActiveBackupServiceClassSet();
        ScanPrinterUtils.printActiveBackup(classSet);
        Assert.assertEquals(0, classSet.size());
        // Update service
        LOGGER.info("=============DISCONF Update service===================");
        classSet = scanModel.getDisconfUpdateService();
        ScanPrinterUtils.printUpdateFile(classSet);
        Assert.assertEquals(2, classSet.size());
    } catch (Exception e) {
        Assert.assertTrue(false);
    }
}
Also used : Set(java.util.Set) ReflectionScanStatic(com.baidu.disconf.client.scan.inner.statically.strategy.impl.ReflectionScanStatic) ScanStaticModel(com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel) Method(java.lang.reflect.Method) ScanStaticStrategy(com.baidu.disconf.client.scan.inner.statically.strategy.ScanStaticStrategy) Test(org.junit.Test)

Aggregations

ScanStaticModel (com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel)3 Method (java.lang.reflect.Method)2 DisconfActiveBackupService (com.baidu.disconf.client.common.annotations.DisconfActiveBackupService)1 DisconfItem (com.baidu.disconf.client.common.annotations.DisconfItem)1 DisconfUpdateService (com.baidu.disconf.client.common.annotations.DisconfUpdateService)1 IDisconfUpdatePipeline (com.baidu.disconf.client.common.update.IDisconfUpdatePipeline)1 ScanStaticStrategy (com.baidu.disconf.client.scan.inner.statically.strategy.ScanStaticStrategy)1 ReflectionScanStatic (com.baidu.disconf.client.scan.inner.statically.strategy.impl.ReflectionScanStatic)1 Set (java.util.Set)1 Test (org.junit.Test)1 Reflections (org.reflections.Reflections)1