Commit 91fcd505 authored by hewei's avatar hewei

增加SelectiveEnhancedPlugin插件;

parent b479fd34
......@@ -23,7 +23,7 @@ Maven引用:
<artifactId>mybatis-generator-plugin</artifactId>
<!-- 稳定版本 -->
<version>1.0.6</version>
<!-- 快照版本(最新提交到中央库,增加了部分功能,未完成测试) -->
<!-- 快照版本(最新提交到中央库,增加了部分功能,欢迎测试反馈) -->
<version>1.0.7-SNAPSHOT</version>
</dependency>
```
......
......@@ -61,6 +61,11 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
return false;
}
// 插件配置位置最好是在末尾
if (PluginTools.getConfigPlugins(getContext()).size() - 1 != PluginTools.getPluginIndex(SelectiveEnhancedPlugin.class, getContext())){
logger.warn("itfsw:插件" + this.getClass().getTypeName() + "插件建议配置在所有插件末尾以便最后调用,否则某些Selective方法得不到增强!");
}
return true;
}
......
......@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -37,27 +38,47 @@ public class PluginTools {
/**
* 检查插件依赖
* @param plugin 插件
* @param ctx 上下文
* @return
*/
public static boolean checkDependencyPlugin(Class plugin, Context ctx) {
return getPluginIndex(plugin, ctx) >= 0;
}
/**
* 获取插件所在位置
*
* @param plugin 插件
* @param ctx 上下文
* @return -1:未找到
*/
public static int getPluginIndex(Class plugin, Context ctx) {
List<PluginConfiguration> list = getConfigPlugins(ctx);
// 检查是否配置了ModelColumnPlugin插件
for (int i = 0; i < list.size(); i++) {
PluginConfiguration config = list.get(i);
if (plugin.getName().equals(config.getConfigurationType())) {
return i;
}
}
return -1;
}
/**
* 获取插件列表
* @param ctx 上下文
* @return
*/
public static boolean checkDependencyPlugin(Class plugin, Context ctx){
public static List<PluginConfiguration> getConfigPlugins(Context ctx) {
try {
// 利用反射获取pluginConfigurations属性
Field field = Context.class.getDeclaredField("pluginConfigurations");
field.setAccessible(true);
List<PluginConfiguration> list = (List<PluginConfiguration>) field.get(ctx);
// 检查是否配置了ModelColumnPlugin插件
for (PluginConfiguration config: list) {
if (plugin.getName().equals(config.getConfigurationType())){
return true;
}
}
return (List<PluginConfiguration>) field.get(ctx);
} catch (Exception e) {
logger.error("插件检查反射异常", e);
}
return false;
return new ArrayList<>();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment