// Path: spring-influxdb-orm/src/main/java/com/vgerbot/orm/influxdb/factory/ClassPathMeasurementScannerFactoryBean.java
// public class ClassPathMeasurementScannerFactoryBean implements FactoryBean<ClassPathMeasurementScanner>, InitializingBean, EnvironmentAware {
// 
//     public static final String MEASUREMENT_PACKAGE = "entityPackage";
// 
//     private Environment environment;
//     private String entityPackage;
//     @Override
//     public ClassPathMeasurementScanner getObject() {
//         ClassPathMeasurementScanner scanner = new ClassPathMeasurementScanner(this.environment);
//         if(!StringUtils.isBlank(entityPackage)) {
//             scanner.setEntityPackages(entityPackage.trim().split("[,;\\s\\r\\n\\t]+"));
//         }
//         return scanner;
//     }
// 
//     @Override
//     public Class<?> getObjectType() {
//         return ClassPathMeasurementScanner.class;
//     }
// 
//     public void setEntityPackage(String entityPackage) {
//         this.entityPackage = entityPackage;
//     }
// 
//     @Override
//     public void afterPropertiesSet() {
// 
//     }
// 
//     @Override
//     public void setEnvironment(Environment environment) {
//         this.environment = environment;
//     }
// }
// 
// Path: spring-influxdb-orm/src/main/java/com/vgerbot/orm/influxdb/utils/StringUtils.java
// public class StringUtils extends org.apache.commons.lang3.StringUtils {
// 
// 	/**
// 	 * 正则匹配替换，类似js中的replace
// 	 * 
// 	 * @param source
// 	 * @param regex
// 	 * @param func
// 	 * @return
// 	 */
// 	public static final String replace(String source, String regex, ReplaceCallback func) {
// 		return replace(source, regex, 0, func);
// 	}
// 
// 	public static final String replace(String source, String regex, int group, ReplaceCallback func) {
// 		Pattern pattern = Pattern.compile(regex);
// 		Matcher m = pattern.matcher(source);
// 		if (m.find()) {
// 			StringBuffer sb = new StringBuffer();
// 			int i = 0;
// 			do {
// 				String grp = m.group(group);
// 				int index = source.indexOf(grp, i);
// 				m.appendReplacement(sb, func.replace(grp, index, source));
// 				i = index + 1;
// 			} while (m.find());
// 			m.appendTail(sb);
// 			return sb.toString();
// 		}
// 		return source;
// 	}
// 
// 	/**
// 	 * 替换回调函数接口
// 	 * 
// 	 * @author y1j2x34
// 	 * @date 2014-7-24
// 	 */
// 	public static interface ReplaceCallback {
// 		String replace(String word, int index, String source);
// 	}
// 
// }


import com.vgerbot.orm.influxdb.annotations.InfluxDBORM;
import com.vgerbot.orm.influxdb.factory.ClassPathMeasurementScannerFactoryBean;
import com.vgerbot.orm.influxdb.utils.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.Assert;
import java.util.List;
package com.vgerbot.orm.influxdb.configure;



public class MeasurementScannerAutoConfigure implements ImportBeanDefinitionRegistrar, BeanFactoryAware {
    private BeanFactory beanFactory;
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(
                importingClassMetadata.getAnnotationAttributes(InfluxDBORM.class.getName(), false)
        );
        String[] measurementPackages = null;
        if (attributes != null) {
            measurementPackages = attributes.getStringArray(InfluxDBORM.FIELD_NAME_ENTITY_BASE_PACKAGE);
        }
        if (ArrayUtils.isEmpty(measurementPackages)) {
            if(AutoConfigurationPackages.has(beanFactory)) {
                List<String> packages = AutoConfigurationPackages.get(beanFactory);
                measurementPackages = packages.toArray(new String[packages.size()]);
            }
        }
        Assert.notEmpty(measurementPackages, "At least one base measurement package must be specified");
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ClassPathMeasurementScannerFactoryBean.class);
// Path: spring-influxdb-orm/src/main/java/com/vgerbot/orm/influxdb/factory/ClassPathMeasurementScannerFactoryBean.java
// public class ClassPathMeasurementScannerFactoryBean implements FactoryBean<ClassPathMeasurementScanner>, InitializingBean, EnvironmentAware {
// 
//     public static final String MEASUREMENT_PACKAGE = "entityPackage";
// 
//     private Environment environment;
//     private String entityPackage;
//     @Override
//     public ClassPathMeasurementScanner getObject() {
//         ClassPathMeasurementScanner scanner = new ClassPathMeasurementScanner(this.environment);
//         if(!StringUtils.isBlank(entityPackage)) {
//             scanner.setEntityPackages(entityPackage.trim().split("[,;\\s\\r\\n\\t]+"));
//         }
//         return scanner;
//     }
// 
//     @Override
//     public Class<?> getObjectType() {
//         return ClassPathMeasurementScanner.class;
//     }
// 
//     public void setEntityPackage(String entityPackage) {
//         this.entityPackage = entityPackage;
//     }
// 
//     @Override
//     public void afterPropertiesSet() {
// 
//     }
// 
//     @Override
//     public void setEnvironment(Environment environment) {
//         this.environment = environment;
//     }
// }
// 
// Path: spring-influxdb-orm/src/main/java/com/vgerbot/orm/influxdb/utils/StringUtils.java
// public class StringUtils extends org.apache.commons.lang3.StringUtils {
// 
// 	/**
// 	 * 正则匹配替换，类似js中的replace
// 	 * 
// 	 * @param source
// 	 * @param regex
// 	 * @param func
// 	 * @return
// 	 */
// 	public static final String replace(String source, String regex, ReplaceCallback func) {
// 		return replace(source, regex, 0, func);
// 	}
// 
// 	public static final String replace(String source, String regex, int group, ReplaceCallback func) {
// 		Pattern pattern = Pattern.compile(regex);
// 		Matcher m = pattern.matcher(source);
// 		if (m.find()) {
// 			StringBuffer sb = new StringBuffer();
// 			int i = 0;
// 			do {
// 				String grp = m.group(group);
// 				int index = source.indexOf(grp, i);
// 				m.appendReplacement(sb, func.replace(grp, index, source));
// 				i = index + 1;
// 			} while (m.find());
// 			m.appendTail(sb);
// 			return sb.toString();
// 		}
// 		return source;
// 	}
// 
// 	/**
// 	 * 替换回调函数接口
// 	 * 
// 	 * @author y1j2x34
// 	 * @date 2014-7-24
// 	 */
// 	public static interface ReplaceCallback {
// 		String replace(String word, int index, String source);
// 	}
// 
// }


// Path: spring-influxdb-orm-autoconfigure/src/main/java/com/vgerbot/orm/influxdb/configure/MeasurementScannerAutoConfigure.java
import com.vgerbot.orm.influxdb.annotations.InfluxDBORM;
import com.vgerbot.orm.influxdb.factory.ClassPathMeasurementScannerFactoryBean;
import com.vgerbot.orm.influxdb.utils.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.Assert;
import java.util.List;

package com.vgerbot.orm.influxdb.configure;



public class MeasurementScannerAutoConfigure implements ImportBeanDefinitionRegistrar, BeanFactoryAware {
    private BeanFactory beanFactory;
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(
                importingClassMetadata.getAnnotationAttributes(InfluxDBORM.class.getName(), false)
        );
        String[] measurementPackages = null;
        if (attributes != null) {
            measurementPackages = attributes.getStringArray(InfluxDBORM.FIELD_NAME_ENTITY_BASE_PACKAGE);
        }
        if (ArrayUtils.isEmpty(measurementPackages)) {
            if(AutoConfigurationPackages.has(beanFactory)) {
                List<String> packages = AutoConfigurationPackages.get(beanFactory);
                measurementPackages = packages.toArray(new String[packages.size()]);
            }
        }
        Assert.notEmpty(measurementPackages, "At least one base measurement package must be specified");
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ClassPathMeasurementScannerFactoryBean.class);
        builder.addPropertyValue(ClassPathMeasurementScannerFactoryBean.MEASUREMENT_PACKAGE, StringUtils.join(measurementPackages, ","));