【update】注释代码

This commit is contained in:
mzc5649
2021-04-02 15:07:07 +08:00
parent 1cc1919403
commit 56d5596967
4 changed files with 88 additions and 41 deletions
@@ -39,12 +39,18 @@ public class CreateFileConfig {
public void setStylePath(String stylePath) {
this.stylePath = stylePath;
}
/**
* 返回模板目录集合
* @date 2021/4/2 14:45
* @param
* @return java.util.List<java.io.File>
*/
public List<File> listTemplateRootDirs() {
String file = this.getClass().getResource(this.templatePath).getFile();
file = file.replaceAll("%20", " ");
log.debug("-------classpath-------" + file);
if (file.indexOf("/BOOT-INF/classes!") != -1 || file.indexOf("/BOOT-INF/lib/") != -1) {
// 当前工程路径
file = System.getProperty("user.dir") + File.separator + "config/jero/code-template-online/".replace("/", File.separator);
log.debug("---JAR--config--classpath-------" + file);
}
@@ -100,6 +100,7 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
return this.list;
}
@Override
public List<String> generateCodeFile(String projectPath, String templatePath, String stylePath) throws Exception {
if (projectPath != null && !"".equals(projectPath)) {
com.jero.codegenerate.properties.CodeConfigProperties.a(projectPath);
@@ -28,38 +28,47 @@ public class BaseCodeGenerate {
public BaseCodeGenerate() {
}
/**
* 生成项目文件
* @date 2021/4/2 14:32
* @param createFileConfig 配置类
* @param projectPath 项目生成路径
* @param configMap 代码配置map
* @return void
*/
protected void createProject(CreateFileConfig createFileConfig, String projectPath, Map<String, Object> configMap) throws Exception {
log.debug("--------generate----projectPath--------" + projectPath);
for(int i = 0; i < createFileConfig.listTemplateRootDirs().size(); ++i) {
File templateDir = (File)createFileConfig.listTemplateRootDirs().get(i);
this.a(projectPath, templateDir, configMap, createFileConfig);
// 模板根目录
File templateRootDir = (File)createFileConfig.listTemplateRootDirs().get(i);
this.a(projectPath, templateRootDir, configMap, createFileConfig);
}
}
protected void a(String projectPath, File templateDir, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
if (templateDir == null) {
protected void a(String projectPath, File templateRootDir, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
if (templateRootDir == null) {
throw new IllegalStateException("'templateRootDir' must be not null");
} else {
log.info(" load template from templateRootDir = '" + templateDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "', out GenerateRootDir:" + com.jero.codegenerate.properties.CodeConfigProperties.projectPath);
List fileList = FileHelper.listFileAndSort(templateDir);
log.debug("----srcFiles----size-----------" + fileList.size());
log.debug("----srcFiles----list------------" + fileList.toString());
log.info(" load template from templateRootDir = '" + templateRootDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "', out GenerateRootDir:" + com.jero.codegenerate.properties.CodeConfigProperties.projectPath);
List templateFileList = FileHelper.listFileAndSort(templateRootDir);
log.debug("----srcFiles----size-----------" + templateFileList.size());
log.debug("----srcFiles----list------------" + templateFileList.toString());
for(int i = 0; i < fileList.size(); ++i) {
File srcFile = (File)fileList.get(i);
this.a(projectPath, templateDir, configMap, srcFile, createFileConfig);
for(int i = 0; i < templateFileList.size(); ++i) {
// 获取一个模板文件
File srcFile = (File)templateFileList.get(i);
this.a(projectPath, templateRootDir, configMap, srcFile, createFileConfig);
}
}
}
protected void a(String projectPath, File templateDir, Map<String, Object> configMap, File srcFile, CreateFileConfig createFileConfig) throws Exception {
log.debug("-------templateRootDir--" + templateDir.getPath());
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.a(templateDir, srcFile);
String templateFile = FileHelper.getDirExcludeRootDir(templateRootDir, srcFile);
try {
log.debug("-------templateFile--" + templateFile);
@@ -96,7 +105,7 @@ public class BaseCodeGenerate {
Template var5 = this.a(var1, var4);
var5.setOutputEncoding(charcterSet);
File var6 = FileHelper.c(var2);
File var6 = FileHelper.createFile(var2);
log.info("[generate]\t template:" + var1 + " ==> " + var2);
FreemarkerHelper.a(var5, var3, var6, charcterSet);
if (!this.a(var6)) {
@@ -67,45 +67,76 @@ public class FileHelper {
}
}
public static String a(File templateDir, File srcFile) {
if (templateDir.equals(srcFile)) {
/**
* 出去模板根目录后的子目录路径
* @date 2021/4/2 15:04
* @param templateRootDir
* @param srcFile
* @return java.lang.String
*/
public static String getDirExcludeRootDir(File templateRootDir, File srcFile) {
if (templateRootDir.equals(srcFile)) {
return "";
} else {
return templateDir.getParentFile() == null ? srcFile.getAbsolutePath().substring(templateDir.getAbsolutePath().length()) : srcFile.getAbsolutePath().substring(templateDir.getAbsolutePath().length() + 1);
return templateRootDir.getParentFile() == null ? srcFile.getAbsolutePath().substring(templateRootDir.getAbsolutePath().length()) : srcFile.getAbsolutePath().substring(templateRootDir.getAbsolutePath().length() + 1);
}
}
public static boolean b(File file) {
return file.isDirectory() ? false : a(file.getName());
/**
* 是否为一个文件
* @date 2021/4/2 13:59
* @param file
* @return boolean
*/
public static boolean isFile(File file) {
return file.isDirectory() ? false : isSuffixNotBlank(file.getName());
}
public static boolean a(String var0) {
return !StringUtils.isBlank(b(var0));
/**
* 后缀名是否为空白
* @date 2021/4/2 13:40
* @param fileName
* @return boolean
*/
public static boolean isSuffixNotBlank(String fileName) {
return !StringUtils.isBlank(getSuffix(fileName));
}
public static String b(String fileName) {
/**
* 获取后缀名
* @date 2021/4/2 13:20
* @param fileName
* @return java.lang.String
*/
public static String getSuffix(String fileName) {
if (fileName == null) {
return null;
} else {
int var1 = fileName.indexOf(".");
return var1 == -1 ? "" : fileName.substring(var1 + 1);
int index = fileName.indexOf(".");
return index == -1 ? "" : fileName.substring(index + 1);
}
}
public static File c(String var0) {
if (var0 == null) {
/**
* 创建文件以及父目录
* @date 2021/4/2 13:57
* @param file
* @return java.io.File
*/
public static File createFile(String file) {
if (file == null) {
throw new IllegalArgumentException("file must be not null");
} else {
File var1 = new File(var0);
c(var1);
return var1;
File file1 = new File(file);
createParentFile(file1);
return file1;
}
}
public static void c(File var0) {
if (var0.getParentFile() != null) {
var0.getParentFile().mkdirs();
/**
* 创建父目录
* @date 2021/4/2 13:58
* @param file
* @return void
*/
public static void createParentFile(File file) {
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
}