【update】添加注释与重命名变量
This commit is contained in:
+25
-12
@@ -146,12 +146,12 @@ public class BaseCodeGenerate {
|
|||||||
//根据template写入数据
|
//根据template写入数据
|
||||||
FreemarkerHelper.fillDataIntoFileByTemplate(template, configMap, file, characterSet);
|
FreemarkerHelper.fillDataIntoFileByTemplate(template, configMap, file, characterSet);
|
||||||
// 文件名开头是否非法
|
// 文件名开头是否非法
|
||||||
if (!this.isStartWithIllegalStr(file)) {
|
if (!this.isStartWithSpecialStr(file)) {
|
||||||
this.messageList.add("生成成功:" + outputFilepath);
|
this.messageList.add("生成成功:" + outputFilepath);
|
||||||
}
|
}
|
||||||
// 是否以非法字符串开头
|
// 是否以非法字符串开头
|
||||||
if (this.isStartWithIllegalStr(file)) {
|
if (this.isStartWithSpecialStr(file)) {
|
||||||
this.a(file, "#segment#");
|
this.splitFileAndGenerate(file, "#segment#");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -171,11 +171,17 @@ public class BaseCodeGenerate {
|
|||||||
* @param file 文件
|
* @param file 文件
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected boolean isStartWithIllegalStr(File file) {
|
protected boolean isStartWithSpecialStr(File file) {
|
||||||
return file.getName().startsWith("[1-n]");
|
return file.getName().startsWith("[1-n]");
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
protected void a(File file, String str) {
|
* 读取文件内容分割生成各个文件
|
||||||
|
* @date 2021/4/6 15:08
|
||||||
|
* @param file 文件
|
||||||
|
* @param str 开头字符串
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected void splitFileAndGenerate(File file, String str) {
|
||||||
InputStreamReader isr = null;
|
InputStreamReader isr = null;
|
||||||
BufferedReader bf = null;
|
BufferedReader bf = null;
|
||||||
ArrayList list = new ArrayList();
|
ArrayList list = new ArrayList();
|
||||||
@@ -200,6 +206,7 @@ public class BaseCodeGenerate {
|
|||||||
String substring = s.substring(str.length());
|
String substring = s.substring(str.length());
|
||||||
// 父目录
|
// 父目录
|
||||||
String parentPath = file.getParentFile().getAbsolutePath();
|
String parentPath = file.getParentFile().getAbsolutePath();
|
||||||
|
// 文件路径
|
||||||
substring = parentPath + File.separator + substring;
|
substring = parentPath + File.separator + substring;
|
||||||
log.info("[generate]\t split file:" + file.getAbsolutePath() + " ==> " + substring);
|
log.info("[generate]\t split file:" + file.getAbsolutePath() + " ==> " + substring);
|
||||||
osw = new OutputStreamWriter(new FileOutputStream(substring), characterSet);
|
osw = new OutputStreamWriter(new FileOutputStream(substring), characterSet);
|
||||||
@@ -218,7 +225,8 @@ public class BaseCodeGenerate {
|
|||||||
bf.close();
|
bf.close();
|
||||||
isr.close();
|
isr.close();
|
||||||
log.debug("[generate]\t delete file:" + file.getAbsolutePath());
|
log.debug("[generate]\t delete file:" + file.getAbsolutePath());
|
||||||
b(file);
|
// 删除文件
|
||||||
|
delFile(file);
|
||||||
flag = false;
|
flag = false;
|
||||||
break label341;
|
break label341;
|
||||||
}
|
}
|
||||||
@@ -362,15 +370,20 @@ public class BaseCodeGenerate {
|
|||||||
templateFilePath1 = path + suffix;
|
templateFilePath1 = path + suffix;
|
||||||
return templateFilePath1;
|
return templateFilePath1;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 删除文件
|
||||||
|
* @date 2021/4/6 15:03
|
||||||
|
* @param file
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected static boolean delFile(File file) {
|
||||||
|
boolean flag = false;
|
||||||
|
|
||||||
protected static boolean b(File var0) {
|
for(int i = 0; !flag && i++ < 10; flag = file.delete()) {
|
||||||
boolean var1 = false;
|
|
||||||
|
|
||||||
for(int var2 = 0; !var1 && var2++ < 10; var1 = var0.delete()) {
|
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
return var1;
|
return flag;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 处理TemplateUrl并返回,使这个字符串不能以分割符开头和结尾
|
* 处理TemplateUrl并返回,使这个字符串不能以分割符开头和结尾
|
||||||
|
|||||||
Reference in New Issue
Block a user