【update】注释代码
This commit is contained in:
+7
-1
@@ -39,12 +39,18 @@ public class CreateFileConfig {
|
|||||||
public void setStylePath(String stylePath) {
|
public void setStylePath(String stylePath) {
|
||||||
this.stylePath = stylePath;
|
this.stylePath = stylePath;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 返回模板目录集合
|
||||||
|
* @date 2021/4/2 14:45
|
||||||
|
* @param
|
||||||
|
* @return java.util.List<java.io.File>
|
||||||
|
*/
|
||||||
public List<File> listTemplateRootDirs() {
|
public List<File> listTemplateRootDirs() {
|
||||||
String file = this.getClass().getResource(this.templatePath).getFile();
|
String file = this.getClass().getResource(this.templatePath).getFile();
|
||||||
file = file.replaceAll("%20", " ");
|
file = file.replaceAll("%20", " ");
|
||||||
log.debug("-------classpath-------" + file);
|
log.debug("-------classpath-------" + file);
|
||||||
if (file.indexOf("/BOOT-INF/classes!") != -1 || file.indexOf("/BOOT-INF/lib/") != -1) {
|
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);
|
file = System.getProperty("user.dir") + File.separator + "config/jero/code-template-online/".replace("/", File.separator);
|
||||||
log.debug("---JAR--config--classpath-------" + file);
|
log.debug("---JAR--config--classpath-------" + file);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -100,6 +100,7 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
|
|||||||
return this.list;
|
return this.list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<String> generateCodeFile(String projectPath, String templatePath, String stylePath) throws Exception {
|
public List<String> generateCodeFile(String projectPath, String templatePath, String stylePath) throws Exception {
|
||||||
if (projectPath != null && !"".equals(projectPath)) {
|
if (projectPath != null && !"".equals(projectPath)) {
|
||||||
com.jero.codegenerate.properties.CodeConfigProperties.a(projectPath);
|
com.jero.codegenerate.properties.CodeConfigProperties.a(projectPath);
|
||||||
|
|||||||
+25
-16
@@ -28,38 +28,47 @@ public class BaseCodeGenerate {
|
|||||||
|
|
||||||
public 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 {
|
protected void createProject(CreateFileConfig createFileConfig, String projectPath, Map<String, Object> configMap) throws Exception {
|
||||||
log.debug("--------generate----projectPath--------" + projectPath);
|
log.debug("--------generate----projectPath--------" + projectPath);
|
||||||
|
|
||||||
for(int i = 0; i < createFileConfig.listTemplateRootDirs().size(); ++i) {
|
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 {
|
protected void a(String projectPath, File templateRootDir, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
|
||||||
if (templateDir == null) {
|
if (templateRootDir == null) {
|
||||||
throw new IllegalStateException("'templateRootDir' must be not null");
|
throw new IllegalStateException("'templateRootDir' must be not null");
|
||||||
} else {
|
} else {
|
||||||
log.info(" load template from templateRootDir = '" + templateDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "', out GenerateRootDir:" + com.jero.codegenerate.properties.CodeConfigProperties.projectPath);
|
log.info(" load template from templateRootDir = '" + templateRootDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "', out GenerateRootDir:" + com.jero.codegenerate.properties.CodeConfigProperties.projectPath);
|
||||||
List fileList = FileHelper.listFileAndSort(templateDir);
|
List templateFileList = FileHelper.listFileAndSort(templateRootDir);
|
||||||
log.debug("----srcFiles----size-----------" + fileList.size());
|
log.debug("----srcFiles----size-----------" + templateFileList.size());
|
||||||
log.debug("----srcFiles----list------------" + fileList.toString());
|
log.debug("----srcFiles----list------------" + templateFileList.toString());
|
||||||
|
|
||||||
for(int i = 0; i < fileList.size(); ++i) {
|
for(int i = 0; i < templateFileList.size(); ++i) {
|
||||||
File srcFile = (File)fileList.get(i);
|
// 获取一个模板文件
|
||||||
this.a(projectPath, templateDir, configMap, srcFile, createFileConfig);
|
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 {
|
protected void a(String projectPath, File templateRootDir, Map<String, Object> configMap, File srcFile, CreateFileConfig createFileConfig) throws Exception {
|
||||||
log.debug("-------templateRootDir--" + templateDir.getPath());
|
log.debug("-------templateRootDir--" + templateRootDir.getPath());
|
||||||
log.debug("-------srcFile--" + srcFile.getPath());
|
log.debug("-------srcFile--" + srcFile.getPath());
|
||||||
String templateFile = FileHelper.a(templateDir, srcFile);
|
String templateFile = FileHelper.getDirExcludeRootDir(templateRootDir, srcFile);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.debug("-------templateFile--" + templateFile);
|
log.debug("-------templateFile--" + templateFile);
|
||||||
@@ -96,7 +105,7 @@ public class BaseCodeGenerate {
|
|||||||
|
|
||||||
Template var5 = this.a(var1, var4);
|
Template var5 = this.a(var1, var4);
|
||||||
var5.setOutputEncoding(charcterSet);
|
var5.setOutputEncoding(charcterSet);
|
||||||
File var6 = FileHelper.c(var2);
|
File var6 = FileHelper.createFile(var2);
|
||||||
log.info("[generate]\t template:" + var1 + " ==> " + var2);
|
log.info("[generate]\t template:" + var1 + " ==> " + var2);
|
||||||
FreemarkerHelper.a(var5, var3, var6, charcterSet);
|
FreemarkerHelper.a(var5, var3, var6, charcterSet);
|
||||||
if (!this.a(var6)) {
|
if (!this.a(var6)) {
|
||||||
|
|||||||
+55
-24
@@ -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 "";
|
return "";
|
||||||
} else {
|
} 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) {
|
if (fileName == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
int var1 = fileName.indexOf(".");
|
int index = fileName.indexOf(".");
|
||||||
return var1 == -1 ? "" : fileName.substring(var1 + 1);
|
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");
|
throw new IllegalArgumentException("file must be not null");
|
||||||
} else {
|
} else {
|
||||||
File var1 = new File(var0);
|
File file1 = new File(file);
|
||||||
c(var1);
|
createParentFile(file1);
|
||||||
return var1;
|
return file1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
public static void c(File var0) {
|
* 创建父目录
|
||||||
if (var0.getParentFile() != null) {
|
* @date 2021/4/2 13:58
|
||||||
var0.getParentFile().mkdirs();
|
* @param file
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static void createParentFile(File file) {
|
||||||
|
if (file.getParentFile() != null) {
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user