优化: 格式化代码

master
曹世达 6 months ago
parent e593d2415b
commit 5ea54ca168

@ -47,10 +47,10 @@ public class InfoOutBuilder {
public InfoOutBuilder setClassName(String className) { public InfoOutBuilder setClassName(String className) {
String outputPath = CfgUtils.getJavaFilePath( String outputPath = CfgUtils.getJavaFilePath(
this.outputInfo.getPackagePath(), this.outputInfo.getPackagePath(),
className, className,
this.outputInfo.getNameSuffix(), this.outputInfo.getNameSuffix(),
this.outputInfo.getNamePrefix() this.outputInfo.getNamePrefix()
); );
this.outputInfo.setOutputPath(outputPath); this.outputInfo.setOutputPath(outputPath);
return this; return this;

@ -7,7 +7,10 @@ import space.caoshd.otone.entity.ContextInfo;
import space.caoshd.otone.entity.OutputInfo; import space.caoshd.otone.entity.OutputInfo;
import space.caoshd.otone.entity.TableInfo; import space.caoshd.otone.entity.TableInfo;
import space.caoshd.otone.tool.PropTools; import space.caoshd.otone.tool.PropTools;
import space.caoshd.otone.util.*; import space.caoshd.otone.util.CfgUtils;
import space.caoshd.otone.util.FileUtils;
import space.caoshd.otone.util.PathConsts;
import space.caoshd.otone.util.VelocityUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -20,16 +23,17 @@ public class SourceBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(SourceBuilder.class); private static final Logger LOGGER = LoggerFactory.getLogger(SourceBuilder.class);
private static final PropTools CONFIG = new PropTools(PathConsts.CONFIG_PROPERTIES_PATH); private static final PropTools CONFIG = new PropTools(PathConsts.CONFIG_PROPERTIES_PATH);
private final Map<String, Object> extra = new HashMap<>();
private TableInfo tableInfo; private TableInfo tableInfo;
private OutputInfo outputInfo; private OutputInfo outputInfo;
private List<TableInfo> tableInfoList; private List<TableInfo> tableInfoList;
private List<OutputInfo> outputInfoList; private List<OutputInfo> outputInfoList;
private final Map<String, Object> extra = new HashMap<>(); private static ClassInfo buildClassInfo(TableInfo tableInfo, OutputInfo outputInfo) {
return new InfoClsBuilder().setTableName(tableInfo.getTableName())
.setPackageName(outputInfo.getPackageName())
.build();
}
public SourceBuilder setTableInfo(TableInfo tableInfo) { public SourceBuilder setTableInfo(TableInfo tableInfo) {
this.tableInfo = tableInfo; this.tableInfo = tableInfo;
@ -88,9 +92,9 @@ public class SourceBuilder {
} }
private void build(TableInfo tableInfo, OutputInfo outputInfo) { private void build(TableInfo tableInfo, OutputInfo outputInfo) {
// 创建数据文件夹 // 创建数据文件夹
FileUtils.mkdir(outputInfo.getPackagePath()); FileUtils.mkdir(outputInfo.getPackagePath());
// 创建上下文环境信息 // 创建上下文环境信息
ContextInfo contextInfo = new ContextInfo(); ContextInfo contextInfo = new ContextInfo();
// 设置表信息 // 设置表信息
@ -99,42 +103,40 @@ public class SourceBuilder {
ClassInfo classInfo = buildClassInfo(tableInfo, outputInfo); ClassInfo classInfo = buildClassInfo(tableInfo, outputInfo);
contextInfo.setConfigInfo(classInfo); contextInfo.setConfigInfo(classInfo);
// 获取输出文件路径 // 完善输出信息 计算输出路径
enhanceOutputInfo(outputInfo, classInfo); enhanceOutputInfo(outputInfo, classInfo);
String outputPath = outputInfo.getOutputPath();
// 获取模板文件路径
String templatePath = outputInfo.getTemplatePath();
// 判断输出文件是否已存在 // 判断输出文件是否已存在
if (!FileUtils.exists(outputPath)) { if (!FileUtils.exists(outputInfo.getOutputPath())) {
// 输出文件不存在 直接生成 // 输出文件不存在 直接生成
VelocityUtils.render(templatePath, outputPath, contextInfo); VelocityUtils.render(
outputInfo.getTemplatePath(),
outputInfo.getOutputPath(),
contextInfo
);
} }
// 输出文件存在 判断是否可以覆盖 // 输出文件存在 判断是否可以覆盖
if (CONFIG.getBoolean(CfgUtils.OUTPUT_COVER_IF_EXIST)) { if (CONFIG.getBoolean(CfgUtils.OUTPUT_COVER_IF_EXIST)) {
// 配置可以执行覆盖 覆盖生成 // 配置可以执行覆盖 覆盖生成
VelocityUtils.render(templatePath, outputPath, contextInfo); VelocityUtils.render(
outputInfo.getTemplatePath(),
outputInfo.getOutputPath(),
contextInfo
);
} else { } else {
// 配置不可以执行覆盖 提示错误消息 // 配置不可以执行覆盖 提示错误消息
LOGGER.warn("output file already exists: {}, " + "please remove it or enable auto " + "cover exist file," LOGGER.warn(
+ " config.properties should like [output.cover_if_exists=true]", "output file already exists: {}, " + "please remove it or enable auto "
outputPath + "cover exist file,"
+ " config.properties should like [output.cover_if_exists=true]",
outputInfo.getOutputPath()
); );
} }
} }
private void enhanceOutputInfo(OutputInfo outputInfo, ClassInfo classInfo) { private void enhanceOutputInfo(OutputInfo outputInfo, ClassInfo classInfo) {
new InfoOutBuilder() new InfoOutBuilder().init(outputInfo).setClassName(classInfo.getClassName()).build();
.init(outputInfo)
.setClassName(classInfo.getClassName())
.build();
}
private static ClassInfo buildClassInfo(TableInfo tableInfo, OutputInfo outputInfo) {
return new InfoClsBuilder()
.setTableName(tableInfo.getTableName())
.setPackageName(outputInfo.getPackageName())
.build();
} }
private void build(TableInfo tableInfo, List<OutputInfo> outputInfoList) { private void build(TableInfo tableInfo, List<OutputInfo> outputInfoList) {
@ -147,55 +149,55 @@ public class SourceBuilder {
private List<OutputInfo> defaultOutputInfoList() { private List<OutputInfo> defaultOutputInfoList() {
return Arrays.asList( return Arrays.asList(
// PO // PO
new InfoOutBuilder().setNameSuffix(CfgUtils.getPoNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getPoNameSuffix())
.setTemplatePath(CfgUtils.getPoTemplatePath()) .setTemplatePath(CfgUtils.getPoTemplatePath())
.setPackagePath(CfgUtils.getPoPackagePath()) .setPackagePath(CfgUtils.getPoPackagePath())
.setPackageName(CfgUtils.getPoPackageName()) .setPackageName(CfgUtils.getPoPackageName())
.build(), .build(),
// MAPPER // MAPPER
new InfoOutBuilder().setNameSuffix(CfgUtils.getMapperNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getMapperNameSuffix())
.setTemplatePath(CfgUtils.getMapperTemplatePath()) .setTemplatePath(CfgUtils.getMapperTemplatePath())
.setPackagePath(CfgUtils.getMapperPackagePath()) .setPackagePath(CfgUtils.getMapperPackagePath())
.setPackageName(CfgUtils.getMapperPackageName()) .setPackageName(CfgUtils.getMapperPackageName())
.build(), .build(),
// SERVICE // SERVICE
new InfoOutBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix())
.setTemplatePath(CfgUtils.getServiceTemplatePath()) .setTemplatePath(CfgUtils.getServiceTemplatePath())
.setPackagePath(CfgUtils.getServicePackagePath()) .setPackagePath(CfgUtils.getServicePackagePath())
.setPackageName(CfgUtils.getServicePackageName()) .setPackageName(CfgUtils.getServicePackageName())
.build(), .build(),
// SERVICE INTERFACE // SERVICE INTERFACE
new InfoOutBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getServiceNameSuffix())
.setNamePrefix(CfgUtils.getServiceInterfacePrefix()) .setNamePrefix(CfgUtils.getServiceInterfacePrefix())
.setTemplatePath(CfgUtils.getServiceInterfaceTemplatePath()) .setTemplatePath(CfgUtils.getServiceInterfaceTemplatePath())
.setPackagePath(CfgUtils.getServiceInterfacePackagePath()) .setPackagePath(CfgUtils.getServiceInterfacePackagePath())
.setPackageName(CfgUtils.getServiceInterfacePackageName()) .setPackageName(CfgUtils.getServiceInterfacePackageName())
.build(), .build(),
// CONTROLLER // CONTROLLER
new InfoOutBuilder().setNameSuffix(CfgUtils.getControllerNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getControllerNameSuffix())
.setTemplatePath(CfgUtils.getControllerTemplatePath()) .setTemplatePath(CfgUtils.getControllerTemplatePath())
.setPackagePath(CfgUtils.getControllerPackagePath()) .setPackagePath(CfgUtils.getControllerPackagePath())
.setPackageName(CfgUtils.getControllerPackageName()) .setPackageName(CfgUtils.getControllerPackageName())
.build(), .build(),
// VIEW // VIEW
new InfoOutBuilder().setNameSuffix(CfgUtils.getViewNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getViewNameSuffix())
.setTemplatePath(CfgUtils.getViewTemplatePath()) .setTemplatePath(CfgUtils.getViewTemplatePath())
.setPackagePath(CfgUtils.getViewPackagePath()) .setPackagePath(CfgUtils.getViewPackagePath())
.setPackageName(CfgUtils.getViewPackageName()) .setPackageName(CfgUtils.getViewPackageName())
.build(), .build(),
// FORM // FORM
new InfoOutBuilder().setNameSuffix(CfgUtils.getFormNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getFormNameSuffix())
.setTemplatePath(CfgUtils.getFormTemplatePath()) .setTemplatePath(CfgUtils.getFormTemplatePath())
.setPackagePath(CfgUtils.getFormPackagePath()) .setPackagePath(CfgUtils.getFormPackagePath())
.setPackageName(CfgUtils.getFormPackageName()) .setPackageName(CfgUtils.getFormPackageName())
.build(), .build(),
// QUERY // QUERY
new InfoOutBuilder().setNameSuffix(CfgUtils.getQueryNameSuffix()) new InfoOutBuilder().setNameSuffix(CfgUtils.getQueryNameSuffix())
.setTemplatePath(CfgUtils.getQueryTemplatePath()) .setTemplatePath(CfgUtils.getQueryTemplatePath())
.setPackagePath(CfgUtils.getQueryPackagePath()) .setPackagePath(CfgUtils.getQueryPackagePath())
.setPackageName(CfgUtils.getQueryPackageName()) .setPackageName(CfgUtils.getQueryPackageName())
.build() .build()
); );
} }

@ -1,7 +1,7 @@
package space.caoshd.otone.util; package space.caoshd.otone.util;
public class SqlConsts { public class SqlConsts {
public static final String TABLE_SQL = "table.sql"; public static final String TABLE_SQL = "table.sql";
public static final String TABLE_SQL_SCHEMA = "table.sql.schema"; public static final String TABLE_SQL_SCHEMA = "table.sql.schema";
public static final String TABLE_SQL_SCHEMA_TABLE = "table.sql.schema.table"; public static final String TABLE_SQL_SCHEMA_TABLE = "table.sql.schema.table";

Loading…
Cancel
Save