Commit ceb76e719059841198a652b7bd10fa0df1c8fccf
1 parent
3e77061c
优化注释,修复 mac 的兼容性问题
Showing
1 changed file
with
14 additions
and
12 deletions
yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java
| ... | ... | @@ -11,6 +11,8 @@ import java.util.Collection; |
| 11 | 11 | import java.util.regex.Matcher; |
| 12 | 12 | import java.util.stream.Collectors; |
| 13 | 13 | |
| 14 | +import static java.io.File.separator; | |
| 15 | + | |
| 14 | 16 | /** |
| 15 | 17 | * 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等 |
| 16 | 18 | * <p> |
| ... | ... | @@ -39,9 +41,9 @@ public class ProjectReactor { |
| 39 | 41 | log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew); |
| 40 | 42 | |
| 41 | 43 | // 获得需要复制的文件 |
| 42 | - log.info("[main][开始获得需要重写的文件]"); | |
| 44 | + log.info("[main][开始获得需要重写的文件,预计需要 10-20 秒]"); | |
| 43 | 45 | Collection<File> files = listFiles(projectBaseDir); |
| 44 | - log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); | |
| 46 | + log.info("[main][需要重写的文件数量:{},预计需要 15-30 秒]", files.size()); | |
| 45 | 47 | // 写入文件 |
| 46 | 48 | files.forEach(file -> { |
| 47 | 49 | String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); |
| ... | ... | @@ -51,19 +53,19 @@ public class ProjectReactor { |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | 55 | private static String getProjectBaseDir() { |
| 54 | - return StrUtil.subBefore(new File(ProjectReactor.class.getClassLoader().getResource(File.separator).getFile()).getPath(), File.separator + "yudao-server", false); | |
| 56 | + return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(), | |
| 57 | + separator + "yudao-server", false); | |
| 55 | 58 | } |
| 56 | 59 | |
| 57 | 60 | private static Collection<File> listFiles(String projectBaseDir) { |
| 58 | 61 | Collection<File> files = FileUtils.listFiles(new File(projectBaseDir), null, true); |
| 59 | - // 移除 IDEA Git GitHub 自身的文件; Node 编译出来的文件 | |
| 62 | + // 移除 IDEA、Git 自身的文件、Node 编译出来的文件 | |
| 60 | 63 | files = files.stream() |
| 61 | - .filter(file -> !file.getPath().contains(File.separator + "target" + File.separator) | |
| 62 | - && !file.getPath().contains(File.separator + "node_modules" + File.separator) | |
| 63 | - && !file.getPath().contains(File.separator + ".idea" + File.separator) | |
| 64 | - && !file.getPath().contains(File.separator + ".git" + File.separator) | |
| 65 | - && !file.getPath().contains(File.separator + ".github" + File.separator) | |
| 66 | - && !file.getPath().contains(File.separator + "dist" + File.separator) | |
| 64 | + .filter(file -> !file.getPath().contains(separator + "target" + separator) | |
| 65 | + && !file.getPath().contains(separator + "node_modules" + separator) | |
| 66 | + && !file.getPath().contains(separator + ".idea" + separator) | |
| 67 | + && !file.getPath().contains(separator + ".git" + separator) | |
| 68 | + && !file.getPath().contains(separator + "dist" + separator) | |
| 67 | 69 | && !file.getPath().contains(".iml") |
| 68 | 70 | && !file.getPath().contains(".html.gz")) |
| 69 | 71 | .collect(Collectors.toList()); |
| ... | ... | @@ -84,8 +86,8 @@ public class ProjectReactor { |
| 84 | 86 | private static void writeFile(File file, String fileContent, String projectBaseDir, |
| 85 | 87 | String projectBaseDirNew, String packageNameNew, String artifactIdNew) { |
| 86 | 88 | String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 |
| 87 | - .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator)), | |
| 88 | - packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(File.separator))) | |
| 89 | + .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(separator)), | |
| 90 | + packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(separator))) | |
| 89 | 91 | .replace(ARTIFACT_ID, artifactIdNew) // |
| 90 | 92 | .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); |
| 91 | 93 | FileUtil.writeUtf8String(fileContent, newPath); | ... | ... |