Commit e3ddb29c184f2b189c9688d2e8c22bdcbc48b581

Authored by 芋道源码
Committed by Gitee
2 parents 20548da9 0bbc0349

!110 优化 ProjectReactor 一键改包程序

Merge pull request !110 from 芋道源码/feature/1.6.2
yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java
@@ -22,14 +22,17 @@ public class ProjectReactor { @@ -22,14 +22,17 @@ public class ProjectReactor {
22 private static final String GROUP_ID = "cn.iocoder.boot"; 22 private static final String GROUP_ID = "cn.iocoder.boot";
23 private static final String ARTIFACT_ID = "yudao"; 23 private static final String ARTIFACT_ID = "yudao";
24 private static final String PACKAGE_NAME = "cn.iocoder.yudao"; 24 private static final String PACKAGE_NAME = "cn.iocoder.yudao";
  25 + private static final String TITLE = "芋道管理系统";
25 26
26 public static void main(String[] args) { 27 public static void main(String[] args) {
27 String projectBaseDir = getProjectBaseDir(); 28 String projectBaseDir = getProjectBaseDir();
  29 +
28 // ========== 配置,需要你手动修改 ========== 30 // ========== 配置,需要你手动修改 ==========
29 String groupIdNew = "cn.star.gg"; 31 String groupIdNew = "cn.star.gg";
30 String artifactIdNew = "star"; 32 String artifactIdNew = "star";
31 String packageNameNew = "cn.start.pp"; 33 String packageNameNew = "cn.start.pp";
32 - String projectBaseDirNew = projectBaseDir + "-new"; 34 + String titleNew = "土豆管理系统";
  35 + String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录
33 // ========== ========== 36 // ========== ==========
34 37
35 // 获得需要复制的文件 38 // 获得需要复制的文件
@@ -38,7 +41,7 @@ public class ProjectReactor { @@ -38,7 +41,7 @@ public class ProjectReactor {
38 log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); 41 log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size());
39 // 写入文件 42 // 写入文件
40 files.forEach(file -> { 43 files.forEach(file -> {
41 - String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew); 44 + String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew);
42 writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); 45 writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew);
43 }); 46 });
44 log.info("[main][重写完成]"); 47 log.info("[main][重写完成]");
@@ -61,18 +64,21 @@ public class ProjectReactor { @@ -61,18 +64,21 @@ public class ProjectReactor {
61 } 64 }
62 65
63 private static String replaceFileContent(File file, String groupIdNew, 66 private static String replaceFileContent(File file, String groupIdNew,
64 - String artifactIdNew, String packageNameNew) { 67 + String artifactIdNew, String packageNameNew,
  68 + String titleNew) {
65 return FileUtil.readString(file, StandardCharsets.UTF_8) 69 return FileUtil.readString(file, StandardCharsets.UTF_8)
66 .replaceAll(GROUP_ID, groupIdNew) 70 .replaceAll(GROUP_ID, groupIdNew)
67 .replaceAll(PACKAGE_NAME, packageNameNew) 71 .replaceAll(PACKAGE_NAME, packageNameNew)
68 .replaceAll(ARTIFACT_ID, artifactIdNew) // 必须放在最后替换,因为 ARTIFACT_ID 太短! 72 .replaceAll(ARTIFACT_ID, artifactIdNew) // 必须放在最后替换,因为 ARTIFACT_ID 太短!
69 - .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); 73 + .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew))
  74 + .replaceAll(TITLE, titleNew);
70 } 75 }
71 76
72 private static void writeFile(File file, String fileContent, String projectBaseDir, 77 private static void writeFile(File file, String fileContent, String projectBaseDir,
73 String projectBaseDirNew, String packageNameNew, String artifactIdNew) { 78 String projectBaseDirNew, String packageNameNew, String artifactIdNew) {
74 String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 79 String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录
75 - .replace(PACKAGE_NAME.replaceAll("\\.", "/"), packageNameNew.replaceAll("\\.", "/")) 80 + .replace(PACKAGE_NAME.replaceAll("\\.", File.separator),
  81 + packageNameNew.replaceAll("\\.", File.separator))
76 .replace(ARTIFACT_ID, artifactIdNew) // 82 .replace(ARTIFACT_ID, artifactIdNew) //
77 .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); 83 .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew));
78 FileUtil.writeUtf8String(fileContent, newPath); 84 FileUtil.writeUtf8String(fileContent, newPath);