Commit 577eb406 authored by hewei's avatar hewei

配合测试用例的编写,更新日志打印方式,采用官方实现,优化warning日志打印位置到所有日志最后

parent f8b2af30
......@@ -47,7 +47,7 @@ public class ExampleTargetPlugin extends BasePlugin {
Properties properties = getProperties();
this.targetPackage = properties.getProperty(TARGET_PACKAGE_KEY);
if (this.targetPackage == null){
logger.error("请配置com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin插件的目标包名(targetPackage)!");
warnings.add("请配置com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin插件的目标包名(targetPackage)!");
return false;
}
return super.validate(warnings);
......
......@@ -52,7 +52,7 @@ public class IncrementsPlugin extends BasePlugin {
// 插件使用前提是使用了ModelBuilderPlugin插件
if (!PluginTools.checkDependencyPlugin(getContext(), ModelBuilderPlugin.class)) {
logger.error("itfsw:插件" + this.getClass().getTypeName() + "插件需配合com.itfsw.mybatis.generator.plugins.ModelBuilderPlugin插件使用!");
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件需配合com.itfsw.mybatis.generator.plugins.ModelBuilderPlugin插件使用!");
return false;
}
......@@ -65,7 +65,7 @@ public class IncrementsPlugin extends BasePlugin {
*/
@Override
public void initialized(IntrospectedTable introspectedTable) {
this.incTools = IncrementsPluginTools.getTools(context, introspectedTable);
this.incTools = IncrementsPluginTools.getTools(context, introspectedTable, warnings);
}
/**
......
......@@ -42,7 +42,7 @@ public class LimitPlugin extends BasePlugin {
public boolean validate(List<String> warnings) {
// 该插件只支持MYSQL
if ("com.mysql.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false){
logger.error("itfsw:插件"+this.getClass().getTypeName()+"只支持MySQL数据库!");
warnings.add("itfsw:插件"+this.getClass().getTypeName()+"只支持MySQL数据库!");
return false;
}
return super.validate(warnings);
......
......@@ -105,18 +105,18 @@ public class LogicalDeletePlugin extends BasePlugin {
|| JDBCType.VARCHAR == type){
this.logicalDeleteColumn = column;
} else {
logger.warn("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"逻辑删除列("+introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY)+")的类型不在支持范围(请使用数字列,字符串列,布尔列)!");
warnings.add("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"逻辑删除列("+introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY)+")的类型不在支持范围(请使用数字列,字符串列,布尔列)!");
}
}
}
if (introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY) != null && this.logicalDeleteColumn == null){
logger.warn("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"没有找到您配置的逻辑删除列("+introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY)+")!");
warnings.add("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"没有找到您配置的逻辑删除列("+introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY)+")!");
}
// 4. 判断逻辑删除值是否配置了
if (this.logicalDeleteColumn != null && (this.logicalDeleteValue == null || this.logicalUnDeleteValue == null)){
logger.warn("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"没有找到您配置的逻辑删除值,请全局或者局部配置logicalDeleteValue和logicalUnDeleteValue值!");
warnings.add("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"没有找到您配置的逻辑删除值,请全局或者局部配置logicalDeleteValue和logicalUnDeleteValue值!");
}
}
......
......@@ -131,7 +131,7 @@ public class ModelBuilderPlugin extends BasePlugin {
// ========================================== IncrementsPlugin =======================================
IncrementsPluginTools incTools = IncrementsPluginTools.getTools(context, introspectedTable);
IncrementsPluginTools incTools = IncrementsPluginTools.getTools(context, introspectedTable, warnings);
if (incTools.support()) {
if (modelBaseRecord) {
// 增加枚举
......
......@@ -47,12 +47,12 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
// 插件使用前提是使用了ModelColumnPlugin插件
if (!PluginTools.checkDependencyPlugin(getContext(), ModelColumnPlugin.class)) {
logger.error("itfsw:插件" + this.getClass().getTypeName() + "插件需配合com.itfsw.mybatis.generator.plugins.ModelColumnPlugin插件使用!");
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件需配合com.itfsw.mybatis.generator.plugins.ModelColumnPlugin插件使用!");
return false;
}
// 插件位置
PluginTools.shouldAfterPlugins(getContext(), this.getClass(), UpsertPlugin.class);
PluginTools.shouldAfterPlugins(getContext(), this.getClass(), warnings, UpsertPlugin.class);
return super.validate(warnings);
}
......
......@@ -44,7 +44,7 @@ public class TablePrefixPlugin extends BasePlugin {
// 如果table配置了domainObjectName或者mapperName就不要再启动该插件了
for (TableConfiguration tableConfiguration : context.getTableConfigurations()) {
if (tableConfiguration.getDomainObjectName() != null || tableConfiguration.getMapperName() != null) {
logger.error("itfsw:插件" + this.getClass().getTypeName() + "插件请不要配合table的domainObjectName或者mapperName一起使用!");
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件请不要配合table的domainObjectName或者mapperName一起使用!");
return false;
}
}
......
......@@ -48,14 +48,14 @@ public class TableRenamePlugin extends BasePlugin {
// 如果配置了searchString 或者 replaceString,二者不允许单独存在
if ((getProperties().getProperty(PRE_SEARCH_STRING) == null && getProperties().getProperty(PRE_REPLACE_STRING) != null)
|| (getProperties().getProperty(PRE_SEARCH_STRING) != null && getProperties().getProperty(PRE_REPLACE_STRING) == null)) {
logger.error("itfsw:插件" + this.getClass().getTypeName() + "插件的searchString、replaceString属性需配合使用,不能单独存在!");
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件的searchString、replaceString属性需配合使用,不能单独存在!");
return false;
}
// 如果table配置了domainObjectName或者mapperName就不要再启动该插件了
for (TableConfiguration tableConfiguration: context.getTableConfigurations()) {
if (tableConfiguration.getDomainObjectName() != null || tableConfiguration.getMapperName() != null){
logger.error("itfsw:插件" + this.getClass().getTypeName() + "插件请不要配合table的domainObjectName或者mapperName一起使用!");
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件请不要配合table的domainObjectName或者mapperName一起使用!");
return false;
}
}
......
......@@ -61,7 +61,7 @@ public class UpsertPlugin extends BasePlugin {
// 插件使用前提是数据库为MySQL
if ("com.mysql.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false) {
logger.error("itfsw:插件" + this.getClass().getTypeName() + "插件使用前提是数据库为MySQL!");
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件使用前提是数据库为MySQL!");
return false;
}
......@@ -71,7 +71,7 @@ public class UpsertPlugin extends BasePlugin {
this.allowMultiQueries = allowMultiQueries == null ? false : StringUtility.isTrue(allowMultiQueries);
if (this.allowMultiQueries) {
// 提示用户注意信息
logger.warn("itfsw:插件" + this.getClass().getTypeName() + "插件您开启了allowMultiQueries支持,注意在jdbc url 配置中增加“allowMultiQueries=true”支持(不怎么建议使用该功能,开启多sql提交会增加sql注入的风险,请确保你所有sql都使用MyBatis书写,请不要使用statement进行sql提交)!");
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件您开启了allowMultiQueries支持,注意在jdbc url 配置中增加“allowMultiQueries=true”支持(不怎么建议使用该功能,开启多sql提交会增加sql注入的风险,请确保你所有sql都使用MyBatis书写,请不要使用statement进行sql提交)!");
}
return super.validate(warnings);
......@@ -509,7 +509,7 @@ public class UpsertPlugin extends BasePlugin {
* @param hasPrefix
*/
private void incrementsSelectiveSupport(XmlElement xmlElement, XmlElement trimXmlElement, IntrospectedTable introspectedTable, boolean hasPrefix) {
IncrementsPluginTools incTools = IncrementsPluginTools.getTools(context, introspectedTable);
IncrementsPluginTools incTools = IncrementsPluginTools.getTools(context, introspectedTable, warnings);
if (incTools.support()) {
List<Element> ifs = new ArrayList<>();
// 获取if节点
......@@ -537,7 +537,7 @@ public class UpsertPlugin extends BasePlugin {
* @param hasPrefix
*/
private void incrementsSupport(XmlElement xmlElement, List<TextElement> elements, IntrospectedTable introspectedTable, boolean hasPrefix) {
IncrementsPluginTools incTools = IncrementsPluginTools.getTools(context, introspectedTable);
IncrementsPluginTools incTools = IncrementsPluginTools.getTools(context, introspectedTable, warnings);
for (TextElement element : elements) {
if (incTools.support()) {
// 获取column
......
......@@ -62,9 +62,10 @@ public class IncrementsPluginTools {
* 获取工具
* @param context
* @param introspectedTable
* @param warnings
* @return
*/
public static IncrementsPluginTools getTools(Context context, IntrospectedTable introspectedTable) {
public static IncrementsPluginTools getTools(Context context, IntrospectedTable introspectedTable, List<String> warnings) {
IncrementsPluginTools tools = new IncrementsPluginTools(context, introspectedTable);
// 判断是否启用了插件
if (PluginTools.getPluginConfiguration(context, IncrementsPlugin.class) != null) {
......@@ -75,7 +76,7 @@ public class IncrementsPluginTools {
for (String incrementsColumnsStr : incrementsColumnsStrs) {
IntrospectedColumn column = introspectedTable.getColumn(incrementsColumnsStr.trim());
if (column == null) {
logger.warn("itfsw:插件" + IncrementsPlugin.class.getTypeName() + "插件没有找到column为" + incrementsColumnsStr.trim() + "的字段!");
warnings.add("itfsw:插件" + IncrementsPlugin.class.getTypeName() + "插件没有找到column为" + incrementsColumnsStr.trim() + "的字段!");
} else {
tools.columns.add(column);
}
......
......@@ -104,16 +104,17 @@ public class PluginTools {
*
* @param context
* @param plugin
* @param warnings
* @param plugins
* @return
*/
public static boolean shouldAfterPlugins(Context context, Class plugin, Class ... plugins){
public static boolean shouldAfterPlugins(Context context, Class plugin, List<String> warnings, Class ... plugins){
int index = getPluginIndex(context, plugin);
if (plugins != null){
for (Class cls : plugins){
int index1 = getPluginIndex(context, cls);
if (index1 != -1 && index1 >= index){
logger.warn("itfsw:插件" + plugin.getTypeName() + "插件建议配置在插件"+cls.getTypeName()+"后面,否则某些功能可能得不到增强!");
warnings.add("itfsw:插件" + plugin.getTypeName() + "插件建议配置在插件"+cls.getTypeName()+"后面,否则某些功能可能得不到增强!");
return false;
}
}
......
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