【update】注释代码,重命名变量
This commit is contained in:
+29
-28
@@ -68,15 +68,15 @@ public class BaseCodeGenerate {
|
||||
protected void a(String projectPath, File templateRootDir, Map<String, Object> configMap, File srcFile, CreateFileConfig createFileConfig) throws Exception {
|
||||
log.debug("-------templateRootDir--" + templateRootDir.getPath());
|
||||
log.debug("-------srcFile--" + srcFile.getPath());
|
||||
String templateFile = FileHelper.getDirExcludeRootDir(templateRootDir, srcFile);
|
||||
String templateFilePath = FileHelper.getDirExcludeRootDir(templateRootDir, srcFile);
|
||||
|
||||
try {
|
||||
log.debug("-------templateFile--" + templateFile);
|
||||
if (createFileConfig.getStylePath() != null && !"".equals(createFileConfig.getStylePath()) && !templateFile.replace(File.separator, ".").startsWith(createFileConfig.getStylePath())) {
|
||||
log.debug("-------templateFile--" + templateFilePath);
|
||||
if (createFileConfig.getStylePath() != null && !"".equals(createFileConfig.getStylePath()) && !templateFilePath.replace(File.separator, ".").startsWith(createFileConfig.getStylePath())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String var7 = a(configMap, templateFile, createFileConfig);
|
||||
String var7 = a(configMap, templateFilePath, createFileConfig);
|
||||
log.debug("-------outputFilepath--" + var7);
|
||||
String var8;
|
||||
if (var7.startsWith("java")) {
|
||||
@@ -84,13 +84,13 @@ public class BaseCodeGenerate {
|
||||
var7 = var7.substring("java".length());
|
||||
var7 = var8 + var7;
|
||||
log.debug("-------java----outputFilepath--" + var7);
|
||||
this.a(templateFile, var7, configMap, createFileConfig);
|
||||
this.a(templateFilePath, var7, configMap, createFileConfig);
|
||||
} else if (var7.startsWith("webapp")) {
|
||||
var8 = projectPath + File.separator + com.jero.codegenerate.properties.CodeConfigProperties.i.replace(".", File.separator);
|
||||
var7 = var7.substring("webapp".length());
|
||||
var7 = var8 + var7;
|
||||
log.debug("-------webapp---outputFilepath---" + var7);
|
||||
this.a(templateFile, var7, configMap, createFileConfig);
|
||||
this.a(templateFilePath, var7, configMap, createFileConfig);
|
||||
}
|
||||
} catch (Exception var10) {
|
||||
log.error(var10.toString(), var10);
|
||||
@@ -119,7 +119,7 @@ public class BaseCodeGenerate {
|
||||
}
|
||||
|
||||
protected Template a(String var1, CreateFileConfig var2) throws IOException {
|
||||
return FreemarkerHelper.a(var2.listTemplateRootDirs(), charcterSet, var1).getTemplate(var1);
|
||||
return FreemarkerHelper.getConfiguration(var2.listTemplateRootDirs(), charcterSet, var1).getTemplate(var1);
|
||||
}
|
||||
|
||||
protected boolean a(File var1) {
|
||||
@@ -269,37 +269,38 @@ public class BaseCodeGenerate {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static String a(Map<String, Object> var0, String var1, CreateFileConfig var2) throws Exception {
|
||||
String var3 = var1;
|
||||
boolean var4 = true;
|
||||
int var9;
|
||||
if ((var9 = var1.indexOf(64)) != -1) {
|
||||
var3 = var1.substring(0, var9);
|
||||
String var5 = var1.substring(var9 + 1);
|
||||
Object var6 = var0.get(var5);
|
||||
if (var6 == null) {
|
||||
System.err.println("[not-generate] WARN: test expression is null by key:[" + var5 + "] on template:[" + var1 + "]");
|
||||
protected static String a(Map<String, Object> configMap, String templateFilePath, CreateFileConfig createFileConfig) throws Exception {
|
||||
String templateFilePath1 = templateFilePath;
|
||||
boolean flag = true;
|
||||
int i;
|
||||
// ascii 64 = @
|
||||
if ((i = templateFilePath.indexOf(64)) != -1) {
|
||||
templateFilePath1 = templateFilePath.substring(0, i);
|
||||
// 截取@后的字符串
|
||||
String substring = templateFilePath.substring(i + 1);
|
||||
Object o = configMap.get(substring);
|
||||
if (o == null) {
|
||||
System.err.println("[not-generate] WARN: test expression is null by key:[" + substring + "] on template:[" + templateFilePath + "]");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!"true".equals(String.valueOf(var6))) {
|
||||
log.error("[not-generate]\t test expression '@" + var5 + "' is false,template:" + var1);
|
||||
if (!"true".equals(String.valueOf(o))) {
|
||||
log.error("[not-generate]\t test expression '@" + substring + "' is false,template:" + templateFilePath);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Configuration var10 = FreemarkerHelper.a(var2.listTemplateRootDirs(), charcterSet, "/");
|
||||
var3 = FreemarkerHelper.a(var3, var0, var10);
|
||||
String var11 = var2.getStylePath();
|
||||
Configuration configuration = FreemarkerHelper.getConfiguration(createFileConfig.listTemplateRootDirs(), charcterSet, "/");
|
||||
templateFilePath1 = FreemarkerHelper.getFillTemplateString(templateFilePath1, configMap, configuration);
|
||||
String var11 = createFileConfig.getStylePath();
|
||||
if (var11 != null && var11 != "") {
|
||||
var3 = var3.substring(var11.length() + 1);
|
||||
templateFilePath1 = templateFilePath1.substring(var11.length() + 1);
|
||||
}
|
||||
|
||||
String var7 = var3.substring(var3.lastIndexOf("."));
|
||||
String var8 = var3.substring(0, var3.lastIndexOf(".")).replace(".", File.separator);
|
||||
var3 = var8 + var7;
|
||||
return var3;
|
||||
String var7 = templateFilePath1.substring(templateFilePath1.lastIndexOf("."));
|
||||
String var8 = templateFilePath1.substring(0, templateFilePath1.lastIndexOf(".")).replace(".", File.separator);
|
||||
templateFilePath1 = var8 + var7;
|
||||
return templateFilePath1;
|
||||
}
|
||||
|
||||
protected static boolean b(File var0) {
|
||||
|
||||
+3
-3
@@ -68,10 +68,10 @@ public class FileHelper {
|
||||
|
||||
}
|
||||
/**
|
||||
* 出去模板根目录后的子目录路径
|
||||
* 除去模板根目录后的子目录路径
|
||||
* @date 2021/4/2 15:04
|
||||
* @param templateRootDir
|
||||
* @param srcFile
|
||||
* @param templateRootDir 模板根目录
|
||||
* @param srcFile 模板文件
|
||||
* @return java.lang.String
|
||||
*/
|
||||
public static String getDirExcludeRootDir(File templateRootDir, File srcFile) {
|
||||
|
||||
+40
-24
@@ -24,25 +24,32 @@ public class FreemarkerHelper {
|
||||
|
||||
public FreemarkerHelper() {
|
||||
}
|
||||
/**
|
||||
* 获取配置类
|
||||
* @date 2021/4/2 15:47
|
||||
* @param templateRootDirs 模板根目录集合
|
||||
* @param charcterSet 字符集
|
||||
* @param separator 分隔符
|
||||
* @return freemarker.template.Configuration
|
||||
*/
|
||||
public static Configuration getConfiguration(List<File> templateRootDirs, String charcterSet, String separator) throws IOException {
|
||||
Configuration configuration = new Configuration();
|
||||
log.debug(" FileTemplateLoader[] size " + templateRootDirs.size());
|
||||
log.debug(" templateRootDirs templateName " + separator);
|
||||
FileTemplateLoader[] fileTemplateLoaders = new FileTemplateLoader[templateRootDirs.size()];
|
||||
|
||||
public static Configuration a(List<File> var0, String var1, String var2) throws IOException {
|
||||
Configuration var3 = new Configuration();
|
||||
log.debug(" FileTemplateLoader[] size " + var0.size());
|
||||
log.debug(" templateRootDirs templateName " + var2);
|
||||
FileTemplateLoader[] var4 = new FileTemplateLoader[var0.size()];
|
||||
|
||||
for(int var5 = 0; var5 < var0.size(); ++var5) {
|
||||
File var6 = (File)var0.get(var5);
|
||||
log.debug(" FileTemplateLoader " + var6.getAbsolutePath());
|
||||
var4[var5] = new FileTemplateLoader(var6);
|
||||
for(int i = 0; i < templateRootDirs.size(); ++i) {
|
||||
File file = (File)templateRootDirs.get(i);
|
||||
log.debug(" FileTemplateLoader " + file.getAbsolutePath());
|
||||
fileTemplateLoaders[i] = new FileTemplateLoader(file);
|
||||
}
|
||||
|
||||
MultiTemplateLoader var7 = new MultiTemplateLoader(var4);
|
||||
var3.setTemplateLoader(var7);
|
||||
var3.setNumberFormat("###############");
|
||||
var3.setBooleanFormat("true,false");
|
||||
var3.setDefaultEncoding(var1);
|
||||
return var3;
|
||||
MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader(fileTemplateLoaders);
|
||||
configuration.setTemplateLoader(multiTemplateLoader);
|
||||
configuration.setNumberFormat("###############");
|
||||
configuration.setBooleanFormat("true,false");
|
||||
configuration.setDefaultEncoding(charcterSet);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public static List<String> a(String var0, String var1) {
|
||||
@@ -75,16 +82,25 @@ public class FreemarkerHelper {
|
||||
return (String[])var3.toArray(new String[var3.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
public static String a(String var0, Map<String, Object> var1, Configuration var2) {
|
||||
StringWriter var3 = new StringWriter();
|
||||
/**
|
||||
* 获取填充好的模板字符串
|
||||
* @date 2021/4/2 16:02
|
||||
* @param templateFilePath
|
||||
* @param configMap
|
||||
* @param configuration
|
||||
* @return java.lang.String
|
||||
*/
|
||||
public static String getFillTemplateString(String templateFilePath, Map<String, Object> configMap, Configuration configuration) {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
||||
try {
|
||||
Template var4 = new Template("templateString...", new StringReader(var0), var2);
|
||||
var4.process(var1, var3);
|
||||
return var3.toString();
|
||||
} catch (Exception var5) {
|
||||
throw new IllegalStateException("cannot process templateString:" + var0 + " cause:" + var5, var5);
|
||||
// 指定使用的模板文件,使用配置类创建模板
|
||||
Template template = new Template("templateString...", new StringReader(templateFilePath), configuration);
|
||||
// 将数据模型(map)通过StringWriter填充到模板文件
|
||||
template.process(configMap, stringWriter);
|
||||
return stringWriter.toString();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("cannot process templateString:" + templateFilePath + " cause:" + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user