Commit 37900a7394880d793ab85216cee3f546ecdac0dd
1 parent
56ea65e5
修改一键改包的bug
Showing
1 changed file
with
16 additions
and
15 deletions
yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java
| ... | ... | @@ -8,10 +8,11 @@ import org.apache.commons.io.FileUtils; |
| 8 | 8 | import java.io.File; |
| 9 | 9 | import java.nio.charset.StandardCharsets; |
| 10 | 10 | import java.util.Collection; |
| 11 | +import java.util.regex.Matcher; | |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等 |
| 14 | - * | |
| 15 | + * <p> | |
| 15 | 16 | * 通过修改 groupIdNew、artifactIdNew、projectBaseDirNew 三个变量 |
| 16 | 17 | * |
| 17 | 18 | * @author 芋道源码 |
| ... | ... | @@ -22,18 +23,19 @@ public class ProjectReactor { |
| 22 | 23 | private static final String GROUP_ID = "cn.iocoder.boot"; |
| 23 | 24 | private static final String ARTIFACT_ID = "yudao"; |
| 24 | 25 | private static final String PACKAGE_NAME = "cn.iocoder.yudao"; |
| 25 | - private static final String TITLE = "芋道管理系统"; | |
| 26 | + private static final String TITLE = "欣辰装点猫管理系统"; | |
| 26 | 27 | |
| 27 | 28 | public static void main(String[] args) { |
| 29 | + long start = System.currentTimeMillis(); | |
| 28 | 30 | String projectBaseDir = getProjectBaseDir(); |
| 29 | 31 | |
| 30 | 32 | // ========== 配置,需要你手动修改 ========== |
| 31 | - String groupIdNew = "cn.star.gg"; | |
| 32 | - String artifactIdNew = "star"; | |
| 33 | - String packageNameNew = "cn.start.pp"; | |
| 34 | - String titleNew = "土豆管理系统"; | |
| 33 | + String groupIdNew = "cn.huwing.boot"; | |
| 34 | + String artifactIdNew = "zdm"; | |
| 35 | + String packageNameNew = "cn.huwing.zdm"; | |
| 36 | + String titleNew = "欣辰装点猫管理系统"; | |
| 35 | 37 | String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录 |
| 36 | - // ========== ========== | |
| 38 | + log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew); | |
| 37 | 39 | |
| 38 | 40 | // 获得需要复制的文件 |
| 39 | 41 | log.info("[main][开始获得需要重写的文件]"); |
| ... | ... | @@ -44,13 +46,12 @@ public class ProjectReactor { |
| 44 | 46 | String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); |
| 45 | 47 | writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); |
| 46 | 48 | }); |
| 47 | - log.info("[main][重写完成]"); | |
| 49 | + long end = System.currentTimeMillis(); | |
| 50 | + log.info("[main][重写完成]共耗时:" + (end - start) / 1000 + "秒"); | |
| 48 | 51 | } |
| 49 | 52 | |
| 50 | 53 | private static String getProjectBaseDir() { |
| 51 | - // noinspection ConstantConditions | |
| 52 | - return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(), | |
| 53 | - "/yudao-server", false); | |
| 54 | + return StrUtil.subBefore(new File(ProjectReactor.class.getClassLoader().getResource(File.separator).getFile()).getPath(), "\\yudao-server", false); | |
| 54 | 55 | } |
| 55 | 56 | |
| 56 | 57 | private static Collection<File> listFiles(String projectBaseDir) { |
| ... | ... | @@ -59,6 +60,7 @@ public class ProjectReactor { |
| 59 | 60 | files.removeIf(file -> file.getPath().contains("/node_modules/")); |
| 60 | 61 | files.removeIf(file -> file.getPath().contains("/.idea/")); // 移除 IDEA 自身的文件 |
| 61 | 62 | files.removeIf(file -> file.getPath().contains("/.git/")); // 移除 Git 自身的文件 |
| 63 | + files.removeIf(file -> file.getPath().contains("/.github/")); // 移除 GitHub 自身的文件 | |
| 62 | 64 | files.removeIf(file -> file.getPath().contains("/dist/")); // 移除 Node 编译出来的 |
| 63 | 65 | return files; |
| 64 | 66 | } |
| ... | ... | @@ -77,11 +79,10 @@ public class ProjectReactor { |
| 77 | 79 | private static void writeFile(File file, String fileContent, String projectBaseDir, |
| 78 | 80 | String projectBaseDirNew, String packageNameNew, String artifactIdNew) { |
| 79 | 81 | String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 |
| 80 | - .replace(PACKAGE_NAME.replaceAll("\\.", File.separator), | |
| 81 | - packageNameNew.replaceAll("\\.", File.separator)) | |
| 82 | + .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator)), | |
| 83 | + packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(File.separator))) | |
| 82 | 84 | .replace(ARTIFACT_ID, artifactIdNew) // |
| 83 | 85 | .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); |
| 84 | 86 | FileUtil.writeUtf8String(fileContent, newPath); |
| 85 | 87 | } |
| 86 | - | |
| 87 | -} | |
| 88 | +} | |
| 88 | 89 | \ No newline at end of file | ... | ... |