Commit 0bbc03493d691c9f83e7e9a5a44cdb7a9d41762f
1 parent
20548da9
优化 ProjectReactor 一键改包程序
Showing
1 changed file
with
11 additions
and
5 deletions
yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java
| ... | ... | @@ -22,14 +22,17 @@ public class ProjectReactor { |
| 22 | 22 | private static final String GROUP_ID = "cn.iocoder.boot"; |
| 23 | 23 | private static final String ARTIFACT_ID = "yudao"; |
| 24 | 24 | private static final String PACKAGE_NAME = "cn.iocoder.yudao"; |
| 25 | + private static final String TITLE = "芋道管理系统"; | |
| 25 | 26 | |
| 26 | 27 | public static void main(String[] args) { |
| 27 | 28 | String projectBaseDir = getProjectBaseDir(); |
| 29 | + | |
| 28 | 30 | // ========== 配置,需要你手动修改 ========== |
| 29 | 31 | String groupIdNew = "cn.star.gg"; |
| 30 | 32 | String artifactIdNew = "star"; |
| 31 | 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 | 41 | log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); |
| 39 | 42 | // 写入文件 |
| 40 | 43 | files.forEach(file -> { |
| 41 | - String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew); | |
| 44 | + String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); | |
| 42 | 45 | writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); |
| 43 | 46 | }); |
| 44 | 47 | log.info("[main][重写完成]"); |
| ... | ... | @@ -61,18 +64,21 @@ public class ProjectReactor { |
| 61 | 64 | } |
| 62 | 65 | |
| 63 | 66 | private static String replaceFileContent(File file, String groupIdNew, |
| 64 | - String artifactIdNew, String packageNameNew) { | |
| 67 | + String artifactIdNew, String packageNameNew, | |
| 68 | + String titleNew) { | |
| 65 | 69 | return FileUtil.readString(file, StandardCharsets.UTF_8) |
| 66 | 70 | .replaceAll(GROUP_ID, groupIdNew) |
| 67 | 71 | .replaceAll(PACKAGE_NAME, packageNameNew) |
| 68 | 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 | 77 | private static void writeFile(File file, String fileContent, String projectBaseDir, |
| 73 | 78 | String projectBaseDirNew, String packageNameNew, String artifactIdNew) { |
| 74 | 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 | 82 | .replace(ARTIFACT_ID, artifactIdNew) // |
| 77 | 83 | .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); |
| 78 | 84 | FileUtil.writeUtf8String(fileContent, newPath); | ... | ... |