Commit f2142f8a by 仲光辉

蛋壳创意科技--代码生成器(简易版) at 2020-10-30 14:33 ZGH.MercyModest

parents
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea
*.iml
target
# 蛋壳创意科技-代码生成器(简易版)
## 使用方式
### 下载最新的模板代码(dankal-microservice-code-template-v1)
> [蛋壳-GitLab](http://git.dankal.cn/mercyModest/dankal-microservice-code-template-v1.git)
### 设置五大必须参数与一个行为控制参数
> - projectName :项目名称
> - basePackageName : 项目基础报名
> - projectDescription : 项目描述
> - templateProjectPath : 模板代码路径
> - projectCreatePath : 项目生成路径
> - isOverride : 项目名称已经存在的行为
### 执行 `CodeGenerator#mian` 方法
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.dankal</groupId>
<artifactId>dankal-simple-code-util</artifactId>
<version>1.0-SNAPSHOT</version>
<description>蛋壳创意科技--微服务-简易代码生成器</description>
<dependencies>
<!--hutool-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>5.4.6</version>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<!--junit-test-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.code.util;
import cn.dankal.code.util.common.CodeUtil;
import cn.dankal.code.util.entity.ProjectInfo;
/**
* 代码生成器
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/30
*/
public class CodeGenerator {
public static void main(String[] args) {
// 项目参数: 必须全部非空
// 项目名称
final String projectName = "tudgo-global-permissoon";
// 项目基础包名 etc. com.tudgo.global.permission
final String basePackageName = "com.tudgo.global.permission";
// 项目描述 etc.土地工权限管理系统
final String projectDescription = "土地工权限管理系统";
// 模板项目路径 : C:\dev\test 目前只支持一套模板[dankal-microservice-code-template-v1]
final String templateProjectPath = "C:/dev/test/dankal-microservice-code-template-v1";
// 项目生成路径 C:\dev\test
final String projectCreatePath = "C:/dev/test";
// 如果 项目目录已经存在( projectCreatePath/projectName ) 是否覆盖
final boolean isOverride = false;
//构建项目信息对象
ProjectInfo projectInfo = CodeUtil.builderProjectInfo(projectName, basePackageName, projectDescription, templateProjectPath, projectCreatePath, isOverride);
try {
// 执行模板代生成
CodeUtil.doGenerate(projectInfo);
System.out.println("代码生成成功");
} catch (Exception exception) {
System.out.printf("代码生成失败!!! errorMessage: %s", exception.getMessage());
System.exit(0);
}
}
}
package cn.dankal.code.util.builder;
import cn.dankal.code.util.entity.ProjectInfo;
/**
* 项目名称构建
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/29
*/
public class ProjectInfoBuilder {
/**
* 构建一个 TemplateInfo 对象
*
* @return ProjectInfo
*/
public static ProjectInfo builder() {
return new ProjectInfo();
}
}
package cn.dankal.code.util.entity;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 项目信息实体
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/29
*/
@Data
@Accessors(chain = true)
public class ProjectInfo implements Serializable {
private static final long serialVersionUID = -6958602838534331817L;
/**
* 项目名称
* etc. tudgo-global-permission
*/
private String projectName;
/**
* 基本包名 (标准的Java包名)
* etc. com.tudgo.global.permission
*/
private String basePackageName;
/**
* 项目描述
* maven: <description></description>
*/
private String projectDescription;
/**
* 项目生成路径
*/
private String projectCreatePath;
/**
* 模板代码路径
*/
private String templateProjectPath;
/**
* 项目路径(系统自动赋值)
*/
private String projectPath;
}
package cn.dankal.code.util.test;
import cn.dankal.code.util.entity.ProjectInfo;
import cn.hutool.core.io.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
/**
* 功能测试
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/30
*/
public class FunctionTest {
/**
* 项目信息对象
*/
private ProjectInfo projectInfo;
@Before
public void beforeTests() {
// 项目名称
final String projectName = "test-in-code-util";
// 项目基础包名 etc. cn.dankal
final String basePackageName = "cn.dankal.test.code";
// 项目描述 etc.蛋壳创意科技--微服务--简易代码生成器
final String projectDescription = "蛋壳创意科技--微服务--简易代码生成器测试项目";
// 模板项目路径 : C:\dev\test 目前只支持一套模板
final String templateProjectPath = "C:/dev/test/dankal-microservice-code-template";
// 项目生成路径 C:\dev\test
final String projectCreatePath = "C:/dev/test";
//创建生成项目路径
String projectPath = projectCreatePath + File.separator + projectName;
File file = new File(projectPath);
if (file.exists()) {
FileUtil.del(file);
}
boolean mkdir = file.mkdir();
if (!mkdir) {
throw new IllegalStateException("创建新项目目录失败");
}
this.projectInfo = new ProjectInfo()
.setProjectName(projectName)
.setProjectCreatePath(projectCreatePath)
.setProjectDescription(projectDescription)
.setBasePackageName(basePackageName)
.setTemplateProjectPath(templateProjectPath)
.setProjectPath(projectPath);
}
@Test
@Ignore
public void testLoopFileByHutool() {
FileUtil.loopFiles(projectInfo.getTemplateProjectPath()).forEach(System.out::println);
}
@After
public void after() {
this.projectInfo = null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment