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